Initial size handling
This commit is contained in:
parent
e028ad1a41
commit
b2c393d23a
28 changed files with 543 additions and 135 deletions
|
|
@ -27,13 +27,15 @@ namespace tp {
|
|||
RectF previewHandleArea = {};
|
||||
|
||||
ResizeHandle resizeHandle;
|
||||
|
||||
RectF areaBeforeDocking = {};
|
||||
};
|
||||
|
||||
public:
|
||||
DockLayoutWidget();
|
||||
|
||||
public:
|
||||
void adjustRect() override {}
|
||||
void pickRect() override {}
|
||||
void adjustChildrenRect() override {}
|
||||
|
||||
void process(const EventHandler& events) override;
|
||||
|
|
@ -47,10 +49,11 @@ namespace tp {
|
|||
void setCenterWidget(Widget* widget);
|
||||
|
||||
void dockWidget(Widget* widget, Side side);
|
||||
void undockWidget(Side side);
|
||||
void undockWidget(Side side, bool restoreArea = true);
|
||||
void toggleWidgetVisibility(Side side);
|
||||
|
||||
private:
|
||||
Side getSideFromWidget(Widget*);
|
||||
void calculateSideAreas();
|
||||
void calculateResizeHandles();
|
||||
void handleResizeEvents(const EventHandler& events);
|
||||
|
|
@ -86,9 +89,9 @@ namespace tp {
|
|||
RGBA mResizeHandleColorHovered = RGBA(0.3, 0.3, 0.3, 1);
|
||||
RGBA mResizeHandleColorActive = RGBA(0.6, 0.6, 0.6, 1);
|
||||
RGBA mBackgroundColor = RGBA(0, 0, 0, 1);
|
||||
RGBA mPreviewColor = RGBA(0.6, 0.6, 0.6, 1);
|
||||
RGBA mPreviewColor = RGBA(0.6, 0.6, 0.6, 0.2);
|
||||
|
||||
public:
|
||||
bool mPreview = false;
|
||||
Widget* mPreviewWidget = nullptr;
|
||||
};
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace tp {
|
|||
|
||||
void process(const EventHandler& events) override;
|
||||
|
||||
void adjustRect() override;
|
||||
void pickRect() override;
|
||||
|
||||
void draw(Canvas& canvas) override;
|
||||
|
||||
|
|
@ -20,6 +20,8 @@ namespace tp {
|
|||
|
||||
[[nodiscard]] bool propagateEventsToChildren() const override;
|
||||
|
||||
[[nodiscard]] bool isFloating() const;
|
||||
|
||||
private:
|
||||
bool mIsFloating = false;
|
||||
bool mIsResizing = false;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace tp {
|
|||
// canvas.rect(getRelativeArea(), RGBA(0, 0, 0, 1));
|
||||
}
|
||||
|
||||
void adjustRect() override {
|
||||
void pickRect() override {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,5 +51,7 @@ namespace tp {
|
|||
Widget* mInFocusWidget = nullptr;
|
||||
|
||||
bool mDebug = true;
|
||||
bool mDebugStopProcessing = false;
|
||||
bool mDebugRedrawAlways = false;
|
||||
};
|
||||
}
|
||||
|
|
@ -13,6 +13,19 @@ namespace tp {
|
|||
class Widget {
|
||||
friend class RootWidget;
|
||||
|
||||
public:
|
||||
enum class SizePolicy {
|
||||
Passive,
|
||||
Expand,
|
||||
Contract,
|
||||
};
|
||||
|
||||
enum class LayoutPolicy {
|
||||
Passive,
|
||||
Vertically,
|
||||
Horizontally,
|
||||
};
|
||||
|
||||
public:
|
||||
Widget();
|
||||
virtual ~Widget() = default;
|
||||
|
|
@ -23,6 +36,7 @@ namespace tp {
|
|||
}
|
||||
|
||||
void addChild(Widget* child);
|
||||
void removeChild(Widget* child);
|
||||
|
||||
WidgetManagerInterface* getRoot();
|
||||
|
||||
|
|
@ -31,18 +45,33 @@ namespace tp {
|
|||
void bringToFront();
|
||||
void bringToBack();
|
||||
|
||||
void setSizePolicy(SizePolicy x, SizePolicy y);
|
||||
void setLayoutPolicy(LayoutPolicy layoutPolicy);
|
||||
|
||||
const Vec2F& getMinSize();
|
||||
void setMinSize(const Vec2F& size);
|
||||
|
||||
public:
|
||||
virtual void process(const EventHandler& events) {}
|
||||
virtual void draw(Canvas& canvas) { canvas.rect(mArea.getCurrentRect(), RGBA(1.f), 10); }
|
||||
virtual void draw(Canvas& canvas) {}
|
||||
virtual void drawOverlay(Canvas& canvas) {}
|
||||
|
||||
virtual void mouseEnter();
|
||||
virtual void mouseLeave();
|
||||
|
||||
// size policies
|
||||
virtual void adjustRect();
|
||||
virtual void pickRect();
|
||||
virtual void clampRect();
|
||||
virtual void adjustChildrenRect();
|
||||
|
||||
// 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);
|
||||
RectF getChildrenEnclosure();
|
||||
RectF getParentEnclosure();
|
||||
void adjustLayout(bool vertical);
|
||||
halnf changeChildSize(Widget*, halnf diff, bool vertical);
|
||||
|
||||
[[nodiscard]] virtual bool processesEvents() const;
|
||||
[[nodiscard]] virtual bool propagateEventsToChildren() const;
|
||||
|
||||
|
|
@ -53,7 +82,11 @@ namespace tp {
|
|||
|
||||
public:
|
||||
[[nodiscard]] RectF getArea() const;
|
||||
[[nodiscard]] RectF getAreaT() const;
|
||||
|
||||
[[nodiscard]] RectF getRelativeArea() const;
|
||||
[[nodiscard]] RectF getRelativeAreaT() const;
|
||||
|
||||
void setArea(const RectF& area);
|
||||
|
||||
protected:
|
||||
|
|
@ -65,6 +98,12 @@ namespace tp {
|
|||
// relative to the parent
|
||||
SpringRect mArea;
|
||||
|
||||
// resizing
|
||||
LayoutPolicy mLayoutPolicy = LayoutPolicy::Passive;
|
||||
Vec2<SizePolicy> mSizePolicy = { SizePolicy::Passive, SizePolicy::Passive };
|
||||
Vec2F mMinSize = { 50, 50 };
|
||||
Vec2F mMaxSize = { FLT_MAX / 2, FLT_MAX / 2 };
|
||||
|
||||
bool mInFocus = false;
|
||||
|
||||
// debug
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue