From a340889f624dce56e5ff08501390f3d20c976ea8 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Sat, 24 Aug 2024 00:06:56 +0200 Subject: [PATCH] UI Add textbox --- src/UI/CMakeLists.txt | 1 + src/UI/UI_textbox.cpp | 35 +++++++++++++++++++++++++++++++++++ src/UI/UI_textbox.hpp | 20 ++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/UI/UI_textbox.cpp create mode 100644 src/UI/UI_textbox.hpp diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index cca4097..0d5f243 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -16,6 +16,7 @@ target_sources(UI ${CMAKE_CURRENT_LIST_DIR}/UI_led.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_button.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_slider.cpp + ${CMAKE_CURRENT_LIST_DIR}/UI_textbox.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_x_boxes.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_combobox.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.cpp diff --git a/src/UI/UI_textbox.cpp b/src/UI/UI_textbox.cpp new file mode 100644 index 0000000..121ad14 --- /dev/null +++ b/src/UI/UI_textbox.cpp @@ -0,0 +1,35 @@ +#include "UI_textbox.hpp" + +UI_textbox::UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color) + : UI_item(id, UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color), m_hint(hint) +{ +} + +UI_textbox::UI_textbox(const json& j) + : UI_item(UI_TEXTBOX_TYPE) +{ + from_json(j); +} + +void UI_textbox::set_hint(std::string hint) +{ + m_hint = hint; +} + +std::string UI_textbox::hint() const +{ + return m_hint; +} + +void UI_textbox::from_json(const json& j) +{ + UI_item::from_json(j); + m_hint = j["hint"]; +} + +json UI_textbox::to_json() const +{ + json j = UI_item::to_json(); + j["hint"] = m_hint; + return j; +} \ No newline at end of file diff --git a/src/UI/UI_textbox.hpp b/src/UI/UI_textbox.hpp new file mode 100644 index 0000000..a31b274 --- /dev/null +++ b/src/UI/UI_textbox.hpp @@ -0,0 +1,20 @@ +#pragma once +#include +#include "UI_item.hpp" + +#define UI_TEXTBOX_TYPE std::string("UItextbox") + +class UI_textbox : public UI_item +{ +public: + UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color); + UI_textbox(const json& j); + + void set_hint(std::string hint); + std::string hint() const; + + void from_json(const json& j) override; + json to_json() const override; +private: + std::string m_hint; +}; \ No newline at end of file