Loading...
Searching...
No Matches
ThumbnailPicker.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4#ifndef MALENA_THUMBNAILPICKER_H
5#define MALENA_THUMBNAILPICKER_H
6
7#pragma once
8
16#include <functional>
17#include <memory>
18#include <string>
19#include <vector>
20
21namespace ml
22{
24 {
25 public:
26 enum class Flag { ACTIVE };
27 };
28
52 class MALENA_API ThumbnailPicker : public ComponentWith<ThumbnailPickerManifest>
53 {
54 public:
56
57 private:
58 std::vector<std::unique_ptr<sf::Texture>> _textures;
59 std::vector<std::string> _captions;
60 std::vector<sf::FloatRect> _cells; // world-space tile rects
61
62 const sf::Font* _font;
63 int _selected = 0;
64 int _columns = 3;
65 float _tileW = 184.f;
66 float _tileH = 128.f;
67 float _gap = 16.f;
68 float _captionH = 24.f;
69 sf::Vector2f _position = {0.f, 0.f};
70 bool _active = false;
71 bool _prevDown = false;
72
73 std::function<void(int)> _onSelectionChanged;
74
75 void layout();
76
77 protected:
78 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
79
80 public:
82
85
86 // ── Content ───────────────────────────────────────────────────────────
87 void clear();
88 void addThumbnail(const sf::Image& image, const std::string& caption);
89 [[nodiscard]] int count() const;
90
91 // ── Layout ────────────────────────────────────────────────────────────
92 void setColumns(int columns);
93 void setTileSize(float w, float h);
94
95 // ── Selection ─────────────────────────────────────────────────────────
96 void setSelectedIndex(int index);
97 [[nodiscard]] int getSelectedIndex() const;
98 void onSelectionChanged(std::function<void(int)> cb);
99
101 void setActive(bool active);
102
103 // ── Positionable ──────────────────────────────────────────────────────
104 void setPosition(const sf::Vector2f& position) override;
105 sf::Vector2f getPosition() const override;
107 };
108
109} // namespace ml
110
111#endif // MALENA_THUMBNAILPICKER_H
static const sf::Font & getDefault()
Return the built-in Arial font.
Base class for all Malena manifests.
Definition Manifest.h:51
ThumbnailPickerManifest::Flag Flag
void addThumbnail(const sf::Image &image, const std::string &caption)
sf::Vector2f getPosition() const override
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
void setPosition(const sf::Vector2f &position) override
void setActive(bool active)
void onSelectionChanged(std::function< void(int)> cb)
void setSelectedIndex(int index)
void setColumns(int columns)
ThumbnailPicker & operator=(const ThumbnailPicker &)=delete
sf::FloatRect getGlobalBounds() const override
void setTileSize(float w, float h)
ThumbnailPicker(const sf::Font &font=FontManager<>::getDefault())
ThumbnailPicker(const ThumbnailPicker &)=delete
int getSelectedIndex() const
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Definition Component.h:323
#define MALENA_API
Definition Animate.h:25
Rect< float > FloatRect
Vector2< float > Vector2f