mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 06:50:07 +00:00
Fix Dialog.bounds doesn't work as expected (fix #3898)
Prior to this fix, the 'Dialog:show()' function overrode bounds when they were defined before the 'show' command.
This commit is contained in:
parent
aeb7157277
commit
8226e5285a
@ -413,6 +413,7 @@ int Dialog_show(lua_State* L)
|
||||
if (!rc.isEmpty()) {
|
||||
conn = dlg->window.Open.connect([dlg, rc]{
|
||||
dlg->setWindowBounds(rc);
|
||||
dlg->window.setAutoRemap(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1836,9 +1837,10 @@ int Dialog_set_data(lua_State* L)
|
||||
int Dialog_get_bounds(lua_State* L)
|
||||
{
|
||||
auto dlg = get_obj<Dialog>(L, 1);
|
||||
if (!dlg->window.isVisible())
|
||||
if (!dlg->window.isVisible() && dlg->window.bounds().isEmpty()) {
|
||||
dlg->window.remapWindow();
|
||||
|
||||
dlg->window.centerWindow(dlg->parentDisplay());
|
||||
}
|
||||
push_new<gfx::Rect>(L, dlg->getWindowBounds());
|
||||
return 1;
|
||||
}
|
||||
@ -1848,8 +1850,10 @@ int Dialog_set_bounds(lua_State* L)
|
||||
auto dlg = get_obj<Dialog>(L, 1);
|
||||
const auto rc = get_obj<gfx::Rect>(L, 2);
|
||||
if (rc) {
|
||||
if (*rc != dlg->getWindowBounds())
|
||||
if (*rc != dlg->getWindowBounds()) {
|
||||
dlg->setWindowBounds(*rc);
|
||||
dlg->window.setAutoRemap(false);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
33
tests/scripts/dialogs.lua
Normal file
33
tests/scripts/dialogs.lua
Normal file
@ -0,0 +1,33 @@
|
||||
-- Copyright (C) 2023 Igara Studio S.A.
|
||||
--
|
||||
-- This file is released under the terms of the MIT license.
|
||||
-- Read LICENSE.txt for more information.
|
||||
|
||||
if app.isUIAvailable then
|
||||
dofile('./test_utils.lua')
|
||||
|
||||
-- Test dialog bounds
|
||||
do
|
||||
local dlg = Dialog("Bounds test")
|
||||
local screenSize = Size(app.window.width, app.window.height)
|
||||
local bounds = dlg.bounds
|
||||
assert(bounds.x == (math.floor(screenSize.width / 2) - math.floor(bounds.width / 2)))
|
||||
assert(bounds.y == (math.floor(screenSize.height / 2) - math.floor(bounds.height / 2)))
|
||||
local bounds2 = bounds
|
||||
dlg:show { wait=false }
|
||||
bounds = dlg.bounds
|
||||
assert(bounds == bounds2)
|
||||
print(bounds)
|
||||
dlg:close()
|
||||
end
|
||||
|
||||
do
|
||||
local rect = Rectangle(10, 20, 200, 50)
|
||||
local dlg2 = Dialog("Bounds test 2")
|
||||
dlg2.bounds = rect
|
||||
assert(dlg2.bounds == rect)
|
||||
dlg2:show { wait=false }
|
||||
assert(dlg2.bounds == rect)
|
||||
dlg2:close()
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user