Esp32-RBGridUI
Library for creating UIs for the RBController app
Loading...
Searching...
No Matches
select.h
Go to the documentation of this file.
1#pragma once
2
3#include "widget.h"
4
5#include <cstring>
6#include <iostream>
7#include <iterator>
8#include <vector>
9
10namespace gridui {
11
14class Select : public Widget {
15 template <typename Self, typename Finished>
17
18 using Widget::Widget;
19
20public:
21 void setColor(const std::string& color) {
22 m_state->set("color", new rbjson::String(color));
23 }
24
25 std::string color() const {
26 return data().getString("color");
27 }
28
29 void setBackground(const std::string& background) {
30 m_state->set("background", new rbjson::String(background));
31 }
32
33 std::string background() const {
34 return data().getString("background");
35 }
36
37 void setOptions(const std::vector<std::string>& options) {
38 std::string out = "";
39 for (auto& option : options) {
40 out.append(option);
41 }
42 m_state->set("options", new rbjson::String(out));
43 }
44
45 void setOptions(const std::string& options) {
46 m_state->set("options", new rbjson::String(options));
47 }
48
49 std::vector<std::string> options() const {
50 std::vector<std::string> out;
51 std::string str = data().getString("options");
52 std::string::size_type lastDelim = 0;
53 std::string::size_type delim = 0;
54
55 do {
56 delim = str.find(',', lastDelim);
57 out.push_back(str.substr(lastDelim, delim - lastDelim));
58 lastDelim = delim;
59 } while (delim != std::string::npos);
60
61 return out;
62 }
63
64 void setSelectedIndex(int index) {
65 m_state->set("selectedIndex", new rbjson::Number(index));
66 }
67
68 int selectedIndex() const {
69 return data().getInt("selectedIndex");
70 }
71
72 void setDisabled(bool disabled) {
73 m_state->set("disabled", new rbjson::Bool(disabled));
74 }
75
76 bool disabled() const {
77 return data().getBool("disabled");
78 }
79};
80
81};
void setOptions(const std::string &options)
Definition select.h:45
std::vector< std::string > options() const
Definition select.h:49
std::string background() const
Definition select.h:33
void setBackground(const std::string &background)
Definition select.h:29
int selectedIndex() const
Definition select.h:68
void setOptions(const std::vector< std::string > &options)
Definition select.h:37
void setColor(const std::string &color)
Definition select.h:21
void setSelectedIndex(int index)
Definition select.h:64
void setDisabled(bool disabled)
Definition select.h:72
bool disabled() const
Definition select.h:76
std::string color() const
Definition select.h:25
bool set(const std::string &key, rbjson::Value *value)
Definition widget.cpp:27
WidgetState * m_state
Definition widget.h:265
const rbjson::Object & data() const
Definition widget.h:263
Definition arm.h:8