summaryrefslogtreecommitdiff
path: root/ui.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui.hpp')
-rw-r--r--ui.hpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/ui.hpp b/ui.hpp
index abb4f69..9d95827 100644
--- a/ui.hpp
+++ b/ui.hpp
@@ -97,7 +97,7 @@ struct UI {
Vertex_Buffer mesh;
Pipeline* pipeline;
Render_Pass* render_pass;
- Element* root, * hot, * hovered;
+ Element* root, * hot, * hovered, * active;
Rect area;
bool layout_dirty;
@@ -129,6 +129,7 @@ struct UI {
);
void destroy();
void layout(int w, int h);
+ void text_input(const char* buf);
void update(Arena* s);
void render(Arena* s, Texture_Id target);
@@ -148,8 +149,13 @@ struct UI {
click,
destroy,
activate,
- deactivate
+ deactivate,
+ input_changed,
+ input_finalised,
+ text_typed,
+ text_backspaced
} type;
+ void* payload;
};
typedef int (*Message_Handler)(Element* e, const Message& m);
@@ -182,7 +188,7 @@ struct UI {
void add_child(Element* ch);
void remove_child(Element* ch);
- void message(const Message& msg);
+ void message(const Message& msg, bool recurse = false);
void render();
bool enabled();
@@ -221,6 +227,45 @@ struct UI {
void on_render() override;
};
+ typedef int (*Input_Filter)(char ch);
+
+ struct Input : Element {
+ Input_Filter filter;
+ char* buf;
+ int buf_size;
+ Input(UI* ui, Element* parent, Input_Filter f);
+ ~Input();
+ Rect layout(const Rect& avail) override;
+ void on_render() override;
+ void on_message(const Message& m) override;
+ void set_text(const char* t);
+ void add_text(const char* s);
+ };
+
+ struct Float_Input : Input {
+ float val;
+ Float_Input(UI* ui, Element* parent);
+ void on_message(const Message& m) override;
+ void set_val(float v);
+ };
+
+ struct Slider : Element {
+ Float_Input* input;
+ float minval, maxval;
+ int drag_off;
+ bool dragging;
+ Slider(UI* ui, Element* parent, float miv, float mav);
+ Rect layout(const Rect& avail) override;
+ void on_message(const Message& m) override;
+ void on_render() override;
+ void on_update() override;
+
+ int track_w();
+ Rect handle_rect();
+ Rect track_rect();
+ float val_from_coord(int coord);
+ };
+
struct Modal : Element {
Container* contents;
Toolbar* title_bar;