image: Show window after 2 secs if dims unknown

Usually we want to wait for dimensions to show the window in correct
apsect ration. But especially for large SVGs dimensions are only known pretty late.
Show the image to give UI feedback instead of waiting for dimensions.

Closes #146

Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/209>
This commit is contained in:
Sophie Herold 2023-04-27 21:12:47 +02:00 • committed by Marge Bot
parent 6db58463bf
commit 3d6940cd45

View file

@ -38,12 +38,15 @@ use crate::config;
use crate::util::{self, Direction, Position}; use crate::util::{self, Direction, Position};
use crate::widgets::{LpImage, LpImageView, LpPropertiesView}; use crate::widgets::{LpImage, LpImageView, LpPropertiesView};
/// Show window after X milliseconds even if image dimensions are not known yet
const SHOW_WINDOW_AFTER: u64 = 2000;
/// Animation duration for showing overlay buttons in milliseconds /// Animation duration for showing overlay buttons in milliseconds
const SHOW_CONTROLS_ANIMATION_DURATION: u32 = 200; const SHOW_CONTROLS_ANIMATION_DURATION: u32 = 200;
/// Animation duration for hiding overlay buttons in milliseconds /// Animation duration for hiding overlay buttons in milliseconds
const HIDE_CONTROLS_ANIMATION_DURATION: u32 = 1000; const HIDE_CONTROLS_ANIMATION_DURATION: u32 = 1000;
/// Time of inactivity after which controls will be hidden in seconds /// Time of inactivity after which controls will be hidden in milliseconds
const HIDE_CONTROLS_IDLE_TIMEOUT: u32 = 3; const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000;
mod imp { mod imp {
use super::*; use super::*;
@ -241,6 +244,11 @@ mod imp {
// and keeps the others usable // and keeps the others usable
gtk::WindowGroup::new().add_window(&*obj); gtk::WindowGroup::new().add_window(&*obj);
glib::timeout_add_local_once(
std::time::Duration::from_millis(SHOW_WINDOW_AFTER),
glib::clone!(@weak obj => move || if !obj.is_visible() { obj.present() }),
);
obj.on_images_available(); obj.on_images_available();
let current_image_signals = self.image_view.current_image_signals(); let current_image_signals = self.image_view.current_image_signals();
@ -726,12 +734,12 @@ impl LpWindow {
}) })
} }
/// Queue a fade animation to play after `HIDE_CONTROLS_IDLE_TIMEOUT` seconds of inactivity /// Queue a fade animation to play after `HIDE_CONTROLS_IDLE_TIMEOUT` of inactivity
fn queue_hide_controls(&self) { fn queue_hide_controls(&self) {
self.dequeue_hide_controls(); self.dequeue_hide_controls();
let new_timeout = glib::timeout_add_seconds_local_once( let new_timeout = glib::timeout_add_local_once(
HIDE_CONTROLS_IDLE_TIMEOUT, std::time::Duration::from_millis(HIDE_CONTROLS_IDLE_TIMEOUT),
glib::clone!(@weak self as win => move || { glib::clone!(@weak self as win => move || {
win.imp().hide_controls_timeout.take(); win.imp().hide_controls_timeout.take();
win.hide_controls(); win.hide_controls();