summaryrefslogtreecommitdiff
path: root/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui.cpp')
-rw-r--r--ui.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/ui.cpp b/ui.cpp
index e20a18c..1e18fc0 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -895,6 +895,46 @@ void UI::Button::on_render() {
);
}
+UI::Checkbox::Checkbox(
+ UI* ui,
+ Element* parent,
+ const char* text
+): Element(ui, parent) {
+ btn = ui->create_element<Button>(this, " ");
+ btn->handler = [](UI::Element* e, const Message& m) {
+ if (m.type == UI::Message::Type::click) {
+ UI::Checkbox* ch = (UI::Checkbox*)e->parent;
+ ch->set_val(!ch->val);
+ }
+ return 0;
+ };
+ label = ui->create_element<Label>(this, text);
+ val = false;
+}
+
+UI::Rect UI::Checkbox::layout(const Rect& avail) {
+ int w;
+ Rect r = avail;
+ Rect br = btn->layout(avail);
+ w = br.w + ui_padding;
+ r.x += w;
+ r.w -= w;
+ r.clip(avail);
+ label->layout(r);
+ bound = Rect(br.x, br.y, br.w + ui_padding * 2, br.h);
+ clip = bound;
+ clip.clip(ui->area);
+ return bound;
+}
+
+void UI::Checkbox::set_val(bool v) {
+ Message msg{};
+ btn->set_text(v? "x": " ");
+ val = v;
+ msg.type = Message::Type::checkbox_changed;
+ message(msg);
+}
+
UI::Input::Input(UI* ui, Element* parent, Input_Filter f):
Element(ui, parent),
filter(f),