Refactor of layout manager to add support for all menus (dirty unstable)
This commit is contained in:
parent
23fe07d3d3
commit
c57041a48e
21 changed files with 274 additions and 167 deletions
|
|
@ -2,7 +2,7 @@
|
|||
#include "DockWidget.hpp"
|
||||
|
||||
#include "Editor.hpp"
|
||||
#include "FloatingWidget.hpp"
|
||||
#include "MenuWidgets.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
|
|
@ -40,11 +40,11 @@ namespace tp {
|
|||
mViewport(canvas, editor) {
|
||||
mEditor = editor;
|
||||
|
||||
mPanel.setText("Controls");
|
||||
mPanel.addToMenu(&mNavigationMenu);
|
||||
mPanel.addToMenu(&mRenderMenu);
|
||||
// mPanel.setText("Controls");
|
||||
//mPanel.addToMenu(&mNavigationMenu);
|
||||
//mPanel.addToMenu(&mRenderMenu);
|
||||
|
||||
dockWidget(&mPanel, DockLayout::RIGHT);
|
||||
dockWidget(&mNavigationMenu, DockLayout::RIGHT);
|
||||
setCenterWidget(&mViewport);
|
||||
|
||||
// Render
|
||||
|
|
@ -120,10 +120,10 @@ namespace tp {
|
|||
|
||||
ViewportWidget mViewport;
|
||||
|
||||
FloatingMenu mPanel;
|
||||
FloatingScrollableMenu mPanel;
|
||||
|
||||
// Controls
|
||||
FloatingMenu mRenderMenu;
|
||||
FloatingScrollableMenu mRenderMenu;
|
||||
ButtonWidget mRenderPathTracer;
|
||||
ButtonWidget mRenderRaster;
|
||||
ButtonWidget mRenderDeNoise;
|
||||
|
|
@ -131,7 +131,7 @@ namespace tp {
|
|||
// Navigation
|
||||
enum NavigationType { ORBIT, PAN, ZOOM } mNavigationType = ORBIT;
|
||||
|
||||
FloatingMenu mNavigationMenu;
|
||||
FloatingScrollableMenu mNavigationMenu;
|
||||
ButtonWidget mNavigationPan;
|
||||
ButtonWidget mNavigationOrbit;
|
||||
ButtonWidget mNavigationZoom;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "Sketch3D.hpp"
|
||||
#include "Widget.hpp"
|
||||
#include "DockWidget.hpp"
|
||||
#include "FloatingWidget.hpp"
|
||||
#include "MenuWidgets.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
|
|
@ -150,15 +150,15 @@ namespace tp {
|
|||
private:
|
||||
Sketch3DWidget mViewport;
|
||||
|
||||
FloatingMenu mPanel;
|
||||
FloatingScrollableMenu mPanel;
|
||||
|
||||
FloatingMenu mControls;
|
||||
FloatingScrollableMenu mControls;
|
||||
ButtonWidget mDrawButton;
|
||||
ButtonWidget mMoveButton;
|
||||
ButtonWidget mRotateButton;
|
||||
ButtonWidget mZoomButton;
|
||||
|
||||
FloatingMenu mColorPicker;
|
||||
FloatingScrollableMenu mColorPicker;
|
||||
SliderWidget mRed;
|
||||
SliderWidget mGreen;
|
||||
SliderWidget mBlue;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include "WidgetApplication.hpp"
|
||||
|
||||
#include "RootWidget.hpp"
|
||||
#include "FloatingWidget.hpp"
|
||||
#include "MenuWidgets.hpp"
|
||||
#include "DockWidget.hpp"
|
||||
|
||||
#include "ScrollableLayout.hpp"
|
||||
|
|
@ -19,9 +19,9 @@ public:
|
|||
void exampleAll() {
|
||||
static DockWidget dock;
|
||||
static LabelWidget centralWidget;
|
||||
static FloatingMenu menus[4];
|
||||
static FloatingMenu nestedMenus[4];
|
||||
static FloatingMenu buttons[10];
|
||||
static FloatingScrollableMenu menus[4];
|
||||
static FloatingScrollableMenu nestedMenus[4];
|
||||
static FloatingScrollableMenu buttons[10];
|
||||
|
||||
dock.setCenterWidget(¢ralWidget);
|
||||
|
||||
|
|
@ -36,6 +36,30 @@ public:
|
|||
setRoot(&dock);
|
||||
}
|
||||
|
||||
void exampleCollapsingMenus() {
|
||||
static DockWidget dock;
|
||||
static CollapsingMenuWidget mainMenu;
|
||||
static CollapsingMenuWidget menus[3];
|
||||
static ButtonWidget buttons[5];
|
||||
|
||||
for (auto& menu : menus) {
|
||||
mainMenu.getContainer()->addChild(&menu);
|
||||
}
|
||||
|
||||
menus[0].getContainer()->addChild(&buttons[0]);
|
||||
menus[0].getContainer()->addChild(&buttons[1]);
|
||||
menus[0].getContainer()->addChild(&buttons[2]);
|
||||
|
||||
menus[1].getContainer()->addChild(&buttons[3]);
|
||||
menus[1].getContainer()->addChild(&buttons[4]);
|
||||
|
||||
// dock.addChild(&menus[0]);
|
||||
|
||||
setRoot(&menus[0]);
|
||||
|
||||
// RootWidget::setWidgetArea(mainMenu, { 333, 333, 522, 522 });
|
||||
}
|
||||
|
||||
void exampleBasic() {
|
||||
static Widget widget;
|
||||
static LabelWidget label;
|
||||
|
|
@ -100,8 +124,8 @@ public:
|
|||
|
||||
void exampleNestedMenus() {
|
||||
static DockWidget dock;
|
||||
static FloatingMenu menu1;
|
||||
static FloatingMenu menu2;
|
||||
static FloatingScrollableMenu menu1;
|
||||
static FloatingScrollableMenu menu2;
|
||||
static ButtonWidget buttons[15];
|
||||
|
||||
setRoot(&dock);
|
||||
|
|
@ -173,8 +197,8 @@ public:
|
|||
|
||||
void exampleDock() {
|
||||
static DockWidget dock;
|
||||
static FloatingMenu menu1;
|
||||
static FloatingMenu menu2;
|
||||
static FloatingScrollableMenu menu1;
|
||||
static FloatingScrollableMenu menu2;
|
||||
static ButtonWidget buttons[15];
|
||||
|
||||
setRoot(&dock);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,11 @@ const Vec2<SizePolicy>& WidgetLayout::getSizePolicy() const { return mSizePolicy
|
|||
|
||||
void WidgetLayout::setSizePolicy(SizePolicy x, SizePolicy y) { mSizePolicy = { x, y }; }
|
||||
|
||||
WidgetLayout* WidgetLayout::lay(Widget* w) { return w->getLayout(); }
|
||||
|
||||
RangeF WidgetLayout::pickRange(const RangeF& current, const RangeF& children, const RangeF& parent, bool vertical) const {
|
||||
return current;
|
||||
|
||||
RangeF out;
|
||||
|
||||
switch (mSizePolicy[vertical]) {
|
||||
|
|
@ -44,10 +48,16 @@ RangeF WidgetLayout::pickRange(const RangeF& current, const RangeF& children, co
|
|||
|
||||
void WidgetLayout::clampMinMaxSize() {
|
||||
auto current = getArea();
|
||||
current.size.clamp(mMinSize, mMaxSize);
|
||||
auto minContent = minContentArea();
|
||||
minContent.size.clamp(mMinSize, mMaxSize);
|
||||
current.clamp(minContent);
|
||||
setArea(current);
|
||||
}
|
||||
|
||||
void WidgetLayout::pickMinimalRect(bool dir) {
|
||||
setArea(minContentArea());
|
||||
}
|
||||
|
||||
RangeF WidgetLayout::clampRange(const RangeF& current, const RangeF& child, const RangeF& parent, bool vertical) const {
|
||||
auto out = current;
|
||||
|
||||
|
|
@ -84,13 +94,17 @@ RectF WidgetLayout::getChildrenEnclosure() const {
|
|||
return out;
|
||||
}
|
||||
|
||||
RectF WidgetLayout::getAvailableChildArea() const {
|
||||
RectF WidgetLayout::availableChildArea() const {
|
||||
return getArea().relative();
|
||||
}
|
||||
|
||||
RectF WidgetLayout::minContentArea() const {
|
||||
return getChildrenEnclosure();
|
||||
}
|
||||
|
||||
RectF WidgetLayout::getParentEnclosure() const {
|
||||
DEBUG_ASSERT(parent())
|
||||
if (!parent()) return { { 0, 0 }, mMaxSize };
|
||||
auto out = parent()->getLayout()->getAvailableChildArea();
|
||||
auto out = parent()->getLayout()->availableChildArea();
|
||||
return out;
|
||||
}
|
||||
|
|
@ -5,7 +5,8 @@
|
|||
using namespace tp;
|
||||
|
||||
Widget::Widget() {
|
||||
mArea.setTargetRect({ 100, 100, 10, 10 });
|
||||
mArea.setTargetRect({ 100, 100, 50, 50 });
|
||||
|
||||
setLayout(WidgetManagerInterface::defaultLayout(this));
|
||||
mArea.endAnimation();
|
||||
|
||||
|
|
|
|||
|
|
@ -26,20 +26,7 @@ void BasicLayout::pickRect(bool vertical) {
|
|||
setArea(newArea);
|
||||
}
|
||||
|
||||
void BasicLayout::clampRect() {
|
||||
DEBUG_ASSERT(0)
|
||||
|
||||
auto current = getArea();
|
||||
auto children = getChildrenEnclosure();
|
||||
auto parent = getParentEnclosure();
|
||||
|
||||
auto rangeX = clampRange(current.getRangeX(), children.getRangeX(), parent.getRangeX(), false);
|
||||
auto rangeY = clampRange(current.getRangeY(), children.getRangeY(), parent.getRangeY(), true);
|
||||
|
||||
setArea(RectF(rangeX, rangeY));
|
||||
}
|
||||
|
||||
void BasicLayout::updateLayout(bool vertical) {
|
||||
void BasicLayout::arrangeChildren(bool vertical) {
|
||||
if (children().empty()) return;
|
||||
|
||||
if (vertical) {
|
||||
|
|
@ -57,61 +44,64 @@ void BasicLayout::updateLayout(bool vertical) {
|
|||
}
|
||||
}
|
||||
|
||||
halnf BasicLayout::shrinkLayoutSize(WidgetLayout* widget, halnf diff, bool vertical) {
|
||||
auto area = widget->getArea();
|
||||
auto prevSize = area.size[vertical];
|
||||
area.size[vertical] += diff;
|
||||
widget->setArea(area);
|
||||
//widget->clampMinMaxSize();
|
||||
return widget->getArea().size[vertical] - prevSize;
|
||||
}
|
||||
|
||||
halnf BasicLayout::changeChildSize(tp::Widget* widget, halnf diff, bool vertical) {
|
||||
auto prevSize = widget->getLayout()->getArea().size[vertical];
|
||||
{
|
||||
auto area = widget->getLayout()->getArea();
|
||||
area.size[vertical] += diff;
|
||||
widget->setAreaCache(area);
|
||||
|
||||
widget->getLayout()->clampMinMaxSize();
|
||||
}
|
||||
auto newSize = widget->getLayout()->getArea().size[vertical];
|
||||
return newSize - prevSize;
|
||||
bool BasicLayout::canChange(Widget* widget, bool vertical) {
|
||||
return widget->getLayout()->getSizePolicy()[vertical] == SizePolicy::Expanding;
|
||||
}
|
||||
|
||||
void BasicLayout::adjustLayout(bool vertical) {
|
||||
std::vector<std::pair<Widget*, bool>> contributors;
|
||||
Vec2F contentSize = { 0, 0 };
|
||||
Vec2F availableSize = getArea().size;
|
||||
|
||||
for (auto child : children()) {
|
||||
child->getLayout()->pickRect(vertical);
|
||||
std::vector<std::pair<WidgetLayout*, bool>> contributors;
|
||||
halnf contentSize = 0;
|
||||
|
||||
if (child->getLayout()->getSizePolicy()[vertical] == SizePolicy::Expanding) {
|
||||
contributors.emplace_back( child, true );
|
||||
|
||||
auto area = child->getLayout()->getArea();
|
||||
area.size[vertical] = 0;
|
||||
child->setAreaCache(area);
|
||||
child->getLayout()->clampMinMaxSize();
|
||||
// find contributors
|
||||
for (Widget* child : children()) {
|
||||
if (canChange(child, vertical)) {
|
||||
contributors.emplace_back( lay(child), true );
|
||||
}
|
||||
|
||||
contentSize += child->getLayout()->getArea().size;
|
||||
}
|
||||
|
||||
availableSize -= mLayoutGap * ((halnf) children().size() - 1) + mLayoutMargin * 2;
|
||||
// let each child to chose desired rect
|
||||
for (Widget* child : children()) {
|
||||
if (canChange(child, vertical)) {
|
||||
lay(child)->pickMinimalRect(vertical);
|
||||
} else {
|
||||
lay(child)->pickRect(vertical);
|
||||
}
|
||||
}
|
||||
|
||||
auto diff = availableSize - contentSize;
|
||||
// calculate content size
|
||||
for (Widget* child : children()) {
|
||||
contentSize += lay(child)->getArea().size[vertical];
|
||||
}
|
||||
|
||||
halnf availableSize = getArea().size[vertical] - (mLayoutGap * ((halnf) children().size() - 1) + mLayoutMargin * 2);
|
||||
|
||||
if (availableSize < 0) return;
|
||||
|
||||
halnf totalQuota = availableSize - contentSize;
|
||||
|
||||
// expand or contract as much as possible
|
||||
while (!contributors.empty() && (diff[vertical] != 0)) {
|
||||
auto quota = diff / (halnf) contributors.size();
|
||||
while (!contributors.empty() && (totalQuota != 0)) {
|
||||
halnf quotaPerContributor = totalQuota / (halnf) contributors.size();
|
||||
|
||||
for (auto& contributor : contributors) {
|
||||
if (!contributor.second) continue;
|
||||
|
||||
// contributor.first->endAnimations();
|
||||
auto contribution = changeChildSize(contributor.first, quota[vertical], vertical);
|
||||
|
||||
halnf contribution = shrinkLayoutSize(contributor.first, quotaPerContributor, vertical);
|
||||
if (contribution == 0) {
|
||||
contributor.second = false;
|
||||
}
|
||||
|
||||
diff[vertical] -= contribution;
|
||||
totalQuota -= contribution;
|
||||
}
|
||||
|
||||
// remove useless contributors
|
||||
contributors.erase(
|
||||
std::remove_if(contributors.begin(), contributors.end(), [](auto node) { return !node.second; }),
|
||||
contributors.end()
|
||||
|
|
@ -120,30 +110,31 @@ void BasicLayout::adjustLayout(bool vertical) {
|
|||
|
||||
// set opposite direction size
|
||||
for (auto child : children()) {
|
||||
// if (child->getLayout()->getSizePolicy()[!vertical] != SizePolicy::Minimal) {
|
||||
auto area = child->getLayout()->getArea();
|
||||
area.size[!vertical] = getArea().size[!vertical] - mLayoutMargin * 2;
|
||||
child->setAreaCache(area);
|
||||
// }
|
||||
RectF area = lay(child)->getArea();
|
||||
area.size[!vertical] = getArea().size[!vertical] - mLayoutMargin * 2;
|
||||
child->setAreaCache(area);
|
||||
}
|
||||
|
||||
// set pos
|
||||
halnf iterPos = mLayoutMargin;
|
||||
for (auto child : children()) {
|
||||
auto area = child->getLayout()->getArea();
|
||||
RectF area = lay(child)->getArea();
|
||||
|
||||
area.pos[vertical] = iterPos;
|
||||
area.pos[!vertical] = mLayoutMargin;
|
||||
|
||||
iterPos += area.size[vertical] + mLayoutGap;
|
||||
child->setAreaCache(area);
|
||||
|
||||
// child->updateAnimations();
|
||||
// child->triggerWidgetUpdate("layout changed");
|
||||
lay(child)->setArea(area);
|
||||
}
|
||||
}
|
||||
|
||||
RectF BasicLayout::getAvailableChildArea() const {
|
||||
auto out = WidgetLayout::getAvailableChildArea();
|
||||
RectF BasicLayout::availableChildArea() const {
|
||||
auto out = WidgetLayout::availableChildArea();
|
||||
return out.shrinkFromCenter(mLayoutMargin, true);
|
||||
}
|
||||
|
||||
RectF BasicLayout::minContentArea() const {
|
||||
auto out = WidgetLayout::getChildrenEnclosure();
|
||||
out.shrinkFromCenter(-mLayoutMargin, true);
|
||||
return out;
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ auto DockLayout::getSideFromWidget(Widget* widget) -> Side {
|
|||
return DockLayout::NONE;
|
||||
}
|
||||
|
||||
void DockLayout::updateLayout(bool vertical) {
|
||||
void DockLayout::arrangeChildren(bool vertical) {
|
||||
for (auto child : children()) {
|
||||
child->getLayout()->pickRect(vertical);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using namespace tp;
|
||||
|
||||
void OverlayLayout::updateLayout(bool vertical) {
|
||||
void OverlayLayout::arrangeChildren(bool vertical) {
|
||||
if (vertical) return;
|
||||
|
||||
if (children().empty()) return;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using namespace tp;
|
||||
|
||||
void ScrollableLayout::updateLayout(bool vertical) {
|
||||
void ScrollableLayout::arrangeChildren(bool vertical) {
|
||||
if (vertical) return;
|
||||
|
||||
// TODO : make better interface to get scroller and content widget
|
||||
|
|
@ -44,7 +44,7 @@ void ScrollableLayout::updateWidgetRects(const RectF& area, Widget* content, Scr
|
|||
content->getLayout()->setArea(contentArea);
|
||||
}
|
||||
|
||||
RectF ScrollableLayout::getAvailableChildArea() const {
|
||||
RectF ScrollableLayout::availableChildArea() const {
|
||||
auto out = getArea();
|
||||
// dont constrain on scroll axis
|
||||
out.pos = -FLT_MAX / 4;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "DockLayout.hpp"
|
||||
#include "ScrollableLayout.hpp"
|
||||
#include "BasicLayout.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ void LayoutManager::adjustLayouts() {
|
|||
});
|
||||
|
||||
for (auto& [iter, _] : mLayOrder) {
|
||||
iter->getLayout()->updateLayout(mVertical);
|
||||
iter->getLayout()->arrangeChildren(mVertical);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,10 +93,13 @@ static int sizePolicyDep[3][3] = {
|
|||
int LayoutManager::getLayoutOrder(WidgetLayout* parent, WidgetLayout* child) const {
|
||||
if (!parent || !child) return 0;
|
||||
|
||||
return 1;
|
||||
|
||||
auto policyParent = parent->getSizePolicy()[mVertical];
|
||||
auto policyChild = parent->getSizePolicy()[mVertical];
|
||||
|
||||
if (dynamic_cast<DockLayout*>(parent)) return -1;
|
||||
// if (dynamic_cast<DockLayout*>(parent)) return -1;
|
||||
// if (dynamic_cast<BasicLayout*>(parent)) return -1;
|
||||
// if (dynamic_cast<ScrollableLayout*>(parent)) return -1;
|
||||
|
||||
return sizePolicyDep[int(policyParent)][int(policyChild)];
|
||||
|
|
|
|||
|
|
@ -47,30 +47,3 @@ FloatingLayout* FloatingWidget::layout() { return dynamic_cast<FloatingLayout*>(
|
|||
const FloatingLayout* FloatingWidget::layout() const {
|
||||
return dynamic_cast<const FloatingLayout*>(Widget::getLayout());
|
||||
}
|
||||
|
||||
FloatingMenu::FloatingMenu() : FloatingWidget() {
|
||||
setDebug("float menu", { 0.0, 0.9, 0.1, 0.7 });
|
||||
|
||||
// addChild(&mMenuLayout);
|
||||
|
||||
addChild(&mHeader);
|
||||
addChild(&mBodyLayout);
|
||||
|
||||
mHeader.setText("Menu");
|
||||
|
||||
mHeader.setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mBodyLayout.setSizePolicy(SizePolicy::Expanding, SizePolicy::Expanding);
|
||||
|
||||
mBodyLayout.setLayout(new ScrollableLayout(&mBodyLayout));
|
||||
mBodyLayout.addChild(&mScrollBar);
|
||||
mBodyLayout.addChild(&mContentWidget);
|
||||
|
||||
mContentWidget.setSizePolicy(SizePolicy::Minimal, SizePolicy::Minimal);
|
||||
|
||||
// getLayout()->setLayoutPolicy(LayoutPolicy::Vertical);
|
||||
// mBodyLayout.getLayout()->setLayoutPolicy(LayoutPolicy::Vertical);
|
||||
}
|
||||
|
||||
void FloatingMenu::setText(const std::string& text) {
|
||||
mHeader.setText(text);
|
||||
}
|
||||
|
|
|
|||
58
Widgets/private/widgets/MenuWidgets.cpp
Normal file
58
Widgets/private/widgets/MenuWidgets.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "MenuWidgets.hpp"
|
||||
|
||||
#include "ScrollableLayout.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
CollapsingMenuWidget::CollapsingMenuWidget() {
|
||||
setDebug("Collapsing Menu", {1});
|
||||
|
||||
setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
|
||||
addChild(&mHeader);
|
||||
addChild(&mContent);
|
||||
}
|
||||
|
||||
void CollapsingMenuWidget::process(const EventHandler& events) {
|
||||
mHover = mHeader.getArea().isInside(events.getPointer());
|
||||
|
||||
if (events.isPressed(InputID::MOUSE1) && mHover) setCollapsed(!mContent.getEnabled());
|
||||
}
|
||||
|
||||
void CollapsingMenuWidget::setCollapsed(bool collapsed) {
|
||||
mContent.setEnabled(collapsed);
|
||||
}
|
||||
|
||||
void CollapsingMenuWidget::draw(Canvas& canvas) {
|
||||
canvas.rect(getArea().relative(), colorBG, rounding);
|
||||
if (mHover) {
|
||||
canvas.rect(mHeader.getArea(), colorHover, rounding);
|
||||
}
|
||||
}
|
||||
|
||||
FloatingScrollableMenu::FloatingScrollableMenu() : FloatingWidget() {
|
||||
setDebug("float menu", { 0.0, 0.9, 0.1, 0.7 });
|
||||
|
||||
// addChild(&mMenuLayout);
|
||||
|
||||
addChild(&mHeader);
|
||||
addChild(&mBodyLayout);
|
||||
|
||||
mHeader.setText("Menu");
|
||||
|
||||
mHeader.setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mBodyLayout.setSizePolicy(SizePolicy::Expanding, SizePolicy::Expanding);
|
||||
|
||||
mBodyLayout.setLayout(new ScrollableLayout(&mBodyLayout));
|
||||
mBodyLayout.addChild(&mScrollBar);
|
||||
mBodyLayout.addChild(&mContentWidget);
|
||||
|
||||
mContentWidget.setSizePolicy(SizePolicy::Minimal, SizePolicy::Minimal);
|
||||
|
||||
// getLayout()->setLayoutPolicy(LayoutPolicy::Vertical);
|
||||
// mBodyLayout.getLayout()->setLayoutPolicy(LayoutPolicy::Vertical);
|
||||
}
|
||||
|
||||
void FloatingScrollableMenu::setText(const std::string& text) {
|
||||
mHeader.setText(text);
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ void SliderWidget::process(const EventHandler& events) {
|
|||
}
|
||||
|
||||
void SliderWidget::draw(Canvas& canvas) {
|
||||
canvas.rect(getArea().relative(), mColorBG, mRounding);
|
||||
canvas.rect(getRelativeArea(), mColorBG, mRounding);
|
||||
|
||||
switch (mState) {
|
||||
case IDLE: canvas.rect(getHandleArea(), mColorIdle, mRounding); break;
|
||||
|
|
|
|||
|
|
@ -26,11 +26,20 @@ namespace tp {
|
|||
explicit WidgetLayout(Widget* widget) { mWidget = widget; }
|
||||
virtual ~WidgetLayout() = default;
|
||||
|
||||
virtual void updateLayout(bool vertical) {}
|
||||
|
||||
public:
|
||||
// picks own position and size
|
||||
// modifies only own area
|
||||
virtual void pickRect(bool vertical) {}
|
||||
virtual void clampRect() {}
|
||||
[[nodiscard]] virtual RectF getAvailableChildArea() const;
|
||||
|
||||
// arranges all children layouts inside itself
|
||||
// modifies children areas
|
||||
virtual void arrangeChildren(bool vertical) {}
|
||||
|
||||
// area that any child can have
|
||||
[[nodiscard]] virtual RectF availableChildArea() const;
|
||||
|
||||
// minimal size base on the content of the layout
|
||||
[[nodiscard]] virtual RectF minContentArea() const;
|
||||
|
||||
public:
|
||||
const Vec2F& getMinSize();
|
||||
|
|
@ -39,6 +48,8 @@ namespace tp {
|
|||
[[nodiscard]] const Vec2<SizePolicy>& getSizePolicy() const;
|
||||
void setSizePolicy(SizePolicy x, SizePolicy y);
|
||||
|
||||
static WidgetLayout* lay(Widget* w);
|
||||
|
||||
public:
|
||||
[[nodiscard]] const RectF& getArea() const;
|
||||
[[nodiscard]] RectF getAnimatedArea() const;
|
||||
|
|
@ -49,6 +60,7 @@ namespace tp {
|
|||
|
||||
public:
|
||||
void clampMinMaxSize();
|
||||
void pickMinimalRect(bool dir);
|
||||
|
||||
[[nodiscard]] RangeF pickRange(const RangeF& current, const RangeF& child, const RangeF& parent, bool v) const;
|
||||
[[nodiscard]] RangeF clampRange(const RangeF& current, const RangeF& child, const RangeF& parent, bool v) const;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ namespace tp {
|
|||
void setSizePolicy(SizePolicy x, SizePolicy y);
|
||||
|
||||
void setEnabled(bool val) { mFlags.set(ENABLED, val); }
|
||||
[[nodiscard]] bool getEnabled() const { return mFlags.get(ENABLED); }
|
||||
|
||||
WidgetLayout* getLayout();
|
||||
[[nodiscard]] const WidgetLayout* getLayout() const;
|
||||
|
|
|
|||
|
|
@ -10,17 +10,21 @@ namespace tp {
|
|||
public:
|
||||
explicit BasicLayout(Widget* widget) : WidgetLayout(widget) {}
|
||||
|
||||
void updateLayout(bool vertical) override;
|
||||
void arrangeChildren(bool vertical) override;
|
||||
|
||||
void pickRect(bool vertical) override;
|
||||
void clampRect() override;
|
||||
[[nodiscard]] RectF getAvailableChildArea() const override;
|
||||
|
||||
[[nodiscard]] RectF availableChildArea() const override;
|
||||
[[nodiscard]] RectF minContentArea() const override;
|
||||
|
||||
void setLayoutPolicy(LayoutPolicy layout) { mLayoutPolicy = layout; }
|
||||
|
||||
private:
|
||||
static bool canChange(Widget*, bool);
|
||||
|
||||
private:
|
||||
void adjustLayout(bool vertical);
|
||||
static halnf changeChildSize(Widget*, halnf diff, bool vertical);
|
||||
static halnf shrinkLayoutSize(WidgetLayout* widget, halnf diff, bool vertical);
|
||||
|
||||
private:
|
||||
LayoutPolicy mLayoutPolicy = LayoutPolicy::Vertical;
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ namespace tp {
|
|||
|
||||
public:
|
||||
void pickRect(bool vertical) override {}
|
||||
void clampRect() override {};
|
||||
void updateLayout(bool vertical) override;
|
||||
void arrangeChildren(bool vertical) override;
|
||||
void adjustChildrenRect();
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@ namespace tp {
|
|||
public:
|
||||
explicit OverlayLayout(Widget* widget) : WidgetLayout(widget) {}
|
||||
|
||||
void updateLayout(bool vertical) override;
|
||||
void arrangeChildren(bool vertical) override;
|
||||
|
||||
void pickRect(bool vertical) override {}
|
||||
void clampRect() override {}
|
||||
};
|
||||
}
|
||||
|
|
@ -12,8 +12,8 @@ namespace tp {
|
|||
setSizePolicy(SizePolicy::Expanding, SizePolicy::Expanding);
|
||||
}
|
||||
|
||||
void updateLayout(bool vertical) override;
|
||||
[[nodiscard]] RectF getAvailableChildArea() const override;
|
||||
void arrangeChildren(bool vertical) override;
|
||||
[[nodiscard]] RectF availableChildArea() const override;
|
||||
|
||||
private:
|
||||
void updateWidgetRects(const RectF& area, Widget* content, ScrollableBarWidget* scroller) const;
|
||||
|
|
|
|||
|
|
@ -13,10 +13,8 @@ namespace tp {
|
|||
}
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override;
|
||||
|
|
@ -28,35 +26,4 @@ namespace tp {
|
|||
FloatingLayout* layout();
|
||||
[[nodiscard]] const FloatingLayout* layout() const;
|
||||
};
|
||||
|
||||
class FloatingMenu : public FloatingWidget {
|
||||
public:
|
||||
FloatingMenu();
|
||||
|
||||
public:
|
||||
void addToMenu(Widget* widget) {
|
||||
widget->setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mContentWidget.addChild(widget);
|
||||
}
|
||||
|
||||
const List<Widget*>& getContent() {
|
||||
return mContentWidget.getChildren();
|
||||
}
|
||||
|
||||
void clearChildren() {
|
||||
mContentWidget.clear();
|
||||
}
|
||||
|
||||
void setText(const std::string& text);
|
||||
|
||||
private:
|
||||
// VerticalLayout mMenuLayout;
|
||||
Widget mBodyLayout;
|
||||
Widget mContentWidget;
|
||||
ScrollableBarWidget mScrollBar;
|
||||
|
||||
LabelWidget mHeader;
|
||||
|
||||
// ButtonWidget mTestButton;
|
||||
};
|
||||
}
|
||||
60
Widgets/public/widgets/MenuWidgets.hpp
Normal file
60
Widgets/public/widgets/MenuWidgets.hpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
|
||||
#include "FloatingWidget.hpp"
|
||||
|
||||
namespace tp {
|
||||
class CollapsingMenuWidget : public Widget {
|
||||
public:
|
||||
CollapsingMenuWidget();
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
void draw(Canvas& canvas) override;
|
||||
[[nodiscard]] bool processesEvents() const override { return true; }
|
||||
|
||||
public:
|
||||
void setCollapsed(bool val);
|
||||
LabelWidget* getHeader() { return &mHeader; }
|
||||
Widget* getContainer() { return &mContent; }
|
||||
|
||||
private:
|
||||
bool mHover = false;
|
||||
LabelWidget mHeader;
|
||||
Widget mContent;
|
||||
|
||||
private:
|
||||
halnf rounding = 5;
|
||||
RGBA colorHover = RGBA(0.7);
|
||||
RGBA colorBG = RGBA(0.3);
|
||||
};
|
||||
|
||||
class FloatingScrollableMenu : public FloatingWidget {
|
||||
public:
|
||||
FloatingScrollableMenu();
|
||||
|
||||
public:
|
||||
void addToMenu(Widget* widget) {
|
||||
widget->setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mContentWidget.addChild(widget);
|
||||
}
|
||||
|
||||
const List<Widget*>& getContent() {
|
||||
return mContentWidget.getChildren();
|
||||
}
|
||||
|
||||
void clearChildren() {
|
||||
mContentWidget.clear();
|
||||
}
|
||||
|
||||
void setText(const std::string& text);
|
||||
|
||||
private:
|
||||
// VerticalLayout mMenuLayout;
|
||||
Widget mBodyLayout;
|
||||
Widget mContentWidget;
|
||||
ScrollableBarWidget mScrollBar;
|
||||
|
||||
LabelWidget mHeader;
|
||||
|
||||
// ButtonWidget mTestButton;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue