Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
ui_button.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <functional>
7
15class UIButton : public UIInteractable {
16 public:
18 const std::string& label = "", const std::string& font = "",
19 const std::string& font_path = "",
20 const std::string& sprite_path = "");
21
22 void update(float dt) override;
23
24 void add_on_press(const std::function<void(UIButton&)>& handler);
25
26 void on_hover() override;
27 void on_unhover() override;
28
29 void on_press() override;
30 void on_release() override;
31
32 [[nodiscard]] std::string label() const;
33 UIButton& label(const std::string& label);
34
36 UIButton& label_color(const Color& color);
37
38 [[nodiscard]] int font_size() const;
39 UIButton& font_size(int size);
40
42 UIButton& button_color(const Color& color);
43
44 private:
45 void trigger_on_press();
46
47 std::vector<std::function<void(UIButton&)>> on_press_handlers_;
48};
Represents a color with red, green, blue, and alpha components. Each component is represented as an u...
Definition color.h:7
std::optional< std::reference_wrapper< T > > get_component() const noexcept
Get the first component of type T attached to this GameObject.
Definition gameObject.h:141
Scene & scene() const noexcept
Represents a point in 2D space.
Definition point.h:6
Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecyc...
Definition scene.h:19
A UI button element.
Definition ui_button.h:15
void add_on_press(const std::function< void(UIButton &)> &handler)
Color label_color() const
Color button_color() const
void on_press() override
Event hook for when the element is pressed.
UIButton & font_size(int size)
int font_size() const
void on_release() override
Event hook for when the element is released.
UIButton(Scene &scene, float width, float height, Point pivot, Point anchor, const std::string &label="", const std::string &font="", const std::string &font_path="", const std::string &sprite_path="")
std::string label() const
UIButton & label_color(const Color &color)
void on_unhover() override
Event hook for when the element is unhovered.
void update(float dt) override
Update the UI object.
UIButton & button_color(const Color &color)
void on_hover() override
Event hook for when the element is hovered.
UIButton & label(const std::string &label)
Base class for interactive UI elements.
Definition ui_interactable.h:28
Point pivot() const
float height() const
Point anchor() const
float width() const