diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index 0bd1b5353..643f2adcb 100644 --- a/doc/en/xml-ui-layouts.md +++ b/doc/en/xml-ui-layouts.md @@ -192,6 +192,9 @@ Example of list description: - `width` - minimum content width. Default: 100. - `selected` - initially selected value. Default: "". - `onselect` - function to which the user-selected value is passed +- `mode` - behaviour / display mode: + - `select` - default mode. + - `button` - button mode: the text is not replaced with the selected option; the element rendered as a regular button. ## *bindbox* diff --git a/doc/ru/xml-ui-layouts.md b/doc/ru/xml-ui-layouts.md index 2ca6da1ce..3b40f6c9c 100644 --- a/doc/ru/xml-ui-layouts.md +++ b/doc/ru/xml-ui-layouts.md @@ -193,6 +193,9 @@ - `width` - минимальная ширина содержимого. По-умолчанию: 100. - `selected` - изначально выбранное значение. По-умолчанию: "". - `onselect` - функция, в которую передаётся выбранное пользователем значение +- `mode` - режим работы: + - `select` - режим по-умолчанию. + - `button` - режим кнопки: текст не заменяется на выбранную опцию, а элемент выглядит как обычная кнопка. ## Привязка ввода - *bindbox* diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 6169a2578..8bfe3a341 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -260,7 +260,7 @@ void GUI::act(float delta, const glm::uvec2& vp) { hover = nullptr; } } - if (focus) { + if (focus && focusedOnStart == focus.get()) { actFocused(); } if (focus && !focus->isFocused()) { @@ -274,6 +274,7 @@ void GUI::postAct() { postRunnables.pop(); callback(); } + focusedOnStart = focus.get(); } void GUI::draw(const DrawContext& pctx, Assets& assets) { diff --git a/src/graphics/ui/GUI.hpp b/src/graphics/ui/GUI.hpp index 7d120c9cc..97fc0ed37 100644 --- a/src/graphics/ui/GUI.hpp +++ b/src/graphics/ui/GUI.hpp @@ -72,6 +72,7 @@ namespace gui { std::shared_ptr hover; std::shared_ptr pressed; std::shared_ptr focus; + const UINode* focusedOnStart = nullptr; std::shared_ptr tooltip; std::shared_ptr rootDocument; std::unique_ptr syntaxColorScheme; diff --git a/src/graphics/ui/elements/SelectBox.cpp b/src/graphics/ui/elements/SelectBox.cpp index b8205d806..0a6940943 100644 --- a/src/graphics/ui/elements/SelectBox.cpp +++ b/src/graphics/ui/elements/SelectBox.cpp @@ -13,14 +13,21 @@ SelectBox::SelectBox( GUI& gui, std::vector