Merge branch 'main' into text3d

This commit is contained in:
MihailRis
2024-11-13 01:14:19 +03:00
12 changed files with 84 additions and 21 deletions
+13 -4
View File
@@ -127,7 +127,7 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
void TextBox::refreshLabel() {
label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f));
label->setText(getText());
label->setText(input.empty() && !hint.empty() ? hint : getText());
if (autoresize && font) {
auto size = getSize();
@@ -505,7 +505,7 @@ void TextBox::performEditingKeyboardEvents(keycode key) {
} else {
defocus();
if (validate() && consumer) {
consumer(label->getText());
consumer(getText());
}
}
} else if (key == keycode::TAB) {
@@ -627,7 +627,7 @@ glm::vec4 TextBox::getErrorColor() const {
return invalidColor;
}
std::wstring TextBox::getText() const {
const std::wstring& TextBox::getText() const {
if (input.empty())
return placeholder;
return input;
@@ -638,7 +638,7 @@ void TextBox::setText(const std::wstring& value) {
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
}
std::wstring TextBox::getPlaceholder() const {
const std::wstring& TextBox::getPlaceholder() const {
return placeholder;
}
@@ -646,6 +646,15 @@ void TextBox::setPlaceholder(const std::wstring& placeholder) {
this->placeholder = placeholder;
}
const std::wstring& TextBox::getHint() const {
return hint;
}
void TextBox::setHint(const std::wstring& text) {
this->hint = text;
}
std::wstring TextBox::getSelection() const {
return input.substr(selectionStart, selectionEnd-selectionStart);
}
+24 -5
View File
@@ -13,23 +13,35 @@ namespace gui {
glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f};
glm::vec4 invalidColor {0.1f, 0.05f, 0.03f, 1.0f};
std::shared_ptr<Label> label;
/// @brief Current user input
std::wstring input;
/// @brief Text will be used if nothing entered
std::wstring placeholder;
/// @brief Text will be shown when nothing entered
std::wstring hint;
/// @brief Text supplier called every frame when not focused
wstringsupplier supplier = nullptr;
/// @brief Text supplier called on Enter pressed
wstringconsumer consumer = nullptr;
/// @brief Text supplier called while input
wstringconsumer subconsumer = nullptr;
/// @brief Text validator returning boolean value
wstringchecker validator = nullptr;
/// @brief Function called on focus
runnable onEditStart = nullptr;
/// @brief Function called on up arrow pressed
runnable onUpPressed;
/// @brief Function called on down arrow pressed
runnable onDownPressed;
/// @brief Is current input valid
bool valid = true;
/// @brief text input pointer, value may be greather than text length
/// @brief Text input pointer, value may be greather than text length
size_t caret = 0;
/// @brief actual local (line) position of the caret on vertical move
/// @brief Actual local (line) position of the caret on vertical move
size_t maxLocalCaret = 0;
size_t textOffset = 0;
int textInitX;
/// @brief last time of the caret was moved (used for blink animation)
/// @brief Last time of the caret was moved (used for blink animation)
double caretLastMove = 0.0;
Font* font = nullptr;
@@ -101,17 +113,24 @@ namespace gui {
virtual glm::vec4 getErrorColor() const;
/// @brief Get TextBox content text or placeholder if empty
virtual std::wstring getText() const;
virtual const std::wstring& getText() const;
/// @brief Set TextBox content text
virtual void setText(const std::wstring &value);
/// @brief Get text placeholder
virtual std::wstring getPlaceholder() const;
virtual const std::wstring& getPlaceholder() const;
/// @brief Set text placeholder
/// @param text will be used instead of empty
virtual void setPlaceholder(const std::wstring& text);
/// @brief Get textbox hint
virtual const std::wstring& getHint() const;
/// @brief Set textbox hint
/// @param text will be shown instead of empty
virtual void setHint(const std::wstring& text);
/// @brief Get selected text
virtual std::wstring getSelection() const;