Loading...
Searching...
No Matches
ColorChooser.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_COLORCHOOSER_H
5#define MALENA_COLORCHOOSER_H
6
7#pragma once
8
18#include <cstddef>
19#include <functional>
20#include <string>
21
22namespace ml
23{
36 {
37 public:
38 enum class Layout { Tabbed, Stacked, GradientOnly, SwatchesOnly };
39
41
43 void onColorSelected(std::function<void(const sf::Color&)> cb);
45 void onColorChanged(std::function<void(const sf::Color&)> cb);
46
47 void setColor(const sf::Color& c);
48 [[nodiscard]] sf::Color color() const { return _current; }
49
51 void setMaxSwatches(int max);
52
53 void setLayout(Layout layout);
54 [[nodiscard]] Layout getLayout() const { return _layout; }
55 void showTab(int index);
56
57 void setOpen(bool open);
58 [[nodiscard]] bool isOpen() const { return _open; }
59
60 void setPosition(const sf::Vector2f& pos) override;
61 void setSize(const sf::Vector2f& size);
62
63 private:
64 void relayout();
65 void applyVisibility();
66 void setHexMode(bool hex);
67 void setCurrent(const sf::Color& c, bool notify);
68 void commit(const sf::Color& c); // deliberate pick → recent + onColorSelected
69 void recordRecent(const sf::Color& c);
70 void syncInputs();
71
72 static std::string toHex(const sf::Color& c);
73
74 Toolbar _tabs;
75 GradientColorPicker _gradient;
76 ColorPicker _swatches; // saved palette (capped; right-click delete)
77 ColorPicker _recent; // auto recent colors (max 16)
78
79 SegmentToggle _modeToggle; // RGB | HEX
80 TextInput _hexInput; // "#RRGGBB"
81 TextInput _rInput, _gInput, _bInput; // 0-255 each
82 Toolbar _actionBar{ iconFont() }; // [💾 save] [✓ done] (icon font)
83 ContextMenu _menu; // right-click swatch menu (Delete)
84
85 std::size_t _iSave = 0, _iDone = 0;
86
87 Layout _layout = Layout::Tabbed;
88 std::size_t _iColor = 0, _iSwatch = 0;
89 int _active = 0;
90 bool _open = true;
91 bool _hexMode = true;
92
93 sf::Color _current { 30, 30, 30 };
94
95 std::function<void(const sf::Color&)> _onColorSelected;
96 std::function<void(const sf::Color&)> _onColorChanged;
97 };
98
99} // namespace ml
100
101#endif // MALENA_COLORCHOOSER_H
sf::Color color() const
void onColorChanged(std::function< void(const sf::Color &)> cb)
void setSize(const sf::Vector2f &size)
void setOpen(bool open)
void setPosition(const sf::Vector2f &pos) override
Set the world-space position immediately (no animation).
void setMaxSwatches(int max)
void setLayout(Layout layout)
void showTab(int index)
bool isOpen() const
void onColorSelected(std::function< void(const sf::Color &)> cb)
Layout getLayout() const
void setColor(const sf::Color &c)
A reusable swatch grid for choosing a color.
Definition ColorPicker.h:34
A reusable right-click / pop-up menu: a small list of labeled items shown at a point that runs an act...
Definition ContextMenu.h:35
A Photoshop-style HSV color picker: a saturation/value gradient square plus a vertical hue bar....
Two-option segmented selector with animated sliding pill.
Single-line rich text input with horizontal scrolling.
Definition TextInput.h:48
A horizontal or vertical strip of buttons, separators, and components.
Definition Toolbar.h:83
#define MALENA_API
Definition Component.h:22
MALENA_API const sf::Font & iconFont()
The bundled Material Icons font (Apache-2.0). Use with Icon codepoints to render crisp UI glyphs.
Vector2< float > Vector2f