Skip to content

Commit

Permalink
Make debug windows right edge sticky
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GrayHatter committed Jan 21, 2023
1 parent e66c14e commit 8453687
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
31 changes: 31 additions & 0 deletions browser/gui/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <imgui-SFML.h>
#include <imgui.h>
#include <imgui_stdlib.h>
#include <imgui_internal.h>
#include <spdlog/spdlog.h>

#include <cmath>
Expand Down Expand Up @@ -156,6 +157,35 @@ void App::set_scale(unsigned scale) {
engine_.set_layout_width(windowSize.x / scale_);
}

void App::sticky_windows(sf::Event::SizeEvent size) {
const char *names[] = {
"Navigation",
"HTTP Response",
"DOM",
"Stylesheet",
"Layout",
NULL,
};

int delta = k_width - size.width;
for (uint8_t i = 0;; ++i) {
const char *name = names[i];
if (!name) {
break;
}
ImGuiWindow *win = ImGui::FindWindowByName(name);
if (!win) {
continue;
}
int edge = win->Pos.x + win->Size.x;
if (edge == k_width) {
ImGui::SetWindowPos(name, {win->Pos.x - delta, win->Pos.y});
}
}
k_width = size.width;
k_height = size.height;
}

int App::run() {
while (window_.isOpen()) {
sf::Event event;
Expand All @@ -170,6 +200,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: {
Expand Down
5 changes: 4 additions & 1 deletion browser/gui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "uri/uri.h"
#include "util/history.h"

#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Cursor.hpp>
Expand Down Expand Up @@ -74,7 +75,9 @@ class App final {

void navigate();
void layout();

void sticky_windows(sf::Event::SizeEvent);
int k_width, k_height;

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

Expand Down

0 comments on commit 8453687

Please sign in to comment.