Refactor Layout Manager
This commit is contained in:
parent
e00dec67ba
commit
96b293d1b5
28 changed files with 408 additions and 123 deletions
|
|
@ -19,13 +19,16 @@ namespace tp {
|
|||
};
|
||||
|
||||
class WidgetLayout {
|
||||
friend class DebugManager;
|
||||
|
||||
public:
|
||||
explicit WidgetLayout(Widget* widget) { mWidget = widget; }
|
||||
virtual ~WidgetLayout() = default;
|
||||
|
||||
virtual void pickRect() = 0;
|
||||
virtual void updateLayout(bool vertical) {}
|
||||
|
||||
virtual void pickRect(bool vertical) = 0;
|
||||
virtual void clampRect() = 0;
|
||||
virtual void adjustChildrenRect() = 0;
|
||||
[[nodiscard]] virtual RectF getAvailableChildArea() const;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -37,6 +37,5 @@ namespace tp {
|
|||
|
||||
LayoutManager mLayoutManager;
|
||||
UpdateManager mUpdateManager;
|
||||
DebugManager mDebugManager;
|
||||
};
|
||||
}
|
||||
|
|
@ -5,14 +5,19 @@
|
|||
namespace tp {
|
||||
|
||||
class BasicLayout : public WidgetLayout {
|
||||
friend class DebugManager;
|
||||
|
||||
public:
|
||||
explicit BasicLayout(Widget* widget) : WidgetLayout(widget) {}
|
||||
|
||||
void pickRect() override;
|
||||
void updateLayout(bool vertical) override;
|
||||
|
||||
void pickRect(bool vertical) override;
|
||||
void clampRect() override;
|
||||
void adjustChildrenRect() override;
|
||||
[[nodiscard]] RectF getAvailableChildArea() const override;
|
||||
|
||||
void setLayoutPolicy(LayoutPolicy layout) { mLayoutPolicy = layout; }
|
||||
|
||||
private:
|
||||
void adjustLayout(bool vertical);
|
||||
static halnf changeChildSize(Widget*, halnf diff, bool vertical);
|
||||
|
|
@ -20,6 +25,6 @@ namespace tp {
|
|||
private:
|
||||
LayoutPolicy mLayoutPolicy = LayoutPolicy::Vertical;
|
||||
halnf mLayoutGap = 5;
|
||||
halnf mLayoutMargin = 10;
|
||||
halnf mLayoutMargin = 9;
|
||||
};
|
||||
}
|
||||
|
|
@ -42,9 +42,10 @@ namespace tp {
|
|||
void updatePreviewSide(const Vec2F& pointer);
|
||||
|
||||
public:
|
||||
void pickRect() override {}
|
||||
void adjustChildrenRect() override;
|
||||
void pickRect(bool vertical) override {}
|
||||
void clampRect() override {};
|
||||
void updateLayout(bool vertical) override;
|
||||
void adjustChildrenRect();
|
||||
|
||||
public:
|
||||
bool setCenterWidget(Widget* widget);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace tp {
|
|||
RectF resizeHandleRect();
|
||||
|
||||
public:
|
||||
void pickRect() override;
|
||||
void pickRect(bool vertical) override;
|
||||
|
||||
private:
|
||||
bool mIsFloating = false;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Widget.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace tp {
|
||||
class DebugManager {
|
||||
public:
|
||||
|
|
@ -11,15 +13,38 @@ namespace tp {
|
|||
bool update(RootWidget* rootWidget, EventHandler& events);
|
||||
void drawDebug(RootWidget* rootWidget, Canvas& canvas);
|
||||
|
||||
void checkProcBreakPoints(Widget* widget) {
|
||||
if (mProcBreakpoints.find(widget) != mProcBreakpoints.end()) {
|
||||
mProcBreakpoints.erase(widget);
|
||||
DEBUG_BREAK(1)
|
||||
}
|
||||
}
|
||||
|
||||
void checkLayoutBreakpoints(Widget* widget) {
|
||||
if (mLayBreakpoints.find(widget) != mLayBreakpoints.end()) {
|
||||
mLayBreakpoints.erase(widget);
|
||||
DEBUG_BREAK(1)
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void recursiveDraw(Canvas& canvas, Widget* active, const Vec2F& pos, int depthOrder);
|
||||
|
||||
static void widgetMenu(Widget*);
|
||||
void drawLayoutOrder();
|
||||
|
||||
private:
|
||||
RootWidget* mRootWidget = nullptr;
|
||||
|
||||
// debug
|
||||
bool mDebug = true;
|
||||
bool mDebugStopProcessing = false;
|
||||
bool mDebugRedrawAlways = false;
|
||||
bool mSlowMotion = false;
|
||||
|
||||
std::set<Widget*> mProcBreakpoints;
|
||||
std::set<Widget*> mLayBreakpoints;
|
||||
};
|
||||
|
||||
extern DebugManager gDebugWidget;
|
||||
}
|
||||
|
|
@ -1,11 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include "Layout.hpp"
|
||||
#include "DebugManager.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace tp {
|
||||
class LayoutManager {
|
||||
friend DebugManager;
|
||||
|
||||
struct DepNode {
|
||||
std::vector<Widget*> depends;
|
||||
int references = 0;
|
||||
int depth = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
LayoutManager() = default;
|
||||
|
||||
void adjust(Widget* root);
|
||||
|
||||
private:
|
||||
void findDependencies(Widget* root);
|
||||
void topologicalSort(Widget* root, int depth = 0);
|
||||
void adjustLayouts();
|
||||
|
||||
private:
|
||||
int getLayoutOrder(WidgetLayout* parent, WidgetLayout* child) const;
|
||||
|
||||
private:
|
||||
std::map<Widget*, DepNode> mDepGraph;
|
||||
std::vector<Widget*> mRoots;
|
||||
|
||||
std::vector<std::pair<Widget*, int>> mLayOrder;
|
||||
bool mVertical = false;
|
||||
};
|
||||
}
|
||||
|
|
@ -28,6 +28,9 @@ namespace tp {
|
|||
void processActiveTree(Widget* iter, EventHandler& events, Vec2F pos);
|
||||
void processFocusItems(EventHandler& events);
|
||||
|
||||
private:
|
||||
static void procWidget(Widget* widget, EventHandler& events, bool withEvents = false);
|
||||
|
||||
private:
|
||||
std::map<Widget*, bool> mTriggeredWidgets;
|
||||
Widget* mInFocusWidget = nullptr;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace tp {
|
|||
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override;
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
[[nodiscard]]bool processesEvents() const override { return true; }
|
||||
|
||||
void drawSide(DockLayout::Side side, Canvas& canvas);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue