add 'onfocus' ui event & optimize container:add
This commit is contained in:
@@ -71,6 +71,10 @@ void Container::mouseRelease(int x, int y) {
|
||||
}
|
||||
|
||||
void Container::act(float delta) {
|
||||
if (mustRefresh) {
|
||||
refresh();
|
||||
mustRefresh = false;
|
||||
}
|
||||
for (const auto& node : nodes) {
|
||||
if (node->isVisible()) {
|
||||
node->act(delta);
|
||||
@@ -162,7 +166,7 @@ void Container::add(const std::shared_ptr<UINode>& node) {
|
||||
nodes.push_back(node);
|
||||
node->setParent(this);
|
||||
node->reposition();
|
||||
refresh();
|
||||
mustRefresh = true;
|
||||
}
|
||||
|
||||
void Container::add(const std::shared_ptr<UINode>& node, glm::vec2 pos) {
|
||||
@@ -202,7 +206,6 @@ void Container::listenInterval(float interval, ontimeout callback, int repeat) {
|
||||
|
||||
void Container::setSize(glm::vec2 size) {
|
||||
if (size == getSize()) {
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
UINode::setSize(size);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
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;
|
||||
|
||||
@@ -74,6 +74,11 @@ UINode* UINode::listenDoubleClick(const onaction& action) {
|
||||
return this;
|
||||
}
|
||||
|
||||
UINode* UINode::listenFocus(const onaction& action) {
|
||||
focusCallbacks.listen(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
UINode* UINode::listenDefocus(const onaction& action) {
|
||||
defocusCallbacks.listen(action);
|
||||
return this;
|
||||
@@ -101,6 +106,11 @@ bool UINode::isPressed() const {
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void UINode::onFocus() {
|
||||
focused = true;
|
||||
focusCallbacks.notify(gui);
|
||||
}
|
||||
|
||||
void UINode::defocus() {
|
||||
focused = false;
|
||||
defocusCallbacks.notify(gui);
|
||||
|
||||
@@ -114,6 +114,8 @@ namespace gui {
|
||||
ActionsSet actions;
|
||||
/// @brief 'ondoubleclick' callbacks
|
||||
ActionsSet doubleClickCallbacks;
|
||||
/// @brief 'onfocus' callbacks
|
||||
ActionsSet focusCallbacks;
|
||||
/// @brief 'ondefocus' callbacks
|
||||
ActionsSet defocusCallbacks;
|
||||
/// @brief element tooltip text
|
||||
@@ -173,9 +175,10 @@ namespace gui {
|
||||
|
||||
virtual UINode* listenAction(const onaction& action);
|
||||
virtual UINode* listenDoubleClick(const onaction& action);
|
||||
virtual UINode* listenFocus(const onaction& action);
|
||||
virtual UINode* listenDefocus(const onaction& action);
|
||||
|
||||
virtual void onFocus() {focused = true;}
|
||||
virtual void onFocus();
|
||||
virtual void doubleClick(int x, int y);
|
||||
virtual void click(int x, int y);
|
||||
virtual void clicked(Mousecode button) {}
|
||||
|
||||
Reference in New Issue
Block a user