ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
SplitPane.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include "Common.hpp"
9#include "Layout.hpp"
10
11#include <functional>
12#include <string_view>
13
14namespace ZenitUI::UI
15{
19
26
39 class SplitPane : public TLayout<SplitPane>
40 {
41 public:
42 static constexpr const char *PART_SPLITTER = "splitter";
43
46 {
47 float firstSize{0.0f};
48 float splitterSize{0.0f};
49 float secondSize{0.0f};
50 };
51
58 float initialRatio = 0.5f);
59
61 void setPanes(std::shared_ptr<Layout> first, std::shared_ptr<Layout> second);
62
64 std::shared_ptr<Layout> firstPane() const;
65
67 std::shared_ptr<Layout> secondPane() const;
68
69 void setOrientation(SplitOrientation o);
70 SplitOrientation getOrientation() const noexcept { return orientation_; }
71
73 void setRatio(float r, bool notify = false);
74 float getRatio() const noexcept { return ratio_; }
75
77 void setSplitterSize(float px);
78 float getSplitterSize() const noexcept { return splitterSize_; }
79
81 void setMinPaneSize(float px);
82
84 void setMinPaneSizes(float firstPx, float secondPx);
85
86 float getMinFirstSize() const noexcept { return minFirst_; }
87 float getMinSecondSize() const noexcept { return minSecond_; }
88
90 Rect getSplitterRect() const noexcept { return splitterRect_; }
91
93 bool isDragging() const noexcept { return dragging_; }
94
96 static bool parseOrientation(std::string_view s, SplitOrientation &out) noexcept;
97
104 static AxisLayout computeAxisLayout(float totalAxis,
105 float ratio,
106 float splitterSize,
107 float minFirst,
108 float minSecond) noexcept;
109
111 std::function<void(float)> onRatioChanged;
112
113 void arrange(Rect space) override;
114
115 protected:
116 Vec2 computeIntrinsicSize(float availW, float availH) override;
117 void onUpdate(float dt) override;
118 void onEnabledChanged(bool nowEnabled) override;
119 void renderContent(float op, const ComputedStyle &style) override;
120
121 private:
122 void collectPanes(std::shared_ptr<Layout> &outFirst,
123 std::shared_ptr<Layout> &outSecond) const;
124 void updateSplitterCursor(bool active);
125
127 float ratio_{0.5f};
128 float splitterSize_{6.0f};
129 float minFirst_{40.0f};
130 float minSecond_{40.0f};
131
132 Rect innerRect_{0, 0, 0, 0};
133 Rect splitterRect_{0, 0, 0, 0};
134 float usableAxis_{0.0f};
135
136 bool dragging_{false};
137 bool splitterHovered_{false};
138 float dragGrabOffset_{0.0f};
139 };
140
142} // namespace ZenitUI::UI
Centralized standard library includes used throughout ZenitUI.
The node class: tree structure, layout pass, style resolution, input dispatch, render orchestration,...
TLayout(Args &&...args)
Definition Layout.hpp:1401
void onUpdate(float dt) override
Called every frame from update, after input dispatch.
std::shared_ptr< Layout > secondPane() const
Second visible normal-flow pane, or nullptr.
void setSplitterSize(float px)
Set divider thickness in pixels (clamped to >= 1).
Vec2 computeIntrinsicSize(float availW, float availH) override
Compute the intrinsic size, excluding padding and border.
void renderContent(float op, const ComputedStyle &style) override
Draw the node's content (text, images, custom geometry).
static AxisLayout computeAxisLayout(float totalAxis, float ratio, float splitterSize, float minFirst, float minSecond) noexcept
Pure 1D split computation respecting divider thickness and min pane sizes.
static bool parseOrientation(std::string_view s, SplitOrientation &out) noexcept
Parse "horizontal" or "vertical".
Rect getSplitterRect() const noexcept
Screen-space rect of the divider bar (zero when fewer than 2 visible panes).
Definition SplitPane.hpp:90
void setPanes(std::shared_ptr< Layout > first, std::shared_ptr< Layout > second)
Replace all children with first and second.
SplitPane(SplitOrientation orientation=SplitOrientation::Horizontal, float initialRatio=0.5f)
Construct a split container.
void onEnabledChanged(bool nowEnabled) override
Called from setEnabled after the state change.
void setMinPaneSize(float px)
Set the same minimum size in pixels for both panes.
bool isDragging() const noexcept
true while the user is actively dragging the divider.
Definition SplitPane.hpp:93
void setMinPaneSizes(float firstPx, float secondPx)
Set independent minimum sizes in pixels for the first and second pane.
void setRatio(float r, bool notify=false)
Set the split ratio in [0, 1]; fires onRatioChanged if notify is true.
void arrange(Rect space) override
Assign a screen rect to this node and lay out its children.
std::shared_ptr< Layout > firstPane() const
First visible normal-flow pane, or nullptr.
std::function< void(float)> onRatioChanged
Fired whenever the user drags, steps via keyboard, or calls setRatio(r, true).
Definition SplitPane.hpp:111
SplitOrientation
Split axis of a SplitPane.
Definition SplitPane.hpp:22
@ Vertical
Panes arranged top and bottom (horizontal divider).
Definition SplitPane.hpp:24
@ Horizontal
Panes arranged left and right (vertical divider).
Definition SplitPane.hpp:23
Dense style: every property has a concrete value.
Definition Style.hpp:1036
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46
Result of splitting a 1D axis into first pane, divider, and second pane.
Definition SplitPane.hpp:46
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25