Euphoria
widgets.h
Go to the documentation of this file.
1#pragma once
2#include <SDL_keycode.h>
3
4#include "eustb_textedit_string.h"
5#include "eu/base/colors.h"
6#include "eu/base/rect.h"
7#include "eu/base/vec2.h"
8
9namespace eu::render
10{
11 struct DrawableFont;
12 struct Texture2d;
13 struct SpriteBatch;
14}
15
16namespace eu::mrgui
17{
18 struct IdStack
19 {
20 [[nodiscard]] u32 get(const std::string& str) const;
21 [[nodiscard]] u32 get(int id) const;
22
23 void push(const std::string& str);
24 void push(int id);
25
26 void pop();
27
28 [[nodiscard]] u32 last_id() const;
29
30 std::vector<u32> stack;
31 };
32
38
39 struct UiState
40 {
41 v2 mouse = { 0,0 };
42 bool mousedown = false;
43 std::optional<u32> hot_item = std::nullopt;
44 std::optional<u32> active_item = std::nullopt;
45 bool active_item_locked = false;
46
47 std::optional<u32> kbd_item = std::nullopt;
48 std::optional<u32> last_widget = std::nullopt;
49 std::optional<KeyboardInput> key = std::nullopt; // todo(Gustav): change to a vector
50 std::optional<char> keychar = std::nullopt; // todo(Gustav): change to a vector
51
53
54 void begin();
55
56 void end();
57
58 [[nodiscard]] bool is_active_free() const;
59 };
60
61 // Simple button IMGUI widget
63
65
66 bool button_texture(u32 id, const Rect& rect, UiState& uistate, render::SpriteBatch* batch, const render::Texture2d* texture, const Rect& active, const Rect& hot, const Rect& normal);
67
68 bool slider(u32 id, float* val, const Rect& rect, UiState& uistate, render::SpriteBatch* batch);
69
70
71 void draw_text(render::SpriteBatch* batch, render::DrawableFont* font, const std::string& str, float size, const v2& pos, const Rgb& color);
72
73 bool textfield(u32 id, std::string* val, render::DrawableFont* font, float size, const v2& pos, UiState& uistate, render::SpriteBatch* batch);
74
75
76}
bool basic_button(u32 id, const Rect &rect, UiState &uistate, render::SpriteBatch *batch)
bool slider(u32 id, float *val, const Rect &rect, UiState &uistate, render::SpriteBatch *batch)
bool textfield(u32 id, std::string *val, render::DrawableFont *font, float size, const v2 &pos, UiState &uistate, render::SpriteBatch *batch)
bool button_logic(u32 id, const Rect &rect, UiState &uistate)
void draw_text(render::SpriteBatch *batch, render::DrawableFont *font, const std::string &str, float size, const v2 &pos, const Rgb &color)
bool button_texture(u32 id, const Rect &rect, UiState &uistate, render::SpriteBatch *batch, const render::Texture2d *texture, const Rect &active, const Rect &hot, const Rect &normal)
Definition ui.h:4
std::uint32_t u32
Definition ints.h:14
std::uint16_t u16
Definition ints.h:13
A (inclusive) range between two values.
Definition range.h:19
Represents color in gamma (non-linear) space (aka sRGB).
Definition colors.h:14
u32 get(int id) const
void push(int id)
u32 get(const std::string &str) const
std::vector< u32 > stack
Definition widgets.h:30
void push(const std::string &str)
u32 last_id() const
std::optional< KeyboardInput > key
Definition widgets.h:49
std::optional< u32 > active_item
Definition widgets.h:44
bool is_active_free() const
TextEditState text_state
Definition widgets.h:52
std::optional< u32 > kbd_item
Definition widgets.h:47
std::optional< u32 > hot_item
Definition widgets.h:43
std::optional< char > keychar
Definition widgets.h:50
bool active_item_locked
Definition widgets.h:45
std::optional< u32 > last_widget
Definition widgets.h:48
A 2d image texture.
Definition texture.h:72
a 2d vector
Definition vec2.h:17