Fix some ToolBar issues calculating the required min height

* The calculation was moved to onResize() event (when bounds are set)
  instead of kPaintMessage
* All groups can be collapsed: in case the available space is so
  small that we can only show one button to expand all tools
* Don't calculate the min height using the "lastToolBounds" absolute
  position, we have to adjust that coordinate with the ToolBar origin
* Make the min height calculation a little more accurate
This commit is contained in:
David Capello 2025-05-09 21:51:26 -03:00
parent 95d65d8163
commit d8e8074345
2 changed files with 16 additions and 14 deletions

View File

@ -125,18 +125,6 @@ bool ToolBar::isToolVisible(Tool* tool)
bool ToolBar::onProcessMessage(Message* msg)
{
switch (msg->type()) {
case kPaintMessage: {
auto toolbox = App::instance()->toolBox();
auto lastToolBounds = getToolGroupBounds(toolbox->getGroupsCount());
int minHeight = lastToolBounds.y + lastToolBounds.h;
if (minHeight != m_minHeight) {
m_minHeight = minHeight;
invalidate();
}
break;
}
case kMouseDownMessage: {
auto mouseMsg = static_cast<const MouseMessage*>(msg);
const Point mousePos = mouseMsg->positionForDisplay(display());
@ -332,6 +320,18 @@ void ToolBar::onSizeHint(SizeHintEvent& ev)
}
}
void ToolBar::onResize(ui::ResizeEvent& ev)
{
Widget::onResize(ev);
auto* toolbox = App::instance()->toolBox();
auto lastToolBounds = getToolGroupBounds(toolbox->getGroupsCount());
m_minHeight = lastToolBounds.y2() -
origin().y
// Preview and timeline buttons
+ 2 * (getToolIconSize(this).h - 1) + 3 * guiscale();
}
void ToolBar::onPaint(ui::PaintEvent& ev)
{
gfx::Rect bounds = clientBounds();
@ -676,9 +676,9 @@ int ToolBar::getHiddenGroups() const
auto* toolbox = App::instance()->toolBox();
const int height = size().h;
if (height < m_minHeight) {
int hidden = (m_minHeight - height) / getToolIconSize(this).h;
int hidden = (m_minHeight - height) / (getToolIconSize(this).h - 1 * guiscale());
if (hidden >= 1)
return std::clamp(hidden + 1, 2, toolbox->getGroupsCount() - 1);
return std::clamp(hidden + 1, 2, toolbox->getGroupsCount());
}
return 0;
}

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -54,6 +55,7 @@ public:
protected:
bool onProcessMessage(ui::Message* msg) override;
void onSizeHint(ui::SizeHintEvent& ev) override;
void onResize(ui::ResizeEvent& ev) override;
void onPaint(ui::PaintEvent& ev) override;
void onVisible(bool visible) override;