edit: Use proper styling for toolbar
This commit is contained in:
parent
b6bdc9398d
commit
e9869bcb40
5 changed files with 149 additions and 135 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
lpcrop {
|
lpcrop {
|
||||||
--discarded-background: rgba(50, 50, 50, 0.7);
|
--discarded-background: rgba(50, 50, 50, 0.7);
|
||||||
--selection-border-color: rgba(255, 255, 255, 0.7);
|
--selection-border-color: rgb(240, 240, 240);
|
||||||
--handle-border-color: rgba(255, 255, 255, 0.9);
|
--handle-border-color: var(--selection-border-color);
|
||||||
--handle-size: 20px;
|
--handle-size: 20px;
|
||||||
--handle-border-width: 3px;
|
--handle-border-width: 3px;
|
||||||
--handle-offset: -4px;
|
--handle-offset: -4px;
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,20 @@ mod imp {
|
||||||
|
|
||||||
self.selection.ensure_initialized(x, y, width, height);
|
self.selection.ensure_initialized(x, y, width, height);
|
||||||
self.selection.set_size(x, y, width, height);
|
self.selection.set_size(x, y, width, height);
|
||||||
|
|
||||||
|
dbg!(self.image.widget_to_img_coord((
|
||||||
|
self.image.image_rendering_x() + self.selection.crop_x() as f64,
|
||||||
|
self.image.image_rendering_y() + self.selection.crop_y() as f64
|
||||||
|
)));
|
||||||
|
|
||||||
|
dbg!(self.image.widget_to_img_coord((
|
||||||
|
self.image.image_rendering_x()
|
||||||
|
+ self.selection.crop_x() as f64
|
||||||
|
+ self.selection.crop_width() as f64,
|
||||||
|
self.image.image_rendering_y()
|
||||||
|
+ self.selection.crop_y() as f64
|
||||||
|
+ self.selection.crop_height() as f64
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,9 @@
|
||||||
</menu>
|
</menu>
|
||||||
<template class="LpEditCrop" parent="GtkWidget">
|
<template class="LpEditCrop" parent="GtkWidget">
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkBox">
|
<object class="AdwToolbarView">
|
||||||
<property name="orientation">vertical</property>
|
<property name="bottom-bar-style">raised</property>
|
||||||
<child>
|
<property name="content">
|
||||||
<object class="GtkOverlay">
|
<object class="GtkOverlay">
|
||||||
<property name="margin-top">18</property>
|
<property name="margin-top">18</property>
|
||||||
<property name="margin-end">18</property>
|
<property name="margin-end">18</property>
|
||||||
|
|
@ -70,16 +70,27 @@
|
||||||
<property name="crop">LpEditCrop</property>
|
<property name="crop">LpEditCrop</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child type="overlay">
|
||||||
|
<object class="GtkButton">
|
||||||
|
<property name="label">Apply</property>
|
||||||
|
<property name="action-name">edit.apply-crop</property>
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="valign">start</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
</object>
|
||||||
|
</property>
|
||||||
|
<child type="bottom">
|
||||||
|
<object class="AdwClamp">
|
||||||
|
<property name="maximum-size">360</property>
|
||||||
|
<property name="child">
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="orientation">horizontal</property>
|
<property name="orientation">horizontal</property>
|
||||||
<property name="homogeneous">true</property>
|
<property name="homogeneous">true</property>
|
||||||
<property name="spacing">6</property>
|
<property name="spacing">6</property>
|
||||||
<property name="margin-bottom">16</property>
|
<style>
|
||||||
<property name="margin-start">16</property>
|
<class name="toolbar" />
|
||||||
<property name="margin-end">16</property>
|
</style>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="orientation">horizontal</property>
|
<property name="orientation">horizontal</property>
|
||||||
|
|
@ -183,6 +194,8 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,9 @@ impl WidgetImpl for imp::LpImage {
|
||||||
snapshot.translate(&graphene::Point::new(0., self.round_f64(y) as f32));
|
snapshot.translate(&graphene::Point::new(0., self.round_f64(y) as f32));
|
||||||
|
|
||||||
// Centering in widget when no scrolling (black bars around image)
|
// 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 x = obj.image_rendering_x();
|
||||||
let y = self.round_f64(f64::max((widget_height - display_height) / 2.0, 0.));
|
let y = obj.image_rendering_y();
|
||||||
// Round to pixel values to not have a half pixel offset to physical pixels
|
snapshot.translate(&graphene::Point::new(x as f32, y as f32));
|
||||||
// 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,
|
|
||||||
));
|
|
||||||
|
|
||||||
// Apply rotation and mirroring
|
// Apply rotation and mirroring
|
||||||
self.snapshot_rotate_mirror(
|
self.snapshot_rotate_mirror(
|
||||||
|
|
@ -339,6 +334,11 @@ impl LpImage {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
let widget_width = imp.widget_width();
|
let widget_width = imp.widget_width();
|
||||||
let display_width = imp.image_displayed_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.))
|
imp.round_f64(f64::max((widget_width - display_width) / 2.0, 0.))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,4 +358,14 @@ impl LpImage {
|
||||||
let imp = self.imp();
|
let imp = self.imp();
|
||||||
imp.round_f64(imp.image_displayed_height())
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
/// Required adjustment to put image coordinate under the cursor at this
|
||||||
/// zoom level
|
/// zoom level
|
||||||
fn adj_for_position(
|
fn adj_for_position(
|
||||||
|
|
@ -181,7 +158,7 @@ impl imp::LpImage {
|
||||||
img_pos
|
img_pos
|
||||||
} else {
|
} else {
|
||||||
// Use center of viewport
|
// 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 {
|
let cur_pos = if let Some(cur) = cur {
|
||||||
|
|
@ -274,7 +251,7 @@ impl imp::LpImage {
|
||||||
let img_pos: Option<(f64, f64)> = self
|
let img_pos: Option<(f64, f64)> = self
|
||||||
.pointer_position
|
.pointer_position
|
||||||
.get()
|
.get()
|
||||||
.map(|x| self.widget_to_img_coord(x));
|
.map(|x| obj.widget_to_img_coord(x));
|
||||||
self.zoom_cursor_target.set(img_pos);
|
self.zoom_cursor_target.set(img_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue