place the selection panel beside what it describes
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "DisplayName.h"
|
||||
#include "EventManager.h"
|
||||
#include "ExitBuilderModeRequestedEvent.h"
|
||||
#include "FloatingLayoutInvalidatedEvent.h"
|
||||
#include "IconCaption.h"
|
||||
#include "InputMapper.h"
|
||||
#include "ItemIconCache.h"
|
||||
@@ -270,15 +271,25 @@ BuildButtonBar::~BuildButtonBar()
|
||||
unregisterForEvents();
|
||||
}
|
||||
|
||||
void BuildButtonBar::anchorTo(const QRect& worldViewRect)
|
||||
void BuildButtonBar::placeIn(const QRect& viewRect,
|
||||
const std::vector<QRect>& /*occupiedRects*/)
|
||||
{
|
||||
m_viewRect = worldViewRect;
|
||||
recenter();
|
||||
}
|
||||
if (viewRect.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The layout drops hidden buttons from its size hint, but only once it has been
|
||||
// re-run: an unlock changes which buttons are shown, and Qt would not get around to
|
||||
// it before the bar is measured here.
|
||||
layout()->activate();
|
||||
|
||||
int BuildButtonBar::getStripHeightPx() const
|
||||
{
|
||||
return height() + kBottomMarginPx;
|
||||
const QSize barSize = sizeHint();
|
||||
// Centered, except that a bar wider than the view stays flush with its left edge
|
||||
// rather than hanging off both sides.
|
||||
const int x = qMax(viewRect.left(),
|
||||
viewRect.left() + (viewRect.width() - barSize.width()) / 2);
|
||||
const int y = viewRect.bottom() - kBottomMarginPx - barSize.height() + 1;
|
||||
setGeometry(QRect(QPoint(x, y), barSize));
|
||||
}
|
||||
|
||||
void BuildButtonBar::clearActiveButton()
|
||||
@@ -328,29 +339,11 @@ void BuildButtonBar::updateVisibility()
|
||||
{
|
||||
m_buttons[i]->setVisible(m_sim->isBuildingUnlocked(m_types[i]));
|
||||
}
|
||||
// A hidden button leaves the row, so the bar has to take up its new width and
|
||||
// re-center on it (REQ-UI-BUILD-BAR).
|
||||
recenter();
|
||||
}
|
||||
|
||||
void BuildButtonBar::recenter()
|
||||
{
|
||||
if (m_viewRect.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The layout drops hidden buttons from its size hint, but only once it has been
|
||||
// re-run: updateVisibility() calls this straight after setVisible(), before Qt
|
||||
// would get around to it on its own.
|
||||
layout()->activate();
|
||||
|
||||
const QSize barSize = sizeHint();
|
||||
// Centered, except that a bar wider than the view stays flush with its left edge
|
||||
// rather than hanging off both sides.
|
||||
const int x = qMax(m_viewRect.left(),
|
||||
m_viewRect.left() + (m_viewRect.width() - barSize.width()) / 2);
|
||||
const int y = m_viewRect.bottom() - kBottomMarginPx - barSize.height() + 1;
|
||||
setGeometry(QRect(QPoint(x, y), barSize));
|
||||
// A hidden button leaves the row, so the bar takes up a new width and has to be
|
||||
// re-centered on it -- and the widgets that keep clear of the bar have to be placed
|
||||
// against that new rect too, so the whole pass is re-run (REQ-UI-BUILD-BAR).
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<FloatingLayoutInvalidatedEvent>());
|
||||
}
|
||||
|
||||
void BuildButtonBar::onBuildButton(int index)
|
||||
|
||||
Reference in New Issue
Block a user