Loading...
Searching...
No Matches
ColorButton.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_COLORBUTTON_H
5#define MALENA_COLORBUTTON_H
6
7#pragma once
8
12#include <functional>
13
14namespace ml
15{
24 class MALENA_API ColorButton : public Graphic<sf::RectangleShape>
25 {
26 public:
28
29 void setColor(const sf::Color& c);
30 [[nodiscard]] sf::Color color() const { return _color; }
31
34 void setColorProvider(std::function<sf::Color()> provider);
35
36 void onClick(std::function<void()> cb);
37
38 void setSize(const sf::Vector2f& size);
39 [[nodiscard]] sf::Vector2f getSize() const { return _size; }
40
41 void setPosition(const sf::Vector2f& pos) override;
42 [[nodiscard]] sf::Vector2f getPosition() const override;
43 [[nodiscard]] sf::FloatRect getGlobalBounds() const override;
44
45 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
46
47 private:
48 sf::Color _color { 30, 30, 30 };
49 sf::Vector2f _pos { 0.f, 0.f };
50 sf::Vector2f _size { 26.f, 26.f };
51 bool _prevMouseDown = false;
52 mutable bool _hover = false;
53 std::function<void()> _onClick;
54 std::function<sf::Color()> _colorProvider;
55 };
56
57} // namespace ml
58
59#endif // MALENA_COLORBUTTON_H
void onClick(std::function< void()> cb)
void setColorProvider(std::function< sf::Color()> provider)
sf::FloatRect getGlobalBounds() const override
Return the axis-aligned bounding box in world space.
sf::Vector2f getSize() const
Definition ColorButton.h:39
sf::Vector2f getPosition() const override
Return the current world-space position.
sf::Color color() const
Definition ColorButton.h:30
void setPosition(const sf::Vector2f &pos) override
Set the world-space position immediately (no animation).
void setColor(const sf::Color &c)
void setSize(const sf::Vector2f &size)
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
#define MALENA_API
Definition Component.h:22
Rect< float > FloatRect
Vector2< float > Vector2f