Add thumbnail selection for compression and watermark previews
Users can now click different batch images in a thumbnail strip to switch which image is used for the quality comparison preview and watermark position preview. Shows up to 10 thumbnails with accent highlight on the selected one.
This commit is contained in:
@@ -237,6 +237,59 @@ pub fn build_watermark_page(state: &AppState) -> adw::NavigationPage {
|
||||
preview_picture.set_visible(has_files);
|
||||
}
|
||||
|
||||
// Thumbnail strip for selecting preview image
|
||||
let wm_thumb_box = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.spacing(4)
|
||||
.halign(gtk::Align::Center)
|
||||
.margin_top(4)
|
||||
.build();
|
||||
{
|
||||
let files = state.loaded_files.borrow();
|
||||
let max_thumbs = files.len().min(10);
|
||||
for i in 0..max_thumbs {
|
||||
let pic = gtk::Picture::builder()
|
||||
.content_fit(gtk::ContentFit::Cover)
|
||||
.width_request(40)
|
||||
.height_request(40)
|
||||
.build();
|
||||
pic.set_filename(Some(&files[i]));
|
||||
let frame = gtk::Frame::builder()
|
||||
.child(&pic)
|
||||
.build();
|
||||
if i == 0 { frame.add_css_class("accent"); }
|
||||
|
||||
let btn = gtk::Button::builder()
|
||||
.child(&frame)
|
||||
.has_frame(false)
|
||||
.tooltip_text(files[i].file_name().and_then(|n| n.to_str()).unwrap_or("image"))
|
||||
.build();
|
||||
|
||||
let pp = preview_picture.clone();
|
||||
let path = files[i].clone();
|
||||
let tb = wm_thumb_box.clone();
|
||||
let current_idx = i;
|
||||
btn.connect_clicked(move |_| {
|
||||
pp.set_filename(Some(&path));
|
||||
let mut c = tb.first_child();
|
||||
let mut j = 0usize;
|
||||
while let Some(w) = c {
|
||||
if let Some(b) = w.downcast_ref::<gtk::Button>() {
|
||||
if let Some(f) = b.child().and_then(|c| c.downcast::<gtk::Frame>().ok()) {
|
||||
if j == current_idx { f.add_css_class("accent"); }
|
||||
else { f.remove_css_class("accent"); }
|
||||
}
|
||||
}
|
||||
c = w.next_sibling();
|
||||
j += 1;
|
||||
}
|
||||
});
|
||||
|
||||
wm_thumb_box.append(&btn);
|
||||
}
|
||||
wm_thumb_box.set_visible(max_thumbs > 1);
|
||||
}
|
||||
|
||||
let preview_stack = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.spacing(4)
|
||||
@@ -244,6 +297,7 @@ pub fn build_watermark_page(state: &AppState) -> adw::NavigationPage {
|
||||
.margin_bottom(8)
|
||||
.build();
|
||||
preview_stack.append(&preview_overlay);
|
||||
preview_stack.append(&wm_thumb_box);
|
||||
preview_stack.append(&no_preview_label);
|
||||
|
||||
preview_group.add(&preview_stack);
|
||||
|
||||
Reference in New Issue
Block a user