mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-05-05 22:40:44 +09:00
Change global widget container to page
This commit is contained in:
@@ -40,7 +40,6 @@ namespace gsr {
|
||||
|
||||
if(mgl::FloatRect(position, item_size).contains(mouse_pos)) {
|
||||
show_dropdown = !show_dropdown;
|
||||
move_to_top = true;
|
||||
} else {
|
||||
show_dropdown = false;
|
||||
}
|
||||
|
||||
22
src/gui/Page.cpp
Normal file
22
src/gui/Page.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#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) {
|
||||
widget->draw(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "../../include/gui/Widget.hpp"
|
||||
#include "../../include/gui/WidgetContainer.hpp"
|
||||
|
||||
namespace gsr {
|
||||
Widget::Widget() {
|
||||
WidgetContainer::get_instance().add_widget(this);
|
||||
|
||||
}
|
||||
|
||||
Widget::~Widget() {
|
||||
WidgetContainer::get_instance().remove_widget(this);
|
||||
|
||||
}
|
||||
|
||||
void Widget::set_position(mgl::vec2f position) {
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#include "../../include/gui/WidgetContainer.hpp"
|
||||
#include "../../include/gui/Widget.hpp"
|
||||
|
||||
namespace gsr {
|
||||
// static
|
||||
WidgetContainer& WidgetContainer::get_instance() {
|
||||
static WidgetContainer instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void WidgetContainer::add_widget(Widget *widget) {
|
||||
// TODO: to_be_added, and remove in the draw loop
|
||||
#ifdef DEBUG
|
||||
for(Widget *existing_widget : widgets) {
|
||||
if(existing_widget == widget)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
widgets.push_back(widget);
|
||||
}
|
||||
|
||||
void WidgetContainer::remove_widget(Widget *widget) {
|
||||
// TODO: to_be_removed, and remove in draw loop
|
||||
for(auto it = widgets.begin(), end = widgets.end(); it != end; ++it) {
|
||||
if(*it == widget) {
|
||||
widgets.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetContainer::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 WidgetContainer::draw(mgl::Window &window) {
|
||||
for(auto it = widgets.begin(); it != widgets.end(); ++it) {
|
||||
Widget *widget = *it;
|
||||
if(widget->move_to_top) {
|
||||
widget->move_to_top = false;
|
||||
std::swap(*it, widgets.back());
|
||||
/*if(widgets.back() != widget) {
|
||||
widgets.erase(it);
|
||||
widgets.push_back(widget);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
for(Widget *widget : widgets) {
|
||||
widget->draw(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user