Fix floating close button in ColorPopup when the window is too narrow

This commit is contained in:
David Capello 2017-06-22 19:11:46 -03:00
parent 3f5bfa6d99
commit 35764bd969
2 changed files with 19 additions and 4 deletions

View File

@ -175,6 +175,7 @@ ColorPopup::ColorPopup(const ColorButtonOptions& options)
, m_vbox(VERTICAL)
, m_topBox(HORIZONTAL)
, m_color(app::Color::fromMask())
, m_closeButton(nullptr)
, m_colorPaletteContainer(options.showIndexTab ?
new ui::View: nullptr)
, m_colorPalette(options.showIndexTab ?
@ -224,19 +225,18 @@ ColorPopup::ColorPopup(const ColorButtonOptions& options)
// TODO fix this hack for close button in popup window
// Move close button (decorative widget) inside the m_topBox
{
Widget* closeButton = nullptr;
WidgetsList decorators;
for (auto child : children()) {
if (child->type() == kWindowCloseButtonWidget) {
closeButton = child;
m_closeButton = child;
removeChild(child);
break;
}
}
if (closeButton) {
if (m_closeButton) {
m_topBox.addChild(new BoxFiller);
VBox* vbox = new VBox;
vbox->addChild(closeButton);
vbox->addChild(m_closeButton);
m_topBox.addChild(vbox);
}
}
@ -309,6 +309,19 @@ app::Color ColorPopup::getColor() const
return m_color;
}
void ColorPopup::onWindowResize()
{
PopupWindowPin::onWindowResize();
if (m_closeButton) {
gfx::Rect rc = m_closeButton->bounds();
if (rc.x2() > bounds().x2()) {
rc.x = bounds().x2() - rc.w;
m_closeButton->setBounds(rc);
}
}
}
void ColorPopup::onMakeFloating()
{
PopupWindowPin::onMakeFloating();

View File

@ -43,6 +43,7 @@ namespace app {
obs::signal<void(const app::Color&)> ColorChange;
protected:
void onWindowResize() override;
void onMakeFloating() override;
void onMakeFixed() override;
void onColorSlidersChange(ColorSlidersChangeEvent& ev);
@ -72,6 +73,7 @@ namespace app {
ui::TooltipManager m_tooltips;
ui::Box m_topBox;
app::Color m_color;
Widget* m_closeButton;
ui::View* m_colorPaletteContainer;
PaletteView* m_colorPalette;
SimpleColors* m_simpleColors;