mirror of https://github.com/aseprite/aseprite.git
Fix popups & tooltips direction when ToolBar is docked at the left side
This commit is contained in:
parent
7ca6f53eb6
commit
fc57df4305
|
@ -395,6 +395,11 @@ void ToolBar::onVisible(bool visible)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToolBar::isDockedAtLeftSide() const
|
||||||
|
{
|
||||||
|
return bounds().center().x < window()->bounds().center().x;
|
||||||
|
}
|
||||||
|
|
||||||
int ToolBar::getToolGroupIndex(ToolGroup* group)
|
int ToolBar::getToolGroupIndex(ToolGroup* group)
|
||||||
{
|
{
|
||||||
ToolBox* toolbox = App::instance()->toolBox();
|
ToolBox* toolbox = App::instance()->toolBox();
|
||||||
|
@ -468,14 +473,18 @@ void ToolBar::openPopupWindow(GroupType group_type, int group_index, tools::Tool
|
||||||
m_currentStrip = toolstrip;
|
m_currentStrip = toolstrip;
|
||||||
m_popupWindow->addChild(toolstrip);
|
m_popupWindow->addChild(toolstrip);
|
||||||
|
|
||||||
|
const int borderWidth = border().width();
|
||||||
Rect rc = getToolGroupBounds(group_index);
|
Rect rc = getToolGroupBounds(group_index);
|
||||||
int w = 0;
|
int w = borderWidth;
|
||||||
for (const auto* tool : tools) {
|
for (const auto* tool : tools) {
|
||||||
(void)tool;
|
(void)tool;
|
||||||
w += bounds().w - border().width() - 1 * guiscale();
|
w += bounds().w - borderWidth - 1 * guiscale();
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.x -= w;
|
if (isDockedAtLeftSide())
|
||||||
|
rc.x = bounds().x2() - borderWidth;
|
||||||
|
else
|
||||||
|
rc.x -= w - borderWidth;
|
||||||
rc.w = w;
|
rc.w = w;
|
||||||
|
|
||||||
// Set hotregion of popup window
|
// Set hotregion of popup window
|
||||||
|
@ -535,7 +544,7 @@ Point ToolBar::getToolPositionInGroup(const Tool* tool) const
|
||||||
const auto& tools = m_currentStrip->tools();
|
const auto& tools = m_currentStrip->tools();
|
||||||
const int nth = std::find(tools.begin(), tools.end(), tool) - tools.begin();
|
const int nth = std::find(tools.begin(), tools.end(), tool) - tools.begin();
|
||||||
|
|
||||||
return Point(iconsize.w / 2 + nth * (iconsize.w - 1 * guiscale()), iconsize.h);
|
return Point(iconsize.w / 2 + nth * (iconsize.w - border().right()), iconsize.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolBar::openTipWindow(ToolGroup* tool_group, Tool* tool)
|
void ToolBar::openTipWindow(ToolGroup* tool_group, Tool* tool)
|
||||||
|
@ -589,10 +598,26 @@ void ToolBar::openTipWindow(int group_index, Tool* tool)
|
||||||
|
|
||||||
Rect toolrc = getToolGroupBounds(group_index);
|
Rect toolrc = getToolGroupBounds(group_index);
|
||||||
Point arrow = (tool ? getToolPositionInGroup(tool) : Point(0, 0));
|
Point arrow = (tool ? getToolPositionInGroup(tool) : Point(0, 0));
|
||||||
if (tool && m_popupWindow && m_popupWindow->isVisible())
|
|
||||||
toolrc.x += arrow.x - m_popupWindow->bounds().w;
|
|
||||||
|
|
||||||
m_tipWindow->pointAt(TOP | RIGHT, toolrc, ui::Manager::getDefault()->display());
|
int pointAt = TOP;
|
||||||
|
if (isDockedAtLeftSide()) {
|
||||||
|
pointAt |= LEFT;
|
||||||
|
toolrc.x -= border().width();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pointAt |= RIGHT;
|
||||||
|
toolrc.x += border().width();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tooltip for subtools (tools inside groups)
|
||||||
|
if (tool && m_popupWindow && m_popupWindow->isVisible()) {
|
||||||
|
if (isDockedAtLeftSide())
|
||||||
|
toolrc.x += arrow.x + bounds().w - border().width();
|
||||||
|
else
|
||||||
|
toolrc.x += arrow.x - m_popupWindow->bounds().w + border().width();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tipWindow->pointAt(pointAt, toolrc, ui::Manager::getDefault()->display());
|
||||||
|
|
||||||
if (m_tipOpened)
|
if (m_tipOpened)
|
||||||
m_tipWindow->openWindow();
|
m_tipWindow->openWindow();
|
||||||
|
|
|
@ -73,6 +73,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
enum class GroupType { Regular, Overflow };
|
enum class GroupType { Regular, Overflow };
|
||||||
|
|
||||||
|
bool isDockedAtLeftSide() const;
|
||||||
int getToolGroupIndex(tools::ToolGroup* group);
|
int getToolGroupIndex(tools::ToolGroup* group);
|
||||||
void openPopupWindow(GroupType group_type,
|
void openPopupWindow(GroupType group_type,
|
||||||
int group_index = 0,
|
int group_index = 0,
|
||||||
|
|
Loading…
Reference in New Issue