mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-16 12:52:46 +00:00
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.
This commit is contained in:
parent
a19a40d6d3
commit
285d4fac38
|
@ -130,7 +130,7 @@ void ViewWidget::set_scale(int scale)
|
||||||
m_bitmap_rect.set_size(new_size);
|
m_bitmap_rect.set_size(new_size);
|
||||||
|
|
||||||
if (on_scale_change)
|
if (on_scale_change)
|
||||||
on_scale_change(m_scale, m_bitmap_rect);
|
on_scale_change(m_scale);
|
||||||
|
|
||||||
relayout();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
int toolbar_height() { return m_toolbar_height; }
|
int toolbar_height() { return m_toolbar_height; }
|
||||||
bool scaled_for_first_image() { return m_scaled_for_first_image; }
|
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 set_scaled_for_first_image(bool val) { m_scaled_for_first_image = val; }
|
||||||
|
void resize_window();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void flip(Gfx::Orientation);
|
void flip(Gfx::Orientation);
|
||||||
|
@ -41,7 +42,7 @@ public:
|
||||||
void navigate(Directions);
|
void navigate(Directions);
|
||||||
void load_from_file(const String&);
|
void load_from_file(const String&);
|
||||||
|
|
||||||
Function<void(int, Gfx::IntRect)> on_scale_change;
|
Function<void(int)> on_scale_change;
|
||||||
Function<void()> on_doubleclick;
|
Function<void()> on_doubleclick;
|
||||||
Function<void(const GUI::DropEvent&)> on_drop;
|
Function<void(const GUI::DropEvent&)> on_drop;
|
||||||
Function<void(const Gfx::Bitmap*)> on_image_change;
|
Function<void(const Gfx::Bitmap*)> on_image_change;
|
||||||
|
@ -60,7 +61,6 @@ private:
|
||||||
void set_bitmap(const Gfx::Bitmap* bitmap);
|
void set_bitmap(const Gfx::Bitmap* bitmap);
|
||||||
|
|
||||||
void relayout();
|
void relayout();
|
||||||
void resize_window();
|
|
||||||
void reset_view();
|
void reset_view();
|
||||||
void animate();
|
void animate();
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ int main(int argc, char** argv)
|
||||||
auto& main_toolbar = toolbar_container.add<GUI::Toolbar>();
|
auto& main_toolbar = toolbar_container.add<GUI::Toolbar>();
|
||||||
|
|
||||||
auto& widget = root_widget.add<ViewWidget>();
|
auto& widget = root_widget.add<ViewWidget>();
|
||||||
widget.on_scale_change = [&](int scale, Gfx::IntRect rect) {
|
widget.on_scale_change = [&](int scale) {
|
||||||
if (!widget.bitmap()) {
|
if (!widget.bitmap()) {
|
||||||
window->set_title("Image Viewer");
|
window->set_title("Image Viewer");
|
||||||
return;
|
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));
|
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()) {
|
if (scale == 100 && !widget.scaled_for_first_image()) {
|
||||||
widget.set_scaled_for_first_image(true);
|
widget.set_scaled_for_first_image(true);
|
||||||
auto w = min(GUI::Desktop::the().rect().width(), rect.width() + 4);
|
widget.resize_window();
|
||||||
auto h = min(GUI::Desktop::the().rect().height(), rect.height() + widget.toolbar_height() + 6);
|
|
||||||
window->resize(w, h);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
widget.on_drop = [&](auto& event) {
|
widget.on_drop = [&](auto& event) {
|
||||||
|
|
Loading…
Reference in a new issue