Skip to content

Commit

Permalink
Fix Dialog.bounds doesn't work as expected (fix aseprite#3898)
Browse files Browse the repository at this point in the history
Prior to this fix, the 'Dialog:show()' function would override bounds
when they were defined before the 'show' command.
Also:
The Dialog.bounds getter now returns only the boundaries of
the current window.
The Dialog.bounds setter now does not allow empty bounds as input
argument.
  • Loading branch information
Gasparoken committed Aug 3, 2023
1 parent ab2d7f7 commit 91319cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app/script/dialog_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ int Dialog_show(lua_State* L)
if (!rc.isEmpty()) {
conn = dlg->window.Open.connect([dlg, rc]{
dlg->setWindowBounds(rc);
dlg->window.setAutoRemap(false);
});
}
}
Expand Down Expand Up @@ -1591,9 +1592,6 @@ 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())
dlg->window.remapWindow();

push_new<gfx::Rect>(L, dlg->getWindowBounds());
return 1;
}
Expand All @@ -1603,8 +1601,11 @@ 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())
// Empty rect isn't allowed.
if (*rc != dlg->getWindowBounds() && !rc->isEmpty()) {
dlg->setWindowBounds(*rc);
dlg->window.setAutoRemap(false);
}
}
return 0;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/scripts/dialogs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- 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 bounds = dlg.bounds
assert(bounds == Rectangle(0, 0, 0, 0))
dlg:show { wait=false }
local screenSize = Size(app.window.width, app.window.height)
bounds = dlg.bounds
assert(bounds.x == (screenSize.width - bounds.width) / 2)
assert(bounds.y == (screenSize.height - bounds.height) / 2)
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

0 comments on commit 91319cc

Please sign in to comment.