diff --git a/doc/en/xml-ui-layouts.md b/doc/en/xml-ui-layouts.md index d6bab384f..8856338ad 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 cbcbbf7c4..00db07547 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 ccb427e73..4ebe8c7a0 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 302b89fed..972b118ff 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()); }