mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
UI message parser
move message parser threads to UI set functions
This commit is contained in:
@@ -27,6 +27,6 @@ void UI_button::click() const
|
||||
{
|
||||
if (m_on_click != nullptr)
|
||||
{
|
||||
m_on_click(m_id);
|
||||
std::thread([this] { m_on_click(m_id); }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ void UI_checkbox::toggle_selected(size_t selected)
|
||||
m_selected[selected] = !m_selected[selected];
|
||||
if (m_on_change != nullptr)
|
||||
{
|
||||
m_on_change(m_id, selected_text());
|
||||
std::thread([this] { m_on_change(m_id, selected_text()); }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ void UI_combobox::set_selected(size_t selected)
|
||||
m_selected = selected;
|
||||
if (m_on_change != nullptr)
|
||||
{
|
||||
m_on_change(m_id, selected_text());
|
||||
std::thread([this] { m_on_change(m_id, selected_text()); }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <cstdint>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
@@ -18,7 +19,7 @@ class UI_item {
|
||||
std::string type() const;
|
||||
bool is_type(json j);
|
||||
|
||||
void set_text(std::string text);
|
||||
virtual void set_text(std::string text);
|
||||
std::string text() const;
|
||||
|
||||
void set_text_size(uint8_t text_size);
|
||||
|
||||
@@ -19,10 +19,10 @@ void UI_slider::set_value(double value)
|
||||
if (value == m_value)
|
||||
return;
|
||||
|
||||
this->m_value = value;
|
||||
if (m_on_change != nullptr)
|
||||
{
|
||||
this->m_value = value;
|
||||
m_on_change(m_id, value);
|
||||
std::thread([this] { m_on_change(m_id, m_value); }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-2
@@ -1,7 +1,7 @@
|
||||
#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(std::string id, std::string hint, Color fg_color, Color bg_color, std::function<void(std::string, std::string)> on_change)
|
||||
: UI_item(id, UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color), m_hint(hint), m_on_change(on_change)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,6 +11,17 @@ UI_textbox::UI_textbox(const json& j)
|
||||
from_json(j);
|
||||
}
|
||||
|
||||
void UI_textbox::set_text(std::string text)
|
||||
{
|
||||
if (text == m_text)
|
||||
return;
|
||||
m_text = text;
|
||||
if (m_on_change != nullptr)
|
||||
{
|
||||
std::thread([this] { m_on_change(m_id, m_text); }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
void UI_textbox::set_hint(std::string hint)
|
||||
{
|
||||
m_hint = hint;
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
class UI_textbox : public UI_item
|
||||
{
|
||||
public:
|
||||
UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color);
|
||||
UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, std::function<void(std::string, std::string)> on_change);
|
||||
UI_textbox(const json& j);
|
||||
|
||||
void set_text(std::string text) override;
|
||||
|
||||
void set_hint(std::string hint);
|
||||
std::string hint() const;
|
||||
|
||||
@@ -17,4 +19,5 @@ public:
|
||||
json to_json() const override;
|
||||
private:
|
||||
std::string m_hint;
|
||||
std::function<void(std::string, std::string)> m_on_change;
|
||||
};
|
||||
Reference in New Issue
Block a user