Loading...
Searching...
No Matches
ScrollPane.h
Go to the documentation of this file.
1#ifndef MALENA_SCROLLPANE_H
2#define MALENA_SCROLLPANE_H
3
5#include <SFML/Graphics.hpp>
6#include <vector>
10#include "ScrollPaneManifest.h"
11
12namespace ml
13{
14 class MALENA_API ScrollPane : public ml::Component<ScrollPaneManifest>
15 {
16 public:
20
21 ScrollPane(float width, float height);
22
23 void addComponent(ml::Core& component);
24 void removeComponent(ml::Core& component);
25
26 // ── Styling ───────────────────────────────────────────────────────────
29 void setScrollBarWidth(float width);
30
31 // ── Layout ────────────────────────────────────────────────────────────
32 void setPosition(const sf::Vector2f& position) override;
33 sf::Vector2f getPosition() const override;
36 void setSize(float width, float height);
37
38 // ── External scroll control ───────────────────────────────────────────
39
41 [[nodiscard]] float getScrollOffsetY() const;
42
44 void setScrollOffsetY(float y);
45
52 void setContentHeight(float height);
53
84 void embed();
85
86 protected:
87 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
88
89 private:
90 float _width;
91 float _height;
92 float _scrollOffsetY = 0.f;
93 float _scrollOffsetX = 0.f;
94 float _scrollSpeed = 20.f;
95 float _scrollBarWidth = 8.f;
96 float _contentHeightOverride = 0.f;
97
98 sf::Vector2f _position = {0.f, 0.f};
99
100 sf::RectangleShape _background;
101 mutable sf::RectangleShape _scrollBarTrack;
102 mutable ml::Rectangle _scrollBarThumb;
103
104 mutable sf::RenderTexture _renderTexture;
105 std::vector<ml::Core*> _children;
106
107 sf::Color _scrollBarTrackColor = sf::Color(200, 200, 200, 150);
108 sf::Color _scrollBarThumbColor = sf::Color(100, 100, 100, 200);
109
110 void stackChildren() const;
111 float getTotalContentHeight() const;
112 float getTotalContentWidth() const;
113 void updateScrollBar() const;
114 };
115}
116
117#endif //SCROLLPANE_H
Primary base class for all user-facing Malena components.
Definition Component.h:275
Virtual base class for all Malena framework objects.
Definition Core.h:69
A framework-integrated rectangle with optional rounded corners.
Definition Rectangle.h:48
void addComponent(ml::Core &component)
ScrollPane(float width, float height)
void setScrollBarWidth(float width)
void setSize(float width, float height)
void setContentHeight(float height)
Override the content height used for scroll calculations.
sf::RenderStates getRenderStates() const override
sf::FloatRect getGlobalBounds() const override
void setScrollBarColor(sf::Color color)
float getScrollOffsetY() const
Return the current vertical scroll offset in pixels.
void embed()
Silence this ScrollPane from the event system entirely.
void setScrollOffsetY(float y)
Programmatically set the vertical scroll offset (clamped).
ScrollPaneManifest::Flag Flag
Definition ScrollPane.h:19
void setBackgroundColor(sf::Color color)
void setPosition(const sf::Vector2f &position) override
void removeComponent(ml::Core &component)
ScrollPaneManifest::State State
Definition ScrollPane.h:18
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
sf::Vector2f getPosition() const override
ml::ManifestResources< ScrollPaneManifest > App
Definition ScrollPane.h:17
#define MALENA_API
Definition Component.h:22
Rect< float > FloatRect
Vector2< float > Vector2f
Unified manifest resource and config accessor.