From 285d4fac383608a44b65c48b8c7e1d52a71c31e2 Mon Sep 17 00:00:00 2001 From: Aziz Berkay Yesilyurt Date: Tue, 13 Jul 2021 23:34:12 +0200 Subject: [PATCH] ImageViewer: Use the same function to resize the window ImageViewer used two different logic to resize the display window, which leads to confusing behaviour for rotate function. Now all the resizing behaviour goes through the existing resize_window function. --- Userland/Applications/ImageViewer/ViewWidget.cpp | 2 +- Userland/Applications/ImageViewer/ViewWidget.h | 4 ++-- Userland/Applications/ImageViewer/main.cpp | 12 ++---------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp index dc03eaca40..f2bf9b5b8d 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.cpp +++ b/Userland/Applications/ImageViewer/ViewWidget.cpp @@ -130,7 +130,7 @@ void ViewWidget::set_scale(int scale) m_bitmap_rect.set_size(new_size); if (on_scale_change) - on_scale_change(m_scale, m_bitmap_rect); + on_scale_change(m_scale); relayout(); } diff --git a/Userland/Applications/ImageViewer/ViewWidget.h b/Userland/Applications/ImageViewer/ViewWidget.h index 97d2da81ce..dc68b23eb9 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.h +++ b/Userland/Applications/ImageViewer/ViewWidget.h @@ -34,6 +34,7 @@ public: int toolbar_height() { return m_toolbar_height; } bool scaled_for_first_image() { return m_scaled_for_first_image; } void set_scaled_for_first_image(bool val) { m_scaled_for_first_image = val; } + void resize_window(); void clear(); void flip(Gfx::Orientation); @@ -41,7 +42,7 @@ public: void navigate(Directions); void load_from_file(const String&); - Function on_scale_change; + Function on_scale_change; Function on_doubleclick; Function on_drop; Function on_image_change; @@ -60,7 +61,6 @@ private: void set_bitmap(const Gfx::Bitmap* bitmap); void relayout(); - void resize_window(); void reset_view(); void animate(); diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp index 23a8437de8..cbd3cf5804 100644 --- a/Userland/Applications/ImageViewer/main.cpp +++ b/Userland/Applications/ImageViewer/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char** argv) auto& main_toolbar = toolbar_container.add(); auto& widget = root_widget.add(); - widget.on_scale_change = [&](int scale, Gfx::IntRect rect) { + widget.on_scale_change = [&](int scale) { if (!widget.bitmap()) { window->set_title("Image Viewer"); return; @@ -86,17 +86,9 @@ int main(int argc, char** argv) window->set_title(String::formatted("{} {} {}% - Image Viewer", widget.path(), widget.bitmap()->size().to_string(), scale)); - if (window->is_fullscreen()) - return; - - if (window->is_maximized()) - return; - if (scale == 100 && !widget.scaled_for_first_image()) { widget.set_scaled_for_first_image(true); - auto w = min(GUI::Desktop::the().rect().width(), rect.width() + 4); - auto h = min(GUI::Desktop::the().rect().height(), rect.height() + widget.toolbar_height() + 6); - window->resize(w, h); + widget.resize_window(); } }; widget.on_drop = [&](auto& event) {