Add textbox
This commit is contained in:
2024-08-24 00:06:56 +02:00
parent 43793e1065
commit a340889f62
3 changed files with 56 additions and 0 deletions
+1
View File
@@ -16,6 +16,7 @@ target_sources(UI
${CMAKE_CURRENT_LIST_DIR}/UI_led.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_led.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_button.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_button.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_slider.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_x_boxes.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_combobox.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_combobox.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.cpp ${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.cpp
+35
View File
@@ -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;
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include <string>
#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;
};