mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
input callback fix + added focused property
This commit is contained in:
parent
165525f18c
commit
01c7cd9141
2 changed files with 24 additions and 1 deletions
|
|
@ -252,6 +252,9 @@ static int p_is_enabled(UINode* node) {
|
|||
static int p_move_into(UINode*) {
|
||||
return state->pushcfunction(l_uinode_move_into);
|
||||
}
|
||||
static int p_get_focused(UINode* node) {
|
||||
return state->pushboolean(node->isFocused());
|
||||
}
|
||||
|
||||
static int l_gui_getattr(lua_State* L) {
|
||||
auto docname = lua_tostring(L, 1);
|
||||
|
|
@ -287,6 +290,7 @@ static int l_gui_getattr(lua_State* L) {
|
|||
{"back", p_get_back},
|
||||
{"reset", p_get_reset},
|
||||
{"inventory", p_get_inventory},
|
||||
{"focused", p_get_focused},
|
||||
};
|
||||
auto func = getters.find(attr);
|
||||
if (func != getters.end()) {
|
||||
|
|
@ -390,6 +394,13 @@ static void p_set_inventory(UINode* node, int idx) {
|
|||
}
|
||||
}
|
||||
}
|
||||
static void p_set_focused(std::shared_ptr<UINode> node, int idx) {
|
||||
if (state->toboolean(idx) && !node->isFocused()) {
|
||||
scripting::engine->getGUI()->setFocus(node);
|
||||
} else if (node->isFocused()){
|
||||
node->defocus();
|
||||
}
|
||||
}
|
||||
|
||||
static int l_gui_setattr(lua_State* L) {
|
||||
auto docname = lua_tostring(L, 1);
|
||||
|
|
@ -425,6 +436,13 @@ static int l_gui_setattr(lua_State* L) {
|
|||
if (func != setters.end()) {
|
||||
func->second(node.get(), 4);
|
||||
}
|
||||
static const std::unordered_map<std::string_view, std::function<void(std::shared_ptr<UINode>,int)>> setters2 {
|
||||
{"focused", p_set_focused},
|
||||
};
|
||||
auto func2 = setters2.find(attr);
|
||||
if (func2 != setters2.end()) {
|
||||
func2->second(node, 4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue