Skip to content

Commit 138e133

Browse files
✨ Add rRadio gui element ✨
1 parent 5afd162 commit 138e133

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

lib/gui/src/elements/Radio.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "Radio.hpp"
2+
#include "Image.hpp"
3+
4+
#include <cstdio>
5+
#include <graphics.hpp>
6+
#include <Surface.hpp>
7+
8+
namespace gui::elements {
9+
10+
Radio::Radio(const uint16_t x, const uint16_t y)
11+
{
12+
m_x = x;
13+
m_y = y;
14+
m_width = 20;
15+
m_height = 20;
16+
m_hasEvents = true;
17+
}
18+
19+
Radio::~Radio() = default;
20+
21+
void Radio::render()
22+
{
23+
m_surface->clear(COLOR_WHITE);
24+
25+
m_surface->fillRoundRectWithBorder(0, 0, m_width, m_height, 10, 2, COLOR_WHITE, COLOR_DARK);
26+
27+
if(m_state)
28+
m_surface->fillRoundRect(4, 4, m_width - 8, m_height - 8, 10, COLOR_DARK);
29+
}
30+
31+
void Radio::onReleased() {
32+
setState(!m_state);
33+
}
34+
35+
void Radio::setState(bool state) {
36+
this->m_state = state;
37+
localGraphicalUpdate();
38+
}
39+
40+
bool Radio::getState() {
41+
return m_state;
42+
}
43+
} // gui::elements

lib/gui/src/elements/Radio.hpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef RADIO_HPP
2+
#define RADIO_HPP
3+
4+
#include "../ElementBase.hpp"
5+
#include "Image.hpp"
6+
7+
namespace gui::elements
8+
{
9+
class Radio final : public ElementBase
10+
{
11+
public:
12+
Radio(uint16_t x, uint16_t y);
13+
~Radio() override;
14+
15+
void render() override;
16+
void onReleased();
17+
void setState(bool state);
18+
bool getState();
19+
20+
private:
21+
bool m_state = false;
22+
};
23+
} // gui::elements
24+
25+
#endif

lib/gui/src/gui.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
#include "elements/Checkbox.hpp"
1313
#include "elements/List.hpp"
1414
#include "elements/Button.hpp"
15+
#include "elements/Radio.hpp"
1516

1617
#endif

src/main.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ extern "C" void app_main()
3131
Switch* sw2 = new Switch(10, 150);
3232
sw2->setState(true);*/
3333

34-
VerticalList* list = new VerticalList(40, 200, 40, 300);
34+
VerticalList* list = new VerticalList(40, 100, 40, 300);
3535
for (uint16_t i = 0; i < 3; i++)
3636
list->add(new Switch(0, 0));
3737
list->add(new Checkbox(0, 0));
38+
list->add(new Radio(0, 0));
39+
3840

3941
win.addChild(list);
4042

0 commit comments

Comments
 (0)