aboutsummaryrefslogtreecommitdiff
path: root/src/gui/Page.cpp
blob: 813c2bde6cc75529245f7eb6d88d412f75920019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "../../include/gui/Page.hpp"
#include "../../include/gui/Widget.hpp"

namespace gsr {
    void Page::add_widget(std::unique_ptr<Widget> widget) {
        widgets.push_back(std::move(widget));
    }

    void Page::on_event(mgl::Event &event, mgl::Window &window) {
        // Process widgets by visibility (backwards)
        for(auto it = widgets.rbegin(), end = widgets.rend(); it != end; ++it) {
            if(!(*it)->on_event(event, window))
                return;
        }
    }

    void Page::draw(mgl::Window &window) {
        for(auto &widget : widgets) {
            if(widget->move_to_top) {
                widget->move_to_top = false;
                std::swap(widget, widgets.back());
            }
            widget->draw(window);
        }

        for(auto &widget : widgets) {
            widget->draw(window);
        }
    }
}