Skip to content

Commit 1b8ca1e

Browse files
committed
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.
1 parent ab35e8b commit 1b8ca1e

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

browser/gui/app.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <imgui-SFML.h>
1818
#include <imgui.h>
1919
#include <imgui_stdlib.h>
20+
#include <imgui_internal.h>
2021
#include <spdlog/spdlog.h>
2122

2223
#include <algorithm>
@@ -159,6 +160,20 @@ void App::set_scale(unsigned scale) {
159160
engine_.set_layout_width(windowSize.x / scale_);
160161
}
161162

163+
void App::sticky_windows(const sf::Event::SizeEvent &size) {
164+
int delta = prev_sticky_w - size.width;
165+
for (ImGuiWindow *win : GImGui->Windows) {
166+
if (!win) {
167+
continue;
168+
}
169+
int edge = static_cast<int>(win->Pos.x) + static_cast<int>(win->Size.x);
170+
if (edge == prev_sticky_w) {
171+
ImGui::SetWindowPos(win, {win->Pos.x - delta, win->Pos.y});
172+
}
173+
}
174+
prev_sticky_w = size.width;
175+
}
176+
162177
int App::run() {
163178
while (window_.isOpen()) {
164179
sf::Event event;
@@ -173,6 +188,7 @@ int App::run() {
173188
case sf::Event::Resized: {
174189
canvas_->set_viewport_size(event.size.width, event.size.height);
175190
engine_.set_layout_width(event.size.width / scale_);
191+
sticky_windows(event.size);
176192
break;
177193
}
178194
case sf::Event::KeyPressed: {

browser/gui/app.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <SFML/Graphics/RenderWindow.hpp>
1818
#include <SFML/System/Clock.hpp>
1919
#include <SFML/Window/Cursor.hpp>
20+
#include <SFML/Window/Event.hpp>
2021

2122
#include <memory>
2223
#include <string>
@@ -74,6 +75,8 @@ class App final {
7475

7576
void navigate();
7677
void layout();
78+
void sticky_windows(const sf::Event::SizeEvent &);
79+
int prev_sticky_w;
7780

7881
std::vector<dom::Node const *> get_hovered_nodes(geom::Position document_position) const;
7982
geom::Position to_document_position(geom::Position window_position) const;

0 commit comments

Comments
 (0)