diff options
author | quou <quou@disroot.org> | 2025-01-14 21:46:29 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-01-14 21:46:29 +1100 |
commit | 729b5a2887912b440b764f967be3949838b78605 (patch) | |
tree | afcd44bc865609713f7ad59c198abba4b9892488 /ui.hpp | |
parent | 274c2ba0eac94a00f942f7f6a78b2b9a1d0759a3 (diff) |
UI slider, float and text inputs
Diffstat (limited to 'ui.hpp')
-rw-r--r-- | ui.hpp | 51 |
1 files changed, 48 insertions, 3 deletions
@@ -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; |