mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Use stack for page navigation, dont add spacing between list elements if the widget is empty or not visible
This commit is contained in:
4
TODO
4
TODO
@@ -8,7 +8,7 @@ Maybe change design to have black triangles appear and get larger until they fil
|
|||||||
Have buttons appear slanted in 3D.
|
Have buttons appear slanted in 3D.
|
||||||
All of these things should be done with vertex buffer, for real 3D.
|
All of these things should be done with vertex buffer, for real 3D.
|
||||||
|
|
||||||
DISPLAY gamescope-0
|
WAYLAND_DISPLAY gamescope-0, DISPLAY=:1 (gamescope xwayland)
|
||||||
|
|
||||||
Optimize list/page when having a few items in it (dont use vector<unique_ptr<Widget>>).
|
Optimize list/page when having a few items in it (dont use vector<unique_ptr<Widget>>).
|
||||||
|
|
||||||
@@ -16,4 +16,4 @@ Only redraw ui if changed (dirty state, propagate upward. Set dirty when adding
|
|||||||
|
|
||||||
Use _NET_WM_ALLOWED_ACTIONS. Same for notifications.
|
Use _NET_WM_ALLOWED_ACTIONS. Same for notifications.
|
||||||
|
|
||||||
Handle events in draw function because the render position of elements is available there so why duplicate it in event handler.
|
Handle events in draw function because the render position of elements is available there so why duplicate it in event handler.
|
||||||
|
|||||||
@@ -76,20 +76,23 @@ namespace gsr {
|
|||||||
if(!widget->visible)
|
if(!widget->visible)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
const auto widget_size = widget->get_size();
|
||||||
// TODO: Do this parent widget alignment for horizontal alignment and for other types of widget alignment
|
// TODO: Do this parent widget alignment for horizontal alignment and for other types of widget alignment
|
||||||
// and other widgets.
|
// and other widgets.
|
||||||
// Also take this widget alignment into consideration in get_size.
|
// Also take this widget alignment into consideration in get_size.
|
||||||
if(widget->get_horizontal_alignment() == Widget::Alignment::CENTER && parent_size.x > 0.001f)
|
if(widget->get_horizontal_alignment() == Widget::Alignment::CENTER && parent_size.x > 0.001f)
|
||||||
offset.x = floor(parent_size.x * 0.5f - widget->get_size().x * 0.5f);
|
offset.x = floor(parent_size.x * 0.5f - widget_size.x * 0.5f);
|
||||||
else if(content_alignment == Alignment::CENTER)
|
else if(content_alignment == Alignment::CENTER)
|
||||||
offset.x = floor(size.x * 0.5f - widget->get_size().x * 0.5f);
|
offset.x = floor(size.x * 0.5f - widget_size.x * 0.5f);
|
||||||
else
|
else
|
||||||
offset.x = 0.0f;
|
offset.x = 0.0f;
|
||||||
|
|
||||||
widget->set_position(draw_pos + offset);
|
widget->set_position(draw_pos + offset);
|
||||||
if(widget.get() != selected_widget)
|
if(widget.get() != selected_widget)
|
||||||
widget->draw(window, mgl::vec2f(0.0f, 0.0f));
|
widget->draw(window, mgl::vec2f(0.0f, 0.0f));
|
||||||
draw_pos.y += widget->get_size().y + spacing.y;
|
draw_pos.y += widget_size.y;
|
||||||
|
if(widget_size.y > 0.001f)
|
||||||
|
draw_pos.y += spacing.y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -98,13 +101,16 @@ namespace gsr {
|
|||||||
if(!widget->visible)
|
if(!widget->visible)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
const auto widget_size = widget->get_size();
|
||||||
if(content_alignment == Alignment::CENTER)
|
if(content_alignment == Alignment::CENTER)
|
||||||
offset.y = floor(size.y * 0.5f - widget->get_size().y * 0.5f);
|
offset.y = floor(size.y * 0.5f - widget_size.y * 0.5f);
|
||||||
|
|
||||||
widget->set_position(draw_pos + offset);
|
widget->set_position(draw_pos + offset);
|
||||||
if(widget.get() != selected_widget)
|
if(widget.get() != selected_widget)
|
||||||
widget->draw(window, mgl::vec2f(0.0f, 0.0f));
|
widget->draw(window, mgl::vec2f(0.0f, 0.0f));
|
||||||
draw_pos.x += widget->get_size().x + spacing.x;
|
draw_pos.x += widget_size.x;
|
||||||
|
if(widget_size.x > 0.001f)
|
||||||
|
draw_pos.x += spacing.x;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -156,7 +162,9 @@ namespace gsr {
|
|||||||
|
|
||||||
const auto widget_size = widget->get_size();
|
const auto widget_size = widget->get_size();
|
||||||
size.x = std::max(size.x, widget_size.x);
|
size.x = std::max(size.x, widget_size.x);
|
||||||
size.y += widget_size.y + spacing.y;
|
size.y += widget_size.y;
|
||||||
|
if(widget_size.y > 0.001f)
|
||||||
|
size.y += spacing.y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -166,7 +174,9 @@ namespace gsr {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
const auto widget_size = widget->get_size();
|
const auto widget_size = widget->get_size();
|
||||||
size.x += widget_size.x + spacing.x;
|
size.x += widget_size.x;
|
||||||
|
if(widget_size.x > 0.001f)
|
||||||
|
size.x += spacing.x;
|
||||||
size.y = std::max(size.y, widget_size.y);
|
size.y = std::max(size.y, widget_size.y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ namespace gsr {
|
|||||||
|
|
||||||
update_if_dirty();
|
update_if_dirty();
|
||||||
|
|
||||||
|
if(items.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
const int padding_top = padding_top_scale * get_theme().window_height;
|
const int padding_top = padding_top_scale * get_theme().window_height;
|
||||||
const int padding_bottom = padding_bottom_scale * get_theme().window_height;
|
const int padding_bottom = padding_bottom_scale * get_theme().window_height;
|
||||||
const int padding_left = padding_left_scale * get_theme().window_height;
|
const int padding_left = padding_left_scale * get_theme().window_height;
|
||||||
@@ -106,7 +109,7 @@ namespace gsr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mgl::vec2f RadioButton::get_size() {
|
mgl::vec2f RadioButton::get_size() {
|
||||||
if(!visible)
|
if(!visible || items.empty())
|
||||||
return {0.0f, 0.0f};
|
return {0.0f, 0.0f};
|
||||||
|
|
||||||
update_if_dirty();
|
update_if_dirty();
|
||||||
|
|||||||
42
src/main.cpp
42
src/main.cpp
@@ -24,6 +24,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/cursorfont.h>
|
#include <X11/cursorfont.h>
|
||||||
@@ -565,7 +566,8 @@ int main(int argc, char **argv) {
|
|||||||
gsr::StaticPage stream_settings_page(window_size.to_vec2f());
|
gsr::StaticPage stream_settings_page(window_size.to_vec2f());
|
||||||
stream_settings_page.add_widget(std::move(stream_settings_content));
|
stream_settings_page.add_widget(std::move(stream_settings_content));
|
||||||
|
|
||||||
gsr::Page *current_page = &front_page;
|
std::stack<gsr::Page*> page_stack;
|
||||||
|
page_stack.push(&front_page);
|
||||||
|
|
||||||
struct MainButton {
|
struct MainButton {
|
||||||
gsr::DropdownButton* button;
|
gsr::DropdownButton* button;
|
||||||
@@ -652,7 +654,7 @@ int main(int argc, char **argv) {
|
|||||||
// Replay
|
// Replay
|
||||||
main_buttons[0].button->on_click = [&](const std::string &id) {
|
main_buttons[0].button->on_click = [&](const std::string &id) {
|
||||||
if(id == "settings") {
|
if(id == "settings") {
|
||||||
current_page = &replay_settings_page;
|
page_stack.push(&replay_settings_page);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@@ -677,7 +679,7 @@ int main(int argc, char **argv) {
|
|||||||
// Record
|
// Record
|
||||||
main_buttons[1].button->on_click = [&](const std::string &id) {
|
main_buttons[1].button->on_click = [&](const std::string &id) {
|
||||||
if(id == "settings") {
|
if(id == "settings") {
|
||||||
current_page = &record_settings_page;
|
page_stack.push(&record_settings_page);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,7 +764,7 @@ int main(int argc, char **argv) {
|
|||||||
// Stream
|
// Stream
|
||||||
main_buttons[2].button->on_click = [&](const std::string &id) {
|
main_buttons[2].button->on_click = [&](const std::string &id) {
|
||||||
if(id == "settings") {
|
if(id == "settings") {
|
||||||
current_page = &stream_settings_page;
|
page_stack.push(&stream_settings_page);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -813,7 +815,7 @@ int main(int argc, char **argv) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto settings_back_button_callback = [&] {
|
const auto settings_back_button_callback = [&] {
|
||||||
current_page = &front_page;
|
page_stack.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
for(int i = 0; i < num_settings_pages; ++i) {
|
for(int i = 0; i < num_settings_pages; ++i) {
|
||||||
@@ -850,7 +852,7 @@ int main(int argc, char **argv) {
|
|||||||
event.type = mgl::Event::MouseMoved;
|
event.type = mgl::Event::MouseMoved;
|
||||||
event.mouse_move.x = window.get_mouse_position().x;
|
event.mouse_move.x = window.get_mouse_position().x;
|
||||||
event.mouse_move.y = window.get_mouse_position().y;
|
event.mouse_move.y = window.get_mouse_position().y;
|
||||||
current_page->on_event(event, window, mgl::vec2f(0.0f, 0.0f));
|
page_stack.top()->on_event(event, window, mgl::vec2f(0.0f, 0.0f));
|
||||||
|
|
||||||
const auto render = [&] {
|
const auto render = [&] {
|
||||||
window.clear(bg_color);
|
window.clear(bg_color);
|
||||||
@@ -862,26 +864,25 @@ int main(int argc, char **argv) {
|
|||||||
window.draw(top_bar_text);
|
window.draw(top_bar_text);
|
||||||
window.draw(logo_sprite);
|
window.draw(logo_sprite);
|
||||||
window.draw(close_sprite);
|
window.draw(close_sprite);
|
||||||
current_page->draw(window, mgl::vec2f(0.0f, 0.0f));
|
page_stack.top()->draw(window, mgl::vec2f(0.0f, 0.0f));
|
||||||
window.display();
|
window.display();
|
||||||
};
|
};
|
||||||
|
|
||||||
while(window.is_open()) {
|
while(window.is_open()) {
|
||||||
if(!running) {
|
if(page_stack.empty() || !running) {
|
||||||
window.set_visible(false);
|
running = false;
|
||||||
window.close();
|
goto quit;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while(window.poll_event(event)) {
|
while(window.poll_event(event)) {
|
||||||
current_page->on_event(event, window, mgl::vec2f(0.0f, 0.0f));
|
page_stack.top()->on_event(event, window, mgl::vec2f(0.0f, 0.0f));
|
||||||
if(event.type == mgl::Event::KeyPressed) {
|
if(event.type == mgl::Event::KeyPressed) {
|
||||||
if(event.key.code == mgl::Keyboard::Escape) {
|
if(event.key.code == mgl::Keyboard::Escape && !page_stack.empty())
|
||||||
window.set_visible(false);
|
page_stack.pop();
|
||||||
window.close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(page_stack.empty())
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(state_update_timer.get_elapsed_time_seconds() >= state_update_timeout_sec) {
|
// if(state_update_timer.get_elapsed_time_seconds() >= state_update_timeout_sec) {
|
||||||
@@ -889,10 +890,14 @@ int main(int argc, char **argv) {
|
|||||||
// update_overlay_shape();
|
// update_overlay_shape();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
render();
|
if(!page_stack.empty())
|
||||||
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quit:
|
||||||
fprintf(stderr, "shutting down!\n");
|
fprintf(stderr, "shutting down!\n");
|
||||||
|
gsr::deinit_theme();
|
||||||
|
window.close();
|
||||||
|
|
||||||
if(gpu_screen_recorder_process != -1) {
|
if(gpu_screen_recorder_process != -1) {
|
||||||
kill(gpu_screen_recorder_process, SIGINT);
|
kill(gpu_screen_recorder_process, SIGINT);
|
||||||
@@ -904,6 +909,5 @@ int main(int argc, char **argv) {
|
|||||||
gpu_screen_recorder_process = -1;
|
gpu_screen_recorder_process = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gsr::deinit_theme();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user