imageView: Include overlay controls in min size

This stops the overlay controls to overlap for very small
window sizes and properties opened.

LpImageView already does custom measure and overlay is it's
direct child. So added it here.

Fixes #32
This commit is contained in:
Sophie Herold 2022-12-08 02:00:50 +01:00 • committed by Christopher Davis
parent 65808f5894
commit 01bebfef38

View file

@ -52,7 +52,12 @@ mod imp {
/// Direct child of this Adw::Bin /// Direct child of this Adw::Bin
#[template_child] #[template_child]
pub bin_child: TemplateChild<gtk::Widget>, pub bin_child: TemplateChild<gtk::Widget>,
/// overlayed controls
#[template_child]
pub controls_box_start: TemplateChild<gtk::Widget>,
/// overlayed controls
#[template_child]
pub controls_box_end: TemplateChild<gtk::Widget>,
#[template_child] #[template_child]
pub carousel: TemplateChild<adw::Carousel>, pub carousel: TemplateChild<adw::Carousel>,
@ -168,8 +173,14 @@ mod imp {
/// one of the opened (current) image. /// one of the opened (current) image.
fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) { fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
// Measure child of AdwBin // Measure child of AdwBin
let child_measure @ (child_min, _, _, _) = let (child_min, child_natural, _, _) = self.bin_child.measure(orientation, for_size);
self.bin_child.measure(orientation, for_size);
// measure size of controls overlays
let (overlay1_min, _, _, _) = self.controls_box_start.measure(orientation, for_size);
let (overlay2_min, _, _, _) = self.controls_box_end.measure(orientation, for_size);
// take as minimum whatever is larger
let min = i32::max(child_min, overlay1_min + overlay2_min);
if let Some(page) = self.instance().current_page_strict() { if let Some(page) = self.instance().current_page_strict() {
// measure `LpImage` // measure `LpImage`
@ -178,10 +189,10 @@ mod imp {
// Ensure that minimum size is not smaller than the one of the child. // Ensure that minimum size is not smaller than the one of the child.
// Also ensure that the natural width is not smaller than the minimal size. // Also ensure that the natural width is not smaller than the minimal size.
// Both things are required by GTK. // Both things are required by GTK.
(child_min, i32::max(child_min, image_natural), -1, -1) (min, i32::max(min, image_natural), -1, -1)
} else { } else {
// If there is no image, just pass through the normal measurement // also include controls overlays when mostly passing through child measurements
child_measure (min, i32::max(child_natural, min), -1, -1)
} }
} }