fix containers refreshing
This commit is contained in:
parent
d845aeb55f
commit
34295faca2
@ -229,7 +229,7 @@ function gui.template(name, params)
|
||||
text = text:gsub("%%{([^}]+)}", function(n)
|
||||
local s = params[n]
|
||||
if type(s) ~= "string" then
|
||||
return s
|
||||
return tostring(s)
|
||||
end
|
||||
if #s == 0 then
|
||||
return
|
||||
|
||||
@ -71,10 +71,7 @@ void Container::mouseRelease(int x, int y) {
|
||||
}
|
||||
|
||||
void Container::act(float delta) {
|
||||
if (mustRefresh) {
|
||||
refresh();
|
||||
mustRefresh = false;
|
||||
}
|
||||
UINode::act(delta);
|
||||
for (const auto& node : nodes) {
|
||||
if (node->isVisible()) {
|
||||
node->act(delta);
|
||||
@ -167,6 +164,12 @@ void Container::add(const std::shared_ptr<UINode>& node) {
|
||||
node->setParent(this);
|
||||
node->reposition();
|
||||
mustRefresh = true;
|
||||
|
||||
auto parent = getParent();
|
||||
while (parent) {
|
||||
parent->setMustRefresh();
|
||||
parent = parent->getParent();
|
||||
}
|
||||
}
|
||||
|
||||
void Container::add(const std::shared_ptr<UINode>& node, glm::vec2 pos) {
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
namespace gui {
|
||||
class Container : public UINode, public ::util::ObjectsKeeper {
|
||||
int prevScrollY = -1;
|
||||
bool mustRefresh = true;
|
||||
protected:
|
||||
std::vector<std::shared_ptr<UINode>> nodes;
|
||||
std::vector<IntervalEvent> intervalEvents;
|
||||
|
||||
@ -66,6 +66,7 @@ namespace gui {
|
||||
class UINode : public std::enable_shared_from_this<UINode> {
|
||||
protected:
|
||||
GUI& gui;
|
||||
bool mustRefresh = true;
|
||||
private:
|
||||
/// @brief element identifier used for direct access in UiDocument
|
||||
std::string id = "";
|
||||
@ -131,7 +132,12 @@ namespace gui {
|
||||
|
||||
/// @brief Called every frame for all visible elements
|
||||
/// @param delta delta timУ
|
||||
virtual void act(float delta) {};
|
||||
virtual void act(float delta) {
|
||||
if (mustRefresh) {
|
||||
mustRefresh = false;
|
||||
refresh();
|
||||
}
|
||||
};
|
||||
virtual void draw(const DrawContext& pctx, const Assets& assets) = 0;
|
||||
|
||||
virtual void setVisible(bool flag);
|
||||
@ -275,5 +281,9 @@ namespace gui {
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::string& id
|
||||
);
|
||||
|
||||
void setMustRefresh() {
|
||||
mustRefresh = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user