GUI2 LuaAPI: add clear_items() (#9418)
This commit is contained in:
parent
56cc3aee0f
commit
d2e7fbbeb8
2 changed files with 31 additions and 3 deletions
|
@ -280,7 +280,30 @@ static int intf_remove_dialog_item(lua_State* L)
|
|||
return luaL_argerror(L, lua_gettop(L), "unsupported widget");
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all entries from a list.
|
||||
* - Arg 1: widget
|
||||
*/
|
||||
static int intf_clear_items(lua_State* L)
|
||||
{
|
||||
gui2::widget* w = &luaW_checkwidget(L, 1);
|
||||
|
||||
if(auto* lb = dynamic_cast<gui2::listbox*>(w)) {
|
||||
lb->clear();
|
||||
} else if(auto* mp = dynamic_cast<gui2::multi_page*>(w)) {
|
||||
mp->clear();
|
||||
} else if(auto* tv = dynamic_cast<gui2::tree_view*>(w)) {
|
||||
tv->clear();
|
||||
} else if(auto* tvn = dynamic_cast<gui2::tree_view_node*>(w)) {
|
||||
tvn->clear();
|
||||
} else {
|
||||
return luaL_argerror(L, lua_gettop(L), "unsupported widget");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace { // helpers of intf_set_dialog_callback()
|
||||
|
@ -463,14 +486,15 @@ int luaW_open(lua_State* L)
|
|||
lk.add_log("Adding widgets module...\n");
|
||||
static luaL_Reg const gui_callbacks[] = {
|
||||
//TODO: the naming is a bit arbitrary: widgets with different
|
||||
// types of elements use add_node, eidgets with only
|
||||
// types of elements use add_node, widgets with only
|
||||
// one type of element use add_element
|
||||
{ "add_item_of_type", &intf_add_item_of_type },
|
||||
{ "add_item", &intf_add_dialog_item },
|
||||
{ "focus", &intf_set_dialog_focus },
|
||||
{ "set_canvas", &intf_set_dialog_canvas },
|
||||
{ "set_callback", &intf_set_dialog_callback },
|
||||
{ "remove_items_at", &intf_remove_dialog_item },
|
||||
{ "remove_items_at", &intf_remove_dialog_item },
|
||||
{ "clear_items", &intf_clear_items },
|
||||
{ "find", &intf_find_widget },
|
||||
{ "close", &intf_dialog_close },
|
||||
{ nullptr, nullptr },
|
||||
|
|
|
@ -224,6 +224,10 @@ function gui.widget.add_item_of_type(widget, category, position, count) end
|
|||
---@param position? integer
|
||||
function gui.widget.remove_items_at(widget, position) end
|
||||
|
||||
---Remove all items from a container widget
|
||||
---@param widget widget
|
||||
function gui.widget.clear_items(widget) end
|
||||
|
||||
---Find a widget based on a path
|
||||
---@param widget widget
|
||||
---@vararg integer|string
|
||||
|
|
Loading…
Add table
Reference in a new issue