5#ifndef MALENA_SPLITPANEL_H
6#define MALENA_SPLITPANEL_H
33 enum class State { IDLE, DIVIDER_HOVER, DIVIDER_DRAG };
95 std::unique_ptr<ml::Core> content;
103 std::vector<Pane> _panes;
108 int _hoveredDivider = -1;
109 int _draggingDiv = -1;
110 float _dragStartMouse = 0.f;
111 float _dragStartSizeA = 0.f;
112 float _dragStartSizeB = 0.f;
113 bool _prevMouseDown =
false;
115 std::function<void(std::size_t,
float)> _onDividerMoved;
118 float totalAvailable()
const;
119 float dividerPos(
int divIdx)
const;
122 void distributeSizes();
123 void drawDivider(sf::RenderTarget& target,
124 const sf::RenderStates& states,
125 int divIdx,
bool hovered,
bool dragging)
const;
145 static_assert(std::is_base_of_v<SplitPanelSettings, S>,
146 "applySettings() requires SplitPanelSettings");
154 static_assert(std::is_base_of_v<SplitPanelTheme, T>,
155 "applyTheme() requires SplitPanelTheme");
159 template<
typename St>
162 static_assert(std::is_base_of_v<SplitPanelSettings, St> &&
163 std::is_base_of_v<SplitPanelTheme, St>,
164 "applyStyle() requires SplitPanelSettings and SplitPanelTheme");
186 T&
addPane(std::unique_ptr<T> content,
float initialSize = 0.f)
188 static_assert(std::is_base_of_v<ml::Core, T>,
189 "addPane() content must derive from ml::Core");
191 T* ptr = content.get();
194 pane.content = std::move(content);
195 pane.size = initialSize;
196 pane.flex = (initialSize == 0.f);
198 if constexpr (detail::has_setSize<T>::value)
199 pane.resizeFn = [ptr](
sf::Vector2f sz){ ptr->setSize(sz); };
201 _panes.push_back(std::move(pane));
219 [[nodiscard]] std::size_t
paneCount()
const {
return _panes.size(); }
236 template<
typename MANIFEST>
static const sf::Font & getDefault()
Return the built-in Arial font.
Base class for all Malena manifests.
void setDividerPosition(std::size_t dividerIndex, float position)
Programmatically set a divider position.
SplitPanel(Orientation orientation=Orientation::HORIZONTAL, const sf::Font &font=FontManager<>::getDefault())
sf::Vector2f getSize() const
void setPosition(const sf::Vector2f &position) override
SplitPanelSettings::Orientation Orientation
SplitPanel(const SplitPanel &)=delete
void applyTheme(const T &t)
sf::Vector2f getPosition() const override
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
void onDividerMoved(std::function< void(std::size_t, float)> cb)
Fired whenever a divider is moved (by drag or API).
void applyStyle(const St &s)
void setPaneMaxSize(std::size_t index, float maxSize)
Set the maximum size of a pane by index.
T & addPane(std::unique_ptr< T > content, float initialSize=0.f)
Add a pane with owned content.
SplitPanelManifest::State State
SplitPanelSettings::HandleStyle HandleStyle
void applySettings(const S &s)
SplitPanelManifest::Flag Flag
SplitPanel & operator=(const SplitPanel &)=delete
void setPaneMinSize(std::size_t index, float minSize)
Set the minimum size of a pane by index.
sf::FloatRect getGlobalBounds() const override
void setSize(const sf::Vector2f &size)
std::size_t paneCount() const
Return the number of panes.
void onThemeApplied(const Theme &theme) override
Called by ThemeManager when the active theme changes.
SplitPanel(Orientation orientation=Orientation::HORIZONTAL, const sf::Font &font=FontManager<>::getDefault())
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Vector2< float > Vector2f
Universal design token set applied across all Themeable components.