From d509b3e1acc9725250ea5a692dbb93e3bdda0ff8 Mon Sep 17 00:00:00 2001 From: KeksNino Date: Sat, 25 Oct 2025 22:33:07 +0200 Subject: [PATCH] fix image preview and add scrollbar --- src/gui.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/gui.rs b/src/gui.rs index 3c911e5..06f645e 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -1,5 +1,7 @@ use gtk::prelude::*; -use gtk::{glib, Application, ApplicationWindow, Button, FlowBox, Image}; +use gtk::{ + glib, Application, ApplicationWindow, Button, FlowBox, Image, PolicyType, ScrolledWindow, +}; use walkdir::WalkDir; pub fn gui() -> glib::ExitCode { @@ -13,11 +15,7 @@ pub fn gui() -> glib::ExitCode { } fn build_ui(app: &Application) { - let container = gtk::Box::new(gtk::Orientation::Vertical, 10); - let wallpaper_dir = "/home/user/Desktop/coding/LinuxWallpaperEngineGUI/431960.o"; - let image = Image::new(); - image.set_pixel_size(150); let flow_box = FlowBox::new(); for entry in WalkDir::new(wallpaper_dir) @@ -32,13 +30,23 @@ fn build_ui(app: &Application) { }) { let path_str = path.to_str().unwrap(); + let image = Image::new(); + image.set_pixel_size(150); image.set_from_file(Some(path_str)); flow_box.append(&image); println!("Found wallpaper preview: {}", path_str); } } - container.append(&flow_box); + flow_box.connect_child_activated(|_, _| { + println!("Selected wallpaper preview"); + }); + + let scrolled_window = ScrolledWindow::builder() + .hscrollbar_policy(PolicyType::Never) + .min_content_width(360) + .child(&flow_box) + .build(); let button = Button::builder() .label("button") @@ -57,7 +65,7 @@ fn build_ui(app: &Application) { .title("Linux Wallpaper Engine") .default_width(800) .default_height(600) - .child(&container) + .child(&scrolled_window) .build(); window.present();