Dreikblack's post in Ultra App Kit - table was marked as the answer
June 18, 2023
Edit button just for having 2 buttons in a menu:
add shared_ptr<Panel> contextMenu; to ListView.h
In ListView.cpp update Initialize method:
bool ListView::Initialize(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent, shared_ptr<ListViewData> header, int columnCount)
{
bool isInit = Widget::Initialize("", x, y, width, height, parent, 0);
itemSize = iVec2(width, getItemHeight());
ListView::columnCount = columnCount;
initBlockCount += (columnCount * 2);
ListView::header = header;
contextMenu = CreatePanel(0, 0, 100, 40, gui->root);
contextMenu->Hide();
auto editButton = CreateButton("Edit", 0, 0, 100, 20, contextMenu);//just for an example, no function
auto removeButton = CreateButton("Remove", 0, 20, 100, 20, contextMenu);
ListenEvent(EVENT_WIDGETACTION, removeButton, RemoveCallback, Self()->As<ListView>());
return isInit;
}
and MouseDown method:
void ListView::MouseDown(const MouseButton button, const int x, const int y)
{
contextMenu->Hide();
if (x >= 0 and y >= getItemHeight() and x < size.x and y < size.y)
{
int itemId = y / getItemHeight() - 1;
if (itemId >= 0 and itemId < items.size())
{
selectedItemId = itemId;
Redraw();
if (button == MOUSE_LEFT)
{
if (pickItemListener)
{
pickItemListener(Event(EVENT_WIDGETACTION, Self(), selectedItemId));
}
}
else if (button == MOUSE_RIGHT)
{
contextMenu->Show();
contextMenu->SetShape(iVec2(x, y), contextMenu->GetSize());
}
}
}
}
Also add this function to same class:
bool RemoveCallback(const Event& ev, shared_ptr<Object> extra)
{
auto listView = extra->As<ListView>();
listView->removeSelectedItem();
listView->contextMenu->Hide();
return true;
}