mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 12:39:57 +00:00
[lua] Add "enabled" and "visible" properties when creating new widgets
Fixed https://github.com/aseprite/api/issues/29
This commit is contained in:
parent
f491a2a506
commit
a2cdde8ec8
@ -285,6 +285,7 @@ int Dialog_add_widget(lua_State* L, Widget* widget)
|
|||||||
auto dlg = get_obj<Dialog>(L, 1);
|
auto dlg = get_obj<Dialog>(L, 1);
|
||||||
const char* label = nullptr;
|
const char* label = nullptr;
|
||||||
std::string id;
|
std::string id;
|
||||||
|
bool visible = true;
|
||||||
|
|
||||||
// This is to separate different kind of widgets without label in
|
// This is to separate different kind of widgets without label in
|
||||||
// different rows.
|
// different rows.
|
||||||
@ -317,11 +318,28 @@ int Dialog_add_widget(lua_State* L, Widget* widget)
|
|||||||
if (type != LUA_TNIL && lua_toboolean(L, -1))
|
if (type != LUA_TNIL && lua_toboolean(L, -1))
|
||||||
widget->setFocusMagnet(true);
|
widget->setFocusMagnet(true);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Enabled
|
||||||
|
type = lua_getfield(L, 2, "enabled");
|
||||||
|
if (type != LUA_TNIL)
|
||||||
|
widget->setEnabled(lua_toboolean(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Visible
|
||||||
|
type = lua_getfield(L, 2, "visible");
|
||||||
|
if (type != LUA_TNIL) {
|
||||||
|
visible = lua_toboolean(L, -1);
|
||||||
|
widget->setVisible(visible);
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label || !dlg->hbox) {
|
if (label || !dlg->hbox) {
|
||||||
if (label) {
|
if (label) {
|
||||||
auto labelWidget = new ui::Label(label);
|
auto labelWidget = new ui::Label(label);
|
||||||
|
if (!visible)
|
||||||
|
labelWidget->setVisible(false);
|
||||||
|
|
||||||
dlg->grid.addChildInCell(labelWidget, 1, 1, ui::LEFT | ui::TOP);
|
dlg->grid.addChildInCell(labelWidget, 1, 1, ui::LEFT | ui::TOP);
|
||||||
if (!id.empty())
|
if (!id.empty())
|
||||||
dlg->labelWidgets[id] = labelWidget;
|
dlg->labelWidgets[id] = labelWidget;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user