Widget Fixes
This commit is contained in:
parent
047d67c4fa
commit
cfb56e184c
7 changed files with 75 additions and 42 deletions
|
|
@ -4,26 +4,36 @@
|
|||
#include "RootWidget.hpp"
|
||||
#include "FloatingWidget.hpp"
|
||||
#include "DockWidget.hpp"
|
||||
#include "ScrollableWidget.hpp"
|
||||
|
||||
#include "ScrollableLayout.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
|
||||
/*
|
||||
* adjust child widgets in the layout view
|
||||
* make scrollable area
|
||||
* change Widget::clampMinMax function to include child enclosure
|
||||
* refactor all sizing in Widget -> move to separate files
|
||||
* refactor root widget -> reorganize code
|
||||
*/
|
||||
|
||||
|
||||
class WidgetApplication : public Application {
|
||||
public:
|
||||
WidgetApplication() {
|
||||
exampleScrolling();
|
||||
exampleAll();
|
||||
}
|
||||
|
||||
void exampleAll() {
|
||||
static DockWidget dock;
|
||||
static LabelWidget centralWidget;
|
||||
static FloatingMenu menus[4];
|
||||
static FloatingMenu nestedMenus[4];
|
||||
static FloatingMenu buttons[10];
|
||||
|
||||
dock.setCenterWidget(¢ralWidget);
|
||||
|
||||
for (auto& menu : menus) {
|
||||
dock.addChild(&menu);
|
||||
}
|
||||
|
||||
for (auto& menu : nestedMenus) {
|
||||
menus[0].addToMenu(&menu);
|
||||
}
|
||||
|
||||
mRootWidget.setRootWidget(&dock);
|
||||
}
|
||||
|
||||
void exampleScrolling() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ void ScrollableLayout::updateLayout(bool vertical) {
|
|||
|
||||
if (!scroller || !content) return;
|
||||
|
||||
updateWidgetRects(getArea(), content, scroller);
|
||||
updateWidgetRects(getArea().relative(), content, scroller);
|
||||
}
|
||||
|
||||
void ScrollableLayout::updateWidgetRects(const RectF& area, Widget* content, ScrollableBarWidget* scroller) const {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "FloatingWidget.hpp"
|
||||
#include "ScrollableLayout.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
|
|
@ -47,3 +48,25 @@ 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);
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ namespace tp {
|
|||
Widget* mWidget = nullptr;
|
||||
|
||||
protected:
|
||||
Vec2<SizePolicy> mSizePolicy = { SizePolicy::Fixed, SizePolicy::Minimal };
|
||||
Vec2<SizePolicy> mSizePolicy = { SizePolicy::Fixed, SizePolicy::Fixed };
|
||||
Vec2F mMinSize = { 50, 50 };
|
||||
Vec2F mMaxSize = { FLT_MAX / 2, FLT_MAX / 2 };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ namespace tp {
|
|||
class ScrollableLayout : public WidgetLayout {
|
||||
public:
|
||||
explicit ScrollableLayout(Widget* widget) :
|
||||
WidgetLayout(widget) {}
|
||||
WidgetLayout(widget) {
|
||||
setSizePolicy(SizePolicy::Expanding, SizePolicy::Expanding);
|
||||
}
|
||||
|
||||
void updateLayout(bool vertical) override;
|
||||
[[nodiscard]] RectF getAvailableChildArea() const override;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "SimpleWidgets.hpp"
|
||||
#include "FloatingLayout.hpp"
|
||||
#include "ScrollableWidget.hpp"
|
||||
|
||||
namespace tp {
|
||||
class FloatingWidget : public Widget {
|
||||
|
|
@ -30,32 +31,20 @@ namespace tp {
|
|||
|
||||
class FloatingMenu : public FloatingWidget {
|
||||
public:
|
||||
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);
|
||||
|
||||
// getLayout()->setLayoutPolicy(LayoutPolicy::Vertical);
|
||||
// mBodyLayout.getLayout()->setLayoutPolicy(LayoutPolicy::Vertical);
|
||||
}
|
||||
FloatingMenu();
|
||||
|
||||
public:
|
||||
void addToMenu(Widget* widget) {
|
||||
widget->setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mBodyLayout.addChild(widget);
|
||||
mContentWidget.addChild(widget);
|
||||
}
|
||||
|
||||
private:
|
||||
// VerticalLayout mMenuLayout;
|
||||
Widget mBodyLayout;
|
||||
Widget mContentWidget;
|
||||
ScrollableBarWidget mScrollBar;
|
||||
|
||||
LabelWidget mHeader;
|
||||
|
||||
// ButtonWidget mTestButton;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue