From 5d0d609a3fb2535fb579ecd9633359e0f35b5df0 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 14 Sep 2016 15:47:27 -0300 Subject: [PATCH] Fix ui::Alert buttons center alignment This bug was introduced in 4a6d6951e3f22964a3c84171f0ca8643b454c5ab --- src/ui/alert.cpp | 18 ++++++++---------- src/ui/grid_ui_tests.cpp | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/ui/alert.cpp b/src/ui/alert.cpp index 715895a2f..c6ed1c847 100644 --- a/src/ui/alert.cpp +++ b/src/ui/alert.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2013, 2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -129,8 +129,6 @@ int Alert::show(const char* format, ...) void Alert::processString(char* buf, std::vector& labels, std::vector& buttons) { - Box* box1, *box2, *box3, *box4, *box5; - Grid* grid; bool title = true; bool label = false; bool separator = false; @@ -200,18 +198,18 @@ void Alert::processString(char* buf, std::vector& labels, std::vectorsetId("labels"); box3->setId("buttons"); // Pseudo separators (only to fill blank space) - box4 = new Box(0); - box5 = new Box(0); + auto box4 = new Box(0); + auto box5 = new Box(0); m_progressPlaceholder = new Box(0); box4->setExpansive(true); @@ -230,7 +228,7 @@ void Alert::processString(char* buf, std::vector& labels, std::vectoraddChild(box5); // Filler box1->addChild(grid); // Buttons - grid->addChildInCell(box3, 1, 1, CENTER | BOTTOM); + grid->addChildInCell(box3, 1, 1, CENTER | BOTTOM | HORIZONTAL); for (std::vector::iterator it = labels.begin(); it != labels.end(); ++it) box2->addChild(*it); diff --git a/src/ui/grid_ui_tests.cpp b/src/ui/grid_ui_tests.cpp index dea892059..4c53d53f8 100644 --- a/src/ui/grid_ui_tests.cpp +++ b/src/ui/grid_ui_tests.cpp @@ -306,3 +306,24 @@ TEST(Grid, ReduceThree) EXPECT_EQ(gfx::Rect(0, 4, 10, 4), b.bounds()); EXPECT_EQ(gfx::Rect(0, 8, 10, 4), c.bounds()); } + +TEST(Grid, Alignment) +{ + Grid grid(1, false); + grid.noBorderNoChildSpacing(); + + Widget a; + a.setMinSize(gfx::Size(10, 10)); + + grid.addChildInCell(&a, 1, 1, CENTER | BOTTOM | HORIZONTAL | VERTICAL); + + Size reqSize = grid.sizeHint(); + EXPECT_EQ(10, reqSize.w); + EXPECT_EQ(10, reqSize.h); + + grid.setBounds(gfx::Rect(10, 10, 40, 10)); + EXPECT_EQ(gfx::Rect(25, 10, 10, 10), a.bounds()); + + grid.setBounds(gfx::Rect(10, 10, 60, 20)); + EXPECT_EQ(gfx::Rect(35, 20, 10, 10), a.bounds()); +}