From af36819694fb7a64e928ebd4193bd7c1ddf3a175 Mon Sep 17 00:00:00 2001 From: av-dx Date: Sun, 27 Jun 2021 12:57:59 +0530 Subject: [PATCH] GUI: Set tray height according to line height --- gui/widgets/grid.cpp | 14 ++++++-------- gui/widgets/grid.h | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/gui/widgets/grid.cpp b/gui/widgets/grid.cpp index 07df2103e42..1a40ba2352b 100644 --- a/gui/widgets/grid.cpp +++ b/gui/widgets/grid.cpp @@ -148,18 +148,19 @@ void GridItemWidget::handleMouseMoved(int x, int y, int button) { void GridItemWidget::handleMouseDown(int x, int y, int button, int clickCount) { if (isHighlighted) { // Work in progress - _grid->openTray(getAbsX() - _grid->_gridXSpacing / 3, getAbsY() + _h, _w + 2 * (_grid->_gridXSpacing / 3), _h / 3, _activeEntry->entryID); + _grid->openTray(getAbsX() - _grid->_gridXSpacing / 3, getAbsY() + _h, _w + 2 * (_grid->_gridXSpacing / 3), kLineHeight * 3, _activeEntry->entryID); _grid->_tray->runModal(); } } #pragma mark - -GridItemTray::GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID) +GridItemTray::GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid) : Dialog(x, y, w, h), CommandSender(boss) { _entryID = entryID; _boss = boss; + _grid = grid; int buttonWidth = w / 3; int buttonHeight = h / 3; @@ -198,10 +199,7 @@ void GridItemTray::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) void GridItemTray::handleMouseDown(int x, int y, int button, int clickCount) { Dialog::handleMouseDown(x, y, button, clickCount); - // HACK: Tray height is determined relative to grid item height - // hence we know the grid item height from within the tray. - // We might want to make tray height independent of grid item height. - if ((x < 0 || x > _w) || (y > _h || y < -(_h * 3))) { + if ((x < 0 || x > _w) || (y > _h || y < -(_grid->_gridItemHeight))) { // Close on clicking outside close(); } else if (y < 0 && clickCount >= 2) { @@ -608,7 +606,7 @@ void GridWidget::reflowLayout() { for (int k = 0; k < _itemsOnScreen; ++k) { GridItemWidget *newItem = new GridItemWidget(this, - _minGridXSpacing + col * (_gridItemWidth + _gridXSpacing), + 2 * _minGridXSpacing + col * (_gridItemWidth + _gridXSpacing), (_scrollPos % (_gridItemHeight + _gridYSpacing)) + _gridYSpacing + (row - 1) * (_gridItemHeight + _gridYSpacing), _gridItemWidth, _gridItemHeight); @@ -627,7 +625,7 @@ void GridWidget::reflowLayout() { } void GridWidget::openTray(int x, int y, int w, int h, int entryId) { - _tray = new GridItemTray(_boss, x, y, w, h, entryId); + _tray = new GridItemTray(_boss, x, y, w, h, entryId, this); } void GridWidget::scrollBarRecalc() { diff --git a/gui/widgets/grid.h b/gui/widgets/grid.h index 7947608f7c9..48064342e38 100644 --- a/gui/widgets/grid.h +++ b/gui/widgets/grid.h @@ -89,6 +89,7 @@ struct GridItemInfo /* GridItemTray */ class GridItemTray: public Dialog, public CommandSender { int _entryID; + GridWidget *_grid; GuiObject *_boss; public: typedef Common::String String; @@ -97,7 +98,7 @@ public: typedef Common::U32String U32String; typedef Common::Array U32StringArray; - GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID); + GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid); void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override; void handleMouseDown(int x, int y, int button, int clickCount) override;