SensESP 3.5.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
ui_button.h
Go to the documentation of this file.
1#ifndef SENSESP_UI_UI_BUTTON_H
2#define SENSESP_UI_UI_BUTTON_H
3
4#include <map>
5#include <memory>
6
7#include "Arduino.h"
9
10namespace sensesp {
11
18class UIButton : public Observable {
19 public:
21 static constexpr size_t kMaxNameLength = 64;
22
23 UIButton(String title, String name, bool must_confirm)
24 : title_(title), name_(name), must_confirm_(must_confirm) {}
25
26 const bool get_must_confirm() { return must_confirm_; }
27 const String get_title() { return title_; }
28 const String get_name() { return name_; }
29
30 static const std::map<String, std::shared_ptr<UIButton>>& get_ui_buttons() {
31 return ui_buttons_;
32 }
33
45 static UIButton* add(String name, String title, bool must_confirm = true) {
46 if (ui_buttons_.count(name) != 0) {
47 ESP_LOGW("UIButton",
48 "Duplicate button name '%s' replaces the earlier button",
49 name.c_str());
50 }
51 if (name.length() > kMaxNameLength) {
52 ESP_LOGW("UIButton",
53 "Button name '%s' exceeds %u characters and is hidden "
54 "from the web UI",
55 name.c_str(), static_cast<unsigned>(kMaxNameLength));
56 }
57 auto new_cmd = std::make_shared<UIButton>(title, name, must_confirm);
58 ui_buttons_[name] = new_cmd;
59
60 return new_cmd.get();
61 }
62
73 static void clear_registry();
74
75 protected:
76 String title_;
77 String name_;
79
80 static std::map<String, std::shared_ptr<UIButton>> ui_buttons_;
81};
82
83} // namespace sensesp
84
85#endif
A base class which allow observers to attach callbacks to themselves. The callbacks will be called wh...
Definition observable.h:16
UIButton implements a button interface on the web UI.
Definition ui_button.h:18
static const std::map< String, std::shared_ptr< UIButton > > & get_ui_buttons()
Definition ui_button.h:30
UIButton(String title, String name, bool must_confirm)
Definition ui_button.h:23
static constexpr size_t kMaxNameLength
Longest button name the web UI click endpoint resolves.
Definition ui_button.h:21
const bool get_must_confirm()
Definition ui_button.h:26
const String get_name()
Definition ui_button.h:28
const String get_title()
Definition ui_button.h:27
static UIButton * add(String name, String title, bool must_confirm=true)
Create a button and register it for the web UI.
Definition ui_button.h:45
static std::map< String, std::shared_ptr< UIButton > > ui_buttons_
Definition ui_button.h:80
static void clear_registry()
Empty the button registry.
Definition ui_button.cpp:7