Skip to content

Commit

Permalink
tweak operator UI
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Nov 24, 2024
1 parent 30890eb commit bba38c6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 59 deletions.
84 changes: 42 additions & 42 deletions src/image_editing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ impl ImageOperation {
ui.vertical(|ui| {
use egui::epaint::*;

const RECT_WIDTH: usize = 255;
let rect_width = 255.;

let (gradient_rect, mut response) =
ui.allocate_at_least(vec2(RECT_WIDTH as f32, 50.), Sense::click_and_drag());
ui.allocate_at_least(vec2(rect_width, 50.), Sense::click_and_drag());

let mut len_with_extra_pts = pts.len();
let len = pts.len();
Expand Down Expand Up @@ -484,7 +484,7 @@ impl ImageOperation {
}

// if last point is shifted, insert extra one at end
if i == len_with_extra_pts - 1 && color.pos < RECT_WIDTH as u8 {
if i == len_with_extra_pts - 1 && color.pos < rect_width as u8 {
let x = gradient_rect.right();
mesh.colored_vertex(pos2(x, gradient_rect.top()), egui_color);
mesh.colored_vertex(pos2(x, gradient_rect.bottom()), egui_color);
Expand All @@ -505,7 +505,7 @@ impl ImageOperation {

if let Some(hover) = response.hover_pos() {
let mouse_pos_in_gradient =
(hover.x - gradient_rect.left()).clamp(0.0, 255.) as i32;
(hover.x - gradient_rect.left()).clamp(0.0, rect_width) as i32;

// check which point is closest

Expand Down Expand Up @@ -871,48 +871,48 @@ impl ImageOperation {
} => {
let ratio = dimensions.1 as f32 / dimensions.0 as f32;

ui.horizontal(|ui| {
let mut r0 = ui.add(
egui::DragValue::new(&mut dimensions.0)
.speed(4.)
.clamp_range(1..=10000)
.prefix("X "),
);
let r1 = ui.add(
egui::DragValue::new(&mut dimensions.1)
.speed(4.)
.clamp_range(1..=10000)
.prefix("Y "),
);
let mut r = ui.allocate_response(Vec2::ZERO, Sense::hover());

if r0.changed() && *aspect {
dimensions.1 = (dimensions.0 as f32 * ratio) as u32
}
ui.vertical(|ui| {
ui.horizontal(|ui| {
let r0 = ui.add(
egui::DragValue::new(&mut dimensions.0)
.speed(4.)
.clamp_range(1..=10000)
.prefix("X "),
);
let r1 = ui.add(
egui::DragValue::new(&mut dimensions.1)
.speed(4.)
.clamp_range(1..=10000)
.prefix("Y "),
);

if r1.changed() {
r0.changed = true;
if *aspect {
dimensions.0 = (dimensions.1 as f32 / ratio) as u32
if r0.changed() && *aspect {
dimensions.1 = (dimensions.0 as f32 * ratio) as u32;
}
}

let r2 = ui
.styled_checkbox(aspect, "🔗")
.on_hover_text("Lock aspect ratio");

if r2.changed() {
r0.changed = true;

if *aspect {
dimensions.1 = (dimensions.0 as f32 * ratio) as u32;
if r1.changed() {
if *aspect {
dimensions.0 = (dimensions.1 as f32 / ratio) as u32
}
}
}
let r2 = ui
.styled_checkbox(aspect, "🔗")
.on_hover_text("Lock aspect ratio");

if r2.changed() {
if *aspect {
dimensions.1 = (dimensions.0 as f32 * ratio) as u32;
}
}
// For this operator, we want to update on release, not on change.
// Since all operators are processed the same, we use the hack to emit `changed` just on release.
// Users dragging the resize values will now only trigger a resize on release, which feels
// more snappy.
r.changed = r0.drag_stopped() || r1.drag_stopped() || r2.changed();
});

// For this operator, we want to update on release, not on change.
// Since all operators are processed the same, we use the hack to emit `changed` just on release.
// Users dragging the resize values will now only trigger a resize on release, which feels
// more snappy.
r0.changed = r0.drag_stopped() || r1.drag_stopped() || r2.changed();

egui::ComboBox::from_id_source("filter")
.selected_text(format!("{filter:?}"))
Expand All @@ -926,12 +926,12 @@ impl ImageOperation {
ScaleFilter::Lanczos3,
] {
if ui.selectable_value(filter, f, format!("{f:?}")).clicked() {
r0.changed = true;
r.changed = true;
}
}
});

r0
r
})
.inner
}
Expand Down
1 change: 0 additions & 1 deletion src/thumbnails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use image::{DynamicImage, GenericImageView};
use log::{debug, error, trace, warn};

use crate::{
file_encoder::{CompressionLevel, FileEncoder},
image_editing::ImageOperation,
image_loader::open_image,
};
Expand Down
38 changes: 22 additions & 16 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ pub fn edit_ui(app: &mut App, ctx: &Context, state: &mut OculanteState, gfx: &mu
ui, &state.image_geometry, &mut state.edit_state.block_panning, &mut state.volatile_settings
);


ui.label_i(&format!("Reset"));
ui.centered_and_justified(|ui| {
if ui.button("Reset all edits").clicked() {
Expand Down Expand Up @@ -1858,6 +1859,10 @@ fn modifier_stack_ui(
mouse_grab: &mut bool,
settings: &mut VolatileSettings,
) {




let mut delete: Option<usize> = None;
let mut swap: Option<(usize, usize)> = None;

Expand All @@ -1883,8 +1888,7 @@ fn modifier_stack_ui(
ui.style_mut().spacing.interact_size = Vec2::ZERO;
ui.style_mut().spacing.indent = 0.0;
ui.style_mut().spacing.item_spacing = Vec2::ZERO;
if egui::Button::new("")
.small()
if egui::Button::new(RichText::new("").size(24.))
.frame(false)
.ui(ui)
.on_hover_text("Remove operator")
Expand All @@ -1897,31 +1901,33 @@ fn modifier_stack_ui(
let up = i != 0;
let down = i != stack_len - 1;

let arrow_size = 8.;
let arrows_rect = ui.allocate_space(vec2(20., arrow_size));

let font_size = 8.;

ui.add_enabled_ui(up, |ui| {
if egui::Button::new("")
.small()
.frame(false)
.ui(ui)
.on_hover_text("Move up")
.clicked()
{
let ur = ui.put(
arrows_rect.1.translate(vec2(0., -7.)),
egui::Button::new(RichText::new("").size(font_size)).frame(false),
);
if ur.on_hover_text("Move up").clicked() {
swap = Some(((i as i32 - 1).max(0) as usize, i));
*image_changed = true;
}
});

ui.add_enabled_ui(down, |ui| {
if egui::Button::new("")
.small()
.frame(false)
.ui(ui)
.on_hover_text("Move down")
.clicked()
{
let dr = ui.put(
arrows_rect.1.translate(vec2(0., 2.)),
egui::Button::new(RichText::new("").size(font_size)).frame(false),
);
if dr.on_hover_text("Move down").clicked() {
swap = Some((i, i + 1));
*image_changed = true;
}
});
ui.add_space(80.);
});

ui.end_row();
Expand Down

0 comments on commit bba38c6

Please sign in to comment.