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