Skip to content

Commit 08ef469

Browse files
committed
Add button and scrollbar element families
1 parent d3ac256 commit 08ef469

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

builtin/ui/elem_defs.lua

+2
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ function ui.Grid:_encode_fields()
8989

9090
return ui._encode("ZS", ui.Elem._encode_fields(self), ui._encode_flags(fl))
9191
end
92+
93+
ui.Button = ui._new_type(ui.Elem, "button", 0x04, true)

src/gui/elem.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace ui
4747
CREATE(ROOT, Root);
4848
CREATE(FLEX, Flex);
4949
CREATE(GRID, Grid);
50+
CREATE(BUTTON, Button);
5051
default:
5152
return nullptr;
5253
}

src/gui/elem.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace ui
4444
ROOT = 0x01,
4545
FLEX = 0x02,
4646
GRID = 0x03,
47+
BUTTON = 0x04,
4748
};
4849

4950
private:

src/gui/generic_elems.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,14 @@ namespace ui
6060

6161
Elem::draw(canvas);
6262
}
63+
64+
bool Button::processInput(const SDL_Event &event)
65+
{
66+
bool handled = Elem::processInput(event);
67+
if (getMainBox().wasTriggered()) {
68+
std::cout << "Triggered \"" << getId() << "\"" << std::endl;
69+
}
70+
71+
return handled;
72+
}
6373
}

src/gui/generic_elems.h

+12
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,16 @@ namespace ui
5353

5454
virtual void draw(Canvas &canvas);
5555
};
56+
57+
class Button : public Elem
58+
{
59+
public:
60+
Button(Window &window, std::string id) :
61+
Elem(window, std::move(id), Box::DYNAMIC | Box::HOLDABLE | Box::USE_SPACE)
62+
{}
63+
64+
virtual Type getType() const override { return BUTTON; }
65+
66+
virtual bool processInput(const SDL_Event &event) override;
67+
};
5668
}

0 commit comments

Comments
 (0)