From 209490192c0e996420f1e03907173642628345c0 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 18 Jan 2025 06:37:27 +0300 Subject: [PATCH] add 'min-size' ui property --- doc/en/xml-ui-layouts.md | 1 + doc/ru/xml-ui-layouts.md | 1 + src/graphics/ui/elements/UINode.cpp | 6 +++++- src/graphics/ui/gui_xml.cpp | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index d6bab384..8856338a 100644 --- a/doc/en/xml-ui-layouts.md +++ b/doc/en/xml-ui-layouts.md @@ -35,6 +35,7 @@ Examples: - `margin` - element margin. Type: 4D vector *left, top, right, bottom* - `visible` - element visibility. Type: boolean (true/false) +- `min-size` - minimal element size. Type: 2D vector. - `position-func` - position supplier for an element (two numbers), called on every parent container size update or on element adding on a container. May be called before *on_hud_open* - `size-func` - element size provider (two numbers), called when the size of the container in which the element is located changes, or when an element is added to the container. Can be called before on_hud_open is called. - `onclick` - lua function called when an element is clicked. diff --git a/doc/ru/xml-ui-layouts.md b/doc/ru/xml-ui-layouts.md index cbcbbf7c..00db0754 100644 --- a/doc/ru/xml-ui-layouts.md +++ b/doc/ru/xml-ui-layouts.md @@ -39,6 +39,7 @@ - `margin` - внешний отступ элемента. Тип: 4D вектор. Порядок: `"left,top,right,bottom"` - `visible` - видимость элемента. Тип: логический ("true"/"false"). +- `min-size` - минимальный размер элемента. Тип: 2D вектор. - `position-func` - поставщик позиции элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open. - `size-func` - поставщик размера элемента (два числа), вызываемый при изменении размера контейнера, в котором находится элемент, либо при добавлении элемента в контейнер. Может быть вызван до вызова on_hud_open. - `onclick` - lua функция вызываемая при нажатии на элемент. diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index ccb427e7..4ebe8c7a 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -290,7 +290,11 @@ const std::string& UINode::getId() const { void UINode::reposition() { if (sizefunc) { - setSize(sizefunc()); + auto newSize = sizefunc(); + setSize( + {newSize.x < 0 ? size.x : newSize.x, + newSize.y < 0 ? size.y : newSize.y} + ); } if (positionfunc) { setPos(positionfunc()); diff --git a/src/graphics/ui/gui_xml.cpp b/src/graphics/ui/gui_xml.cpp index 302b89fe..972b118f 100644 --- a/src/graphics/ui/gui_xml.cpp +++ b/src/graphics/ui/gui_xml.cpp @@ -91,6 +91,9 @@ static void _readUINode( if (element.has("pos")) { node.setPos(element.attr("pos").asVec2()); } + if (element.has("min-size")) { + node.setMinSize(element.attr("min-size").asVec2()); + } if (element.has("size")) { node.setSize(element.attr("size").asVec2()); }