feat: 'edited' property reset & add 'oncontrolkey' textbox callback
This commit is contained in:
@@ -553,6 +553,13 @@ static void p_set_editable(UINode* node, lua::State* L, int idx) {
|
||||
box->setEditable(lua::toboolean(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_edited(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
if (!lua::toboolean(L, idx)) {
|
||||
box->setUnedited();
|
||||
}
|
||||
}
|
||||
}
|
||||
static void p_set_line_numbers(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setShowLineNumbers(lua::toboolean(L, idx));
|
||||
@@ -675,6 +682,7 @@ static int l_gui_setattr(lua::State* L) {
|
||||
{"hint", p_set_hint},
|
||||
{"text", p_set_text},
|
||||
{"editable", p_set_editable},
|
||||
{"edited", p_set_edited},
|
||||
{"lineNumbers", p_set_line_numbers},
|
||||
{"syntax", p_set_syntax},
|
||||
{"markup", p_set_markup},
|
||||
|
||||
@@ -36,6 +36,28 @@ static lua::State* process_callback(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
key_handler scripting::create_key_handler(
|
||||
const scriptenv& env, const std::string& src, const std::string& file
|
||||
) {
|
||||
return [=](int code) {
|
||||
if (auto L = process_callback(env, src, file)) {
|
||||
int top = lua::gettop(L);
|
||||
if (lua::isfunction(L, -1)) {
|
||||
lua::pushinteger(L, code);
|
||||
lua::call_nothrow(L, 1);
|
||||
}
|
||||
int returned = lua::gettop(L) - top + 1;
|
||||
if (returned) {
|
||||
bool x = lua::toboolean(L, -1);
|
||||
lua::pop(L, returned);
|
||||
return x;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
wstringconsumer scripting::create_wstring_consumer(
|
||||
const scriptenv& env, const std::string& src, const std::string& file
|
||||
) {
|
||||
|
||||
@@ -17,6 +17,12 @@ namespace scripting {
|
||||
const std::string& file = "[string]"
|
||||
);
|
||||
|
||||
key_handler create_key_handler(
|
||||
const scriptenv& env,
|
||||
const std::string& src,
|
||||
const std::string& file = "[string]"
|
||||
);
|
||||
|
||||
wstringconsumer create_wstring_consumer(
|
||||
const scriptenv& env,
|
||||
const std::string& src,
|
||||
|
||||
Reference in New Issue
Block a user