edit: Use proper styling for toolbar

This commit is contained in:
Sophie Herold 2024-09-19 20:13:53 +02:00
parent b6bdc9398d
commit e9869bcb40
5 changed files with 149 additions and 135 deletions

View file

@ -108,14 +108,9 @@ impl WidgetImpl for imp::LpImage {
snapshot.translate(&graphene::Point::new(0., self.round_f64(y) as f32));
// Centering in widget when no scrolling (black bars around image)
let x = self.round_f64(f64::max((widget_width - display_width) / 2.0, 0.));
let y = self.round_f64(f64::max((widget_height - display_height) / 2.0, 0.));
// Round to pixel values to not have a half pixel offset to physical pixels
// The offset would leading to a blurry output
snapshot.translate(&graphene::Point::new(
self.round_f64(x) as f32,
self.round_f64(y) as f32,
));
let x = obj.image_rendering_x();
let y = obj.image_rendering_y();
snapshot.translate(&graphene::Point::new(x as f32, y as f32));
// Apply rotation and mirroring
self.snapshot_rotate_mirror(
@ -339,6 +334,11 @@ impl LpImage {
let imp = self.imp();
let widget_width = imp.widget_width();
let display_width = imp.image_displayed_width();
// Centering in widget when no scrolling (black bars around image)
//
// Round to pixel values to not have a half pixel offset to physical pixels
// The offset would leading to a blurry output
imp.round_f64(f64::max((widget_width - display_width) / 2.0, 0.))
}
@ -358,4 +358,14 @@ impl LpImage {
let imp = self.imp();
imp.round_f64(imp.image_displayed_height())
}
/// Convert widget coordinates to image coordinates
pub fn widget_to_img_coord(&self, (cur_x, cur_y): (f64, f64)) -> (f64, f64) {
let imp = self.imp();
let zoom = imp.applicable_zoom();
let x = (cur_x - self.image_rendering_x() + imp.hadj_value()) / zoom;
let y = (cur_y - self.image_rendering_y() + imp.vadj_value()) / zoom;
(x, y)
}
}

View file

@ -103,29 +103,6 @@ impl imp::LpImage {
}
}
fn horizontal_bar(&self) -> f64 {
f64::max(
0.,
(self.widget_width() - self.image_displayed_width()) / 2.,
)
}
fn vertical_bar(&self) -> f64 {
f64::max(
0.,
(self.widget_height() - self.image_displayed_height()) / 2.,
)
}
/// Convert widget coordinates to image coordinates
fn widget_to_img_coord(&self, (cur_x, cur_y): (f64, f64)) -> (f64, f64) {
let zoom = self.applicable_zoom();
let x = (cur_x - self.horizontal_bar() + self.hadj_value()) / zoom;
let y = (cur_y - self.vertical_bar() + self.vadj_value()) / zoom;
(x, y)
}
/// Required adjustment to put image coordinate under the cursor at this
/// zoom level
fn adj_for_position(
@ -181,7 +158,7 @@ impl imp::LpImage {
img_pos
} else {
// Use center of viewport
self.widget_to_img_coord((self.widget_width() / 2., self.widget_height() / 2.))
obj.widget_to_img_coord((self.widget_width() / 2., self.widget_height() / 2.))
};
let cur_pos = if let Some(cur) = cur {
@ -274,7 +251,7 @@ impl imp::LpImage {
let img_pos: Option<(f64, f64)> = self
.pointer_position
.get()
.map(|x| self.widget_to_img_coord(x));
.map(|x| obj.widget_to_img_coord(x));
self.zoom_cursor_target.set(img_pos);
}
}