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_input.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <functional>
8#include <vector>
9
17class UIInput : public UIInteractable {
18 public:
20 const std::string& placeholder = "", const std::string& font = "",
21 const std::string& font_path = "",
22 const std::string& sprite_path = "");
23
24 void update(float dt) override;
25
26 void add_on_focus(const std::function<void(UIInput&)>& handler);
27 void add_on_unfocus(const std::function<void(UIInput&)>& handler);
28 void add_on_text_changed(const std::function<void(UIInput&)>& handler);
29
30 void on_hover() override;
31 void on_unhover() override;
32 void on_focus() override;
33 void on_unfocus() override;
34
35 [[nodiscard]] std::string text() const;
36 UIInput& text(const std::string& value);
37
39 UIInput& text_color(const Color& color);
40
41 [[nodiscard]] int font_size() const;
42 UIInput& font_size(int size);
43
45 UIInput& input_color(const Color& color);
46
47 private:
48 void trigger_on_focus();
49 void trigger_on_unfocus();
50 void trigger_on_text_changed();
51
52 std::vector<std::function<void(UIInput&)>> on_focus_handlers_;
53 std::vector<std::function<void(UIInput&)>> on_unfocus_handlers_;
54 std::vector<std::function<void(UIInput&)>> on_text_changed_handlers_;
55
56 std::string content_;
57};
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 input field element.
Definition ui_input.h:17
UIInput(Scene &scene, float width, float height, Point pivot, Point anchor, const std::string &placeholder="", const std::string &font="", const std::string &font_path="", const std::string &sprite_path="")
void on_hover() override
Event hook for when the element is hovered.
void on_unhover() override
Event hook for when the element is unhovered.
std::string text() const
Color text_color() const
void add_on_focus(const std::function< void(UIInput &)> &handler)
void on_unfocus() override
Event hook for when the element loses focus.
UIInput & input_color(const Color &color)
UIInput & font_size(int size)
UIInput & text_color(const Color &color)
Color input_color() const
void add_on_text_changed(const std::function< void(UIInput &)> &handler)
void update(float dt) override
Update the UI object.
void on_focus() override
Event hook for when the element gains focus.
int font_size() const
void add_on_unfocus(const std::function< void(UIInput &)> &handler)
UIInput & text(const std::string &value)
Base class for interactive UI elements.
Definition ui_interactable.h:28
Point pivot() const
float height() const
Point anchor() const
float width() const