From 2cf51a694107ab4837d69aa4dd5e5b717e4a0c4d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 19 Nov 2024 04:21:05 +0300 Subject: [PATCH] add 'line-numbers' property to textbox & make TextBox extend Container instead of Panel --- doc/en/xml-ui-layouts.md | 1 + doc/ru/xml-ui-layouts.md | 1 + src/graphics/ui/elements/TextBox.cpp | 119 +++++++++++++++++++----- src/graphics/ui/elements/TextBox.hpp | 11 ++- src/graphics/ui/gui_xml.cpp | 14 ++- src/logic/scripting/lua/libs/libgui.cpp | 14 +++ 6 files changed, 135 insertions(+), 25 deletions(-) diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index f4db96c6..b039a29b 100644 --- a/doc/en/xml-ui-layouts.md +++ b/doc/en/xml-ui-layouts.md @@ -104,6 +104,7 @@ Inner text - initially entered text - `multiline` - allows display of multiline text. - `text-wrap` - allows automatic text wrapping (works only with multiline: "true") - `editable` - determines whether the text can be edited. +- `line-numbers` - enables line numbers display. - `error-color` - color when entering incorrect data (the text does not pass the validator check). Type: RGBA color. - `text-color` - text color. Type: RGBA color. - `validator` - lua function that checks text for correctness. Takes a string as input, returns true if the text is correct. diff --git a/doc/ru/xml-ui-layouts.md b/doc/ru/xml-ui-layouts.md index adffcd73..dc9455f7 100644 --- a/doc/ru/xml-ui-layouts.md +++ b/doc/ru/xml-ui-layouts.md @@ -105,6 +105,7 @@ - `multiline` - разрешает отображение многострочного текста. - `text-wrap` - разрешает автоматический перенос текста (работает только при multiline: "true") - `editable`- определяет возможность редактирования текста. +- `line-numbers` - включает отображение номеров строк. - `error-color` - цвет при вводе некорректных данных (текст не проходит проверку валидатора). Тип: RGBA цвет. - `text-color` - цвет текста. Тип: RGBA цвет. - `validator` - lua функция, проверяющая текст на корректность. Принимает на вход строку, возвращает true если текст корректен. diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index a4e613d3..6a123fca 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -1,5 +1,6 @@ #include "TextBox.hpp" +#include #include #include @@ -14,16 +15,30 @@ using namespace gui; +inline constexpr int LINE_NUMBERS_PANE_WIDTH = 40; + TextBox::TextBox(std::wstring placeholder, glm::vec4 padding) - : Panel(glm::vec2(200,32), padding, 0), + : Container(glm::vec2(200,32)), + padding(padding), input(L""), placeholder(std::move(placeholder)) { setOnUpPressed(nullptr); setOnDownPressed(nullptr); + setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.75f)); label = std::make_shared