KolibriLib
Loading...
Searching...
No Matches
form.hpp
1#ifndef __FORM_H__
2#define __FORM_H__
3
4#include <string>
5
6#include "UI.hpp"
7#include "graphic.hpp"
8#include "text.hpp"
9#include "button.hpp"
10#include "input.hpp"
11#include "color.hpp"
12
13namespace KolibriLib
14{
15 namespace UI
16 {
18 class Form : public UIElement
19 {
20 private:
22 buttons::Button _butt;
23
25 std::string _inputText;
26
27 public:
35 Form(const Coord& coord = {0, 0}, const Size& size = {32, 16}, const std::string& BackgroundText = "Text...", const Color::Color& FormColor = OS::sys_color_table.work_text, const Color::Color& ButtonTextColor = OS::sys_color_table.work_area, const unsigned& Margin = DefaultMargin);
36
37 void init(Coord coord = {0, 0}, Size size = {32, 16}, std::string BackgroundText = " ", Color::Color FormColor = OS::sys_color_table.work_text, Color::Color ButtonTextColor = OS::sys_color_table.work_area, unsigned Margin = DefaultMargin);
38
40 void Render();
41
43 void Handler();
44
47 bool ButtonHandler();
48
51 std::string GetInput();
52
55 std::string GetBackgroundText();
56
60
61
62 ~Form();
63 };
64
65 Form::Form(const Coord& coord, const Size& size, const std::string& BackgroundText, const Color::Color& FormColor, const Color::Color& ButtonTextColor, const unsigned& Margin) : UIElement(coord, size, FormColor, Margin)
66 {
67 _ksys_debug_puts("Form:");
68 _butt.init(coord, size, " ", Margin, ButtonTextColor); // Инициализация кнопки
69 }
70
71 void Form::init(Coord coord, Size size, std::string BackgroundText, Color::Color FormColor, Color::Color ButtonTextColor, unsigned Margin)
72 {
73 _coord = coord;
74 _size = size;
75 _MainColor = FormColor;
76 _Margin = Margin;
77 _butt.init(coord, size, "BackgroundText", Margin, ButtonTextColor);
78 }
79
81 {
82 return _butt.GetTextLabel();
83 }
84
86 {
87 return _butt.GetColor();
88 }
89
90 Form::~Form()
91 {
92
93 }
94
96 {
97 graphic::DrawRectangleLines(_coord, {_coord.x + (int)_size.x, _coord.y + (int)_size.y}, _MainColor);
98
99 _butt.Render();
100 }
101
102 std::string Form::GetInput()
103 {
104 return _inputText;
105 }
106
108 {
109 char input = Input::keyboard::CheckKeyboard();
110 if (input > 33 && input != 127) // Если введённый символ не является спецсимволом, и это не Delete
111 {
112 _inputText.push_back(input);
113 }
114 if (input == 127) // input = Delete
115 {
116 _inputText.erase(_inputText.end() - 1);
117 }
118 }
120 {
121 if (_butt.Handler())
122 {
123 return true;
124 }
125 else
126 {
127 return false;
128 }
129 }
130 } // namespace UI
131} // namespace KolibriLib
132
133
134#endif // __FORM_H__
Форма для ввода текста
Definition form.hpp:19
Form(const Coord &coord={0, 0}, const Size &size={32, 16}, const std::string &BackgroundText="Text...", const Color::Color &FormColor=OS::sys_color_table.work_text, const Color::Color &ButtonTextColor=OS::sys_color_table.work_area, const unsigned &Margin=DefaultMargin)
конструктор
Definition form.hpp:65
void Render()
Отрисовать форму
Definition form.hpp:95
bool ButtonHandler()
Обработчик кнопки
Definition form.hpp:119
std::string GetBackgroundText()
Definition form.hpp:80
Color::Color GetBackgroundColor()
Definition form.hpp:85
void Handler()
Обработчик
Definition form.hpp:107
std::string GetInput()
Получить введённый текст
Definition form.hpp:102
Элемент интерфейса
Definition UI.hpp:29
unsigned _Margin
Отступы
Definition UI.hpp:41
Size _size
Размер
Definition UI.hpp:36
Coord _coord
Координаты
Definition UI.hpp:33
Color::Color GetColor()
Получить осносной цвет элемента
Definition UI.hpp:69
Класс для работы с кнопками
Definition button.hpp:127
bool Handler()
Обработчик кнопки
Definition button.hpp:305
void Render()
Отрисовать кнопку
Definition button.hpp:380
void init(const Coord &coord={0, 0}, const Size &size={0, 0}, const std::string &text="button", const unsigned &Margin=UI::DefaultMargin, const Color::Color &ButtonColor=OS::sys_color_table.work_button)
инициализировать параметры
Definition button.hpp:323
std::string GetTextLabel()
Возвращает текст кнопки
Definition button.hpp:279
ksys_color_t Color
Цвет
Definition color.hpp:13
Color::ColorsTable sys_color_table
Таблица стандартных(системных) цветов
Definition os.hpp:15
Основное пространство имён
Definition base.hpp:18
void init()
инициализация
Definition base.hpp:21