From 21653933e04fca111966feb41ddcd78a35d80f25 Mon Sep 17 00:00:00 2001 From: Gregory Mullen <_@gr.ht> Date: Sat, 21 Jan 2023 12:35:07 -0800 Subject: [PATCH] gui: make debug windows right edge sticky Now when the right edge of any debug window in the list is at the edge of the viewport width, it will stick there through resizes. There's a bug where if the resize change is enough to "capture" a window that wasn't intended to be sticky it will capture. Given this didn't happen much during testing, I don't think the extra state + code required is worth it for these windows. --- browser/gui/app.cpp | 18 ++++++++++++++++++ browser/gui/app.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/browser/gui/app.cpp b/browser/gui/app.cpp index 47b77664..c85239de 100644 --- a/browser/gui/app.cpp +++ b/browser/gui/app.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -134,6 +135,8 @@ App::App(std::string browser_title, std::string start_page_hint, bool load_start engine_.set_on_page_loaded(std::bind_front(&App::on_page_loaded, this)); engine_.set_on_layout_updated(std::bind_front(&App::on_layout_updated, this)); + prev_sticky_w = 0; + if (load_start_page) { ensure_has_scheme(url_buf_); navigate(); @@ -159,6 +162,20 @@ void App::set_scale(unsigned scale) { engine_.set_layout_width(windowSize.x / scale_); } +void App::sticky_windows(const sf::Event::SizeEvent &size) { + int delta = prev_sticky_w - size.width; + for (ImGuiWindow *win : GImGui->Windows) { + if (!win) { + continue; + } + int edge = static_cast(win->Pos.x) + static_cast(win->Size.x); + if (edge == prev_sticky_w) { + ImGui::SetWindowPos(win, {win->Pos.x - delta, win->Pos.y}); + } + } + prev_sticky_w = size.width; +} + int App::run() { while (window_.isOpen()) { sf::Event event; @@ -173,6 +190,7 @@ int App::run() { case sf::Event::Resized: { canvas_->set_viewport_size(event.size.width, event.size.height); engine_.set_layout_width(event.size.width / scale_); + sticky_windows(event.size); break; } case sf::Event::KeyPressed: { diff --git a/browser/gui/app.h b/browser/gui/app.h index 0ef275fe..5ea461b5 100644 --- a/browser/gui/app.h +++ b/browser/gui/app.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,8 @@ class App final { void navigate(); void layout(); + void sticky_windows(const sf::Event::SizeEvent &); + int prev_sticky_w; std::vector get_hovered_nodes(geom::Position document_position) const; geom::Position to_document_position(geom::Position window_position) const;