Fix sizing issues and others
This commit is contained in:
parent
0b73f8037b
commit
a36386cc20
12 changed files with 325 additions and 142 deletions
|
|
@ -36,7 +36,7 @@ namespace tp {
|
|||
|
||||
public:
|
||||
void pickRect() override {}
|
||||
void adjustChildrenRect() override {}
|
||||
void adjustChildrenRect() override;
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
void draw(Canvas& canvas) override;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@ namespace tp {
|
|||
class FloatingWidget : public Widget {
|
||||
public:
|
||||
FloatingWidget() {
|
||||
setDebug("float", { 0.0, 0.9, 0.1, 0.7 });
|
||||
setDebug("float", { 0.0, 0.9, 0.1, 1 });
|
||||
|
||||
// mSizePolicy = { SizePolicy::Contract, SizePolicy::Contract };
|
||||
mLayoutPolicy = LayoutPolicy::Horizontally;
|
||||
}
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
|
|
@ -18,7 +21,10 @@ namespace tp {
|
|||
|
||||
RectF resizeHandleRect();
|
||||
|
||||
[[nodiscard]] bool needsNextFrame() const override;
|
||||
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override;
|
||||
[[nodiscard]] bool processesEvents() const override { return true; }
|
||||
|
||||
[[nodiscard]] bool isFloating() const;
|
||||
|
||||
|
|
@ -38,24 +44,31 @@ namespace tp {
|
|||
FloatingMenu() {
|
||||
setDebug("float menu", { 0.0, 0.9, 0.1, 0.7 });
|
||||
|
||||
addChild(&mMenuLayout);
|
||||
// addChild(&mMenuLayout);
|
||||
|
||||
mMenuLayout.addChild(&mHeader);
|
||||
mMenuLayout.addChild(&mBodyLayout);
|
||||
addChild(&mHeader);
|
||||
addChild(&mBodyLayout);
|
||||
|
||||
mHeader.setText("Menu");
|
||||
|
||||
mHeader.setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mBodyLayout.setSizePolicy(SizePolicy::Expanding, SizePolicy::Expanding);
|
||||
|
||||
setLayoutPolicy(LayoutPolicy::Vertically);
|
||||
mBodyLayout.setLayoutPolicy(LayoutPolicy::Vertically);
|
||||
}
|
||||
|
||||
public:
|
||||
void addToMenu(Widget* widget) {
|
||||
widget->setSizePolicy(SizePolicy::Expanding, SizePolicy::Minimal);
|
||||
mBodyLayout.addChild(widget);
|
||||
}
|
||||
|
||||
private:
|
||||
VerticalLayout mMenuLayout;
|
||||
VerticalLayout mBodyLayout;
|
||||
// VerticalLayout mMenuLayout;
|
||||
Widget mBodyLayout;
|
||||
LabelWidget mHeader;
|
||||
|
||||
ButtonWidget mTestButton;
|
||||
// ButtonWidget mTestButton;
|
||||
};
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ namespace tp {
|
|||
RootWidget() { setDebug("root", RGBA(1)); }
|
||||
|
||||
void setRootWidget(Widget* widget);
|
||||
void updateWidget(Widget*);
|
||||
void updateWidget(Widget*, const char* reason = nullptr) override;
|
||||
|
||||
static void setWidgetArea(Widget& widget, const RectF& rect);
|
||||
|
||||
|
|
@ -37,16 +37,18 @@ namespace tp {
|
|||
void findFocusWidget(Widget* iter, Widget** focus, const Vec2F& pointer);
|
||||
void handleFocusChanges(EventHandler& events);
|
||||
void getWidgetPath(Widget* widget, std::vector<Widget*>& out);
|
||||
void processActiveTree(ActiveTreeNode* iter, EventHandler& events);
|
||||
void processActiveTree(ActiveTreeNode* iter, EventHandler& events, Vec2F pos);
|
||||
void processFocusItems(EventHandler& events);
|
||||
void adjustSizes(ActiveTreeNode* iter);
|
||||
void updateAreaCache(ActiveTreeNode* iter, bool read);
|
||||
static void debugDrawWidget(Widget* widget);
|
||||
|
||||
private:
|
||||
RectF mScreenArea;
|
||||
Widget* mRoot = nullptr;
|
||||
|
||||
// frame to frame changes
|
||||
std::set<Widget*> mTriggeredWidgets;
|
||||
std::map<Widget*, bool> mTriggeredWidgets;
|
||||
std::map<Widget*, ActiveTreeNode> mWidgetsToProcess;
|
||||
Widget* mInFocusWidget = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ namespace tp {
|
|||
|
||||
public:
|
||||
enum class SizePolicy {
|
||||
Passive,
|
||||
Expand,
|
||||
Contract,
|
||||
Fixed,
|
||||
Expanding,
|
||||
Minimal,
|
||||
};
|
||||
|
||||
enum class LayoutPolicy {
|
||||
|
|
@ -40,7 +40,7 @@ namespace tp {
|
|||
|
||||
WidgetManagerInterface* getRoot();
|
||||
|
||||
void triggerWidgetUpdate();
|
||||
void triggerWidgetUpdate(const char* reason = nullptr);
|
||||
|
||||
void bringToFront();
|
||||
void bringToBack();
|
||||
|
|
@ -67,6 +67,9 @@ namespace tp {
|
|||
// resizing
|
||||
RangeF pickRange(const RangeF& current, const RangeF& children, const RangeF& parent, bool vertical);
|
||||
RangeF clampRange(const RangeF& current, const RangeF& children, const RangeF& parent, bool vertical);
|
||||
|
||||
void clampMinMaxSize();
|
||||
|
||||
RectF getChildrenEnclosure();
|
||||
RectF getParentEnclosure();
|
||||
void adjustLayout(bool vertical);
|
||||
|
|
@ -83,11 +86,14 @@ namespace tp {
|
|||
public:
|
||||
[[nodiscard]] RectF getArea() const;
|
||||
[[nodiscard]] RectF getAreaT() const;
|
||||
[[nodiscard]] RectF getAreaCache() const;
|
||||
|
||||
[[nodiscard]] RectF getRelativeArea() const;
|
||||
[[nodiscard]] RectF getRelativeAreaT() const;
|
||||
[[nodiscard]] RectF getRelativeAreaCache() const;
|
||||
|
||||
void setArea(const RectF& area);
|
||||
void setAreaCache(const RectF& area);
|
||||
|
||||
protected:
|
||||
Widget* mParent = nullptr;
|
||||
|
|
@ -100,20 +106,28 @@ namespace tp {
|
|||
|
||||
// resizing
|
||||
LayoutPolicy mLayoutPolicy = LayoutPolicy::Passive;
|
||||
Vec2<SizePolicy> mSizePolicy = { SizePolicy::Passive, SizePolicy::Passive };
|
||||
Vec2<SizePolicy> mSizePolicy = { SizePolicy::Fixed, SizePolicy::Fixed };
|
||||
Vec2F mMinSize = { 50, 50 };
|
||||
Vec2F mMaxSize = { FLT_MAX / 2, FLT_MAX / 2 };
|
||||
|
||||
bool mInFocus = false;
|
||||
|
||||
halnf mLayoutGap = 5;
|
||||
halnf mLayoutMargin = 10;
|
||||
|
||||
// cache
|
||||
RectF mAreaCache;
|
||||
|
||||
// debug
|
||||
int inOutCallbacks = 0;
|
||||
std::string mName = "widget base";
|
||||
Vec2F mLocalPoint;
|
||||
Vec2F mGlobalPoint;
|
||||
RGBA mDebugColor = { 1, 1, 1, 0.3 };
|
||||
std::string mTriggerReason = "none";
|
||||
};
|
||||
|
||||
struct WidgetManagerInterface : public Widget {
|
||||
virtual void updateWidget(Widget*) = 0;
|
||||
virtual void updateWidget(Widget*, const char* reason = nullptr) = 0;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue