implement toogle button to show and hide neighbours

This commit is contained in:
2022-01-24 14:16:50 +01:00
parent c6252375a9
commit cd36dc44d5

View File

@@ -1,6 +1,6 @@
use adw::{prelude::*, ApplicationWindow, HeaderBar, SplitButton}; use adw::{prelude::*, ApplicationWindow, HeaderBar, SplitButton};
use gtk::{ use gtk::{
prelude::*, ActionBar, Adjustment, Align, Application, AspectFrame, Box, Button, Grid, Image, prelude::*, ActionBar, Adjustment, Application, AspectFrame, Box, Button, Grid, Image,
Orientation, Scale, Separator, ToggleButton, Orientation, Scale, Separator, ToggleButton,
}; };
@@ -9,6 +9,9 @@ const MARGIN_BOTTOM: i32 = 32;
const MARGIN_LEFT: i32 = 32; const MARGIN_LEFT: i32 = 32;
const MARGIN_RIGHT: i32 = 32; const MARGIN_RIGHT: i32 = 32;
const TOGGLE_NEIGHBOURS_TEXT_TOGGLED: &str = "Hide Neighbours";
const TOGGLE_NEIGHBOURS_TEXT: &str = "Show Neighbours";
fn main() { fn main() {
let application = Application::builder() let application = Application::builder()
.application_id("com.example.FirstAdwaitaApp") .application_id("com.example.FirstAdwaitaApp")
@@ -23,24 +26,28 @@ fn main() {
// MAIN CONTENT // // MAIN CONTENT //
////////////////// //////////////////
let focus_image = Image::builder() let focus_image = std::sync::Arc::new(
Image::builder()
.file("/var/home/hannes/Downloads/test/I12982_X022_Y029_Z5048.jpg") .file("/var/home/hannes/Downloads/test/I12982_X022_Y029_Z5048.jpg")
.vexpand(true) .vexpand(true)
.hexpand(true) .hexpand(true)
.build(); .build(),
);
let focus_neighbours_grid = Grid::builder() let focus_neighbours_grid = std::sync::Arc::new(
Grid::builder()
.vexpand(true) .vexpand(true)
.hexpand(true) .hexpand(true)
.column_spacing(0) .column_spacing(0)
.row_spacing(0) .row_spacing(0)
.build(); .build(),
);
let focus_neighbours_aspect_frame = AspectFrame::builder() let focus_neighbours_aspect_frame = AspectFrame::builder()
.child(&focus_neighbours_grid)
.ratio(1.0) .ratio(1.0)
.xalign(0.5) .xalign(0.5)
.yalign(0.5) .yalign(0.5)
.build(); .build();
focus_neighbours_aspect_frame.set_child(Some(focus_image.as_ref()));
let neighbours_1 = Image::builder() let neighbours_1 = Image::builder()
.vexpand(true) .vexpand(true)
@@ -88,8 +95,6 @@ fn main() {
.file("/var/home/hannes/Downloads/test/I12982_X022_Y029_Z5048.jpg") .file("/var/home/hannes/Downloads/test/I12982_X022_Y029_Z5048.jpg")
.build(); .build();
//focus_neighbours_grid.add
focus_neighbours_grid.attach(&neighbours_1, 0, 0, 1, 1); focus_neighbours_grid.attach(&neighbours_1, 0, 0, 1, 1);
focus_neighbours_grid.attach(&neighbours_2, 1, 0, 1, 1); focus_neighbours_grid.attach(&neighbours_2, 1, 0, 1, 1);
focus_neighbours_grid.attach(&neighbours_3, 2, 0, 1, 1); focus_neighbours_grid.attach(&neighbours_3, 2, 0, 1, 1);
@@ -107,7 +112,8 @@ fn main() {
.step_increment(1.0) .step_increment(1.0)
.build(); .build();
let focus_scale = Scale::builder() let focus_scale = std::sync::Arc::new(
Scale::builder()
.orientation(Orientation::Vertical) .orientation(Orientation::Vertical)
.adjustment(&focus_scale_adjustment) .adjustment(&focus_scale_adjustment)
.vexpand(true) .vexpand(true)
@@ -119,7 +125,8 @@ fn main() {
.inverted(true) .inverted(true)
.round_digits(0) .round_digits(0)
.digits(0) .digits(0)
.build(); .build(),
);
let center_content_seperator = Separator::new(Orientation::Vertical); let center_content_seperator = Separator::new(Orientation::Vertical);
let center_content = Box::builder() let center_content = Box::builder()
@@ -128,11 +135,11 @@ fn main() {
.spacing(0) .spacing(0)
.build(); .build();
center_content.append(&focus_scale); center_content.append(focus_scale.as_ref());
center_content.append(&center_content_seperator); center_content.append(&center_content_seperator);
//center_content.append(&focus_image);
center_content.append(&focus_neighbours_aspect_frame); center_content.append(&focus_neighbours_aspect_frame);
let focus_image_clone = focus_image.clone();
focus_scale.connect_value_changed(move |x| { focus_scale.connect_value_changed(move |x| {
eprintln!("Changed value! {:?}", x.value()); eprintln!("Changed value! {:?}", x.value());
let path = if x.value() > 6.0 { let path = if x.value() > 6.0 {
@@ -142,7 +149,7 @@ fn main() {
} else { } else {
"/var/home/hannes/Downloads/test/I12985_X022_Y029_Z5195.jpg" "/var/home/hannes/Downloads/test/I12985_X022_Y029_Z5195.jpg"
}; };
focus_image.set_from_file(Some(path)); focus_image_clone.as_ref().set_from_file(Some(path));
}); });
//////////// ////////////
@@ -176,8 +183,23 @@ fn main() {
focus_skip_link_widget.append(&skip_button); focus_skip_link_widget.append(&skip_button);
focus_skip_link_widget.append(&focus_button); focus_skip_link_widget.append(&focus_button);
let neighbour_toggle_button = ToggleButton::builder().label("Toggle Neighbours").build(); let neighbour_toggle_button = ToggleButton::builder()
.label(TOGGLE_NEIGHBOURS_TEXT)
.width_request(158)
.build();
let focus_image_clone = focus_image.clone();
let focus_neighbours_grid_clone = focus_neighbours_grid.clone();
neighbour_toggle_button.connect_toggled(move |x| match x.is_active() {
true => {
focus_neighbours_aspect_frame.set_child(Some(focus_neighbours_grid_clone.as_ref()));
x.set_label(TOGGLE_NEIGHBOURS_TEXT_TOGGLED);
}
false => {
focus_neighbours_aspect_frame.set_child(Some(focus_image_clone.as_ref()));
x.set_label(TOGGLE_NEIGHBOURS_TEXT);
}
});
bottom_toolbar.pack_start(&neighbour_toggle_button); bottom_toolbar.pack_start(&neighbour_toggle_button);
bottom_toolbar.pack_end(&focus_skip_link_widget); bottom_toolbar.pack_end(&focus_skip_link_widget);