input callback fix + added focused property
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user