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;
102 std::vector<Pane> _panes;
107 int _hoveredDivider = -1;
108 int _draggingDiv = -1;
109 float _dragStartMouse = 0.f;
110 float _dragStartSizeA = 0.f;
111 float _dragStartSizeB = 0.f;
112 bool _prevMouseDown =
false;
114 std::function<void(std::size_t,
float)> _onDividerMoved;
117 float totalAvailable()
const;
118 float dividerPos(
int divIdx)
const;
121 void distributeSizes();
122 void drawDivider(sf::RenderTarget& target,
123 const sf::RenderStates& states,
124 int divIdx,
bool hovered,
bool dragging)
const;
142 static_assert(std::is_base_of_v<SplitPanelSettings, S>,
143 "applySettings() requires SplitPanelSettings");
151 static_assert(std::is_base_of_v<SplitPanelTheme, T>,
152 "applyTheme() requires SplitPanelTheme");
156 template<
typename St>
159 static_assert(std::is_base_of_v<SplitPanelSettings, St> &&
160 std::is_base_of_v<SplitPanelTheme, St>,
161 "applyStyle() requires SplitPanelSettings and SplitPanelTheme");
183 T&
addPane(std::unique_ptr<T> content,
float initialSize = 0.f)
185 static_assert(std::is_base_of_v<ml::Core, T>,
186 "addPane() content must derive from ml::Core");
188 T* ptr = content.get();
191 pane.content = std::move(content);
192 pane.size = initialSize;
194 if constexpr (detail::has_setSize<T>::value)
195 pane.resizeFn = [ptr](
sf::Vector2f sz){ ptr->setSize(sz); };
197 _panes.push_back(std::move(pane));
214 [[nodiscard]] std::size_t
paneCount()
const {
return _panes.size(); }
231 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.