2014-06-23 00:56:04 +00:00
|
|
|
// Aseprite UI Library
|
2019-10-29 19:37:06 +00:00
|
|
|
// Copyright (C) 2019 Igara Studio S.A.
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
2014-06-23 00:56:04 +00:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ui/panel.h"
|
|
|
|
|
|
|
|
#include "ui/resize_event.h"
|
2015-12-04 00:50:05 +00:00
|
|
|
#include "ui/size_hint_event.h"
|
2014-06-23 00:56:04 +00:00
|
|
|
|
2019-10-29 19:37:06 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-06-23 00:56:04 +00:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
Panel::Panel()
|
2019-10-29 19:37:06 +00:00
|
|
|
: m_multiple(false)
|
2014-06-23 00:56:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::showChild(Widget* widget)
|
|
|
|
{
|
2019-10-29 19:37:06 +00:00
|
|
|
m_multiple = false;
|
2015-12-03 22:46:13 +00:00
|
|
|
for (auto child : children()) {
|
2014-06-23 00:56:04 +00:00
|
|
|
if (!child->isDecorative())
|
|
|
|
child->setVisible(child == widget);
|
|
|
|
}
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
2019-10-29 19:37:06 +00:00
|
|
|
void Panel::showAllChildren()
|
|
|
|
{
|
|
|
|
m_multiple = true;
|
|
|
|
for (auto child : children()) {
|
|
|
|
if (!child->isDecorative())
|
|
|
|
child->setVisible(true);
|
|
|
|
}
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
2014-06-23 00:56:04 +00:00
|
|
|
void Panel::onResize(ResizeEvent& ev)
|
|
|
|
{
|
2019-10-29 19:37:06 +00:00
|
|
|
if (m_multiple) {
|
|
|
|
VBox::onResize(ev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-23 00:56:04 +00:00
|
|
|
// Copy the new position rectangle
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-04 17:39:04 +00:00
|
|
|
setBoundsQuietly(ev.bounds());
|
2014-06-23 00:56:04 +00:00
|
|
|
|
|
|
|
// Set all the children to the same "cpos"
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-04 17:39:04 +00:00
|
|
|
gfx::Rect cpos = childrenBounds();
|
2015-12-03 22:46:13 +00:00
|
|
|
for (auto child : children()) {
|
2014-06-23 00:56:04 +00:00
|
|
|
if (!child->isDecorative())
|
|
|
|
child->setBounds(cpos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:50:05 +00:00
|
|
|
void Panel::onSizeHint(SizeHintEvent& ev)
|
2014-06-23 00:56:04 +00:00
|
|
|
{
|
2019-10-29 19:37:06 +00:00
|
|
|
if (m_multiple) {
|
|
|
|
VBox::onSizeHint(ev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-23 00:56:04 +00:00
|
|
|
gfx::Size maxSize(0, 0);
|
|
|
|
gfx::Size reqSize;
|
|
|
|
|
2015-12-03 22:46:13 +00:00
|
|
|
for (auto child : children()) {
|
2014-06-23 00:56:04 +00:00
|
|
|
if (!child->isDecorative()) {
|
2015-12-04 00:50:05 +00:00
|
|
|
reqSize = child->sizeHint();
|
2014-06-23 00:56:04 +00:00
|
|
|
|
2019-10-29 19:37:06 +00:00
|
|
|
maxSize.w = std::max(maxSize.w, reqSize.w);
|
|
|
|
maxSize.h = std::max(maxSize.h, reqSize.h);
|
2014-06-23 00:56:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasText())
|
2019-10-29 19:37:06 +00:00
|
|
|
maxSize.w = std::max(maxSize.w, textWidth());
|
2014-06-23 00:56:04 +00:00
|
|
|
|
2015-12-04 00:50:05 +00:00
|
|
|
ev.setSizeHint(
|
2015-06-23 22:20:49 +00:00
|
|
|
maxSize.w + border().width(),
|
|
|
|
maxSize.h + border().height());
|
2014-06-23 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ui
|