Move measurement point pickers into a side-by-side dropdown
This commit is contained in:
parent
c71d0003b8
commit
531b78df82
|
|
@ -1212,13 +1212,7 @@ impl Editor {
|
|||
let (r, _) = ui.allocate_exact_size(
|
||||
Vec2::new(
|
||||
ui.available_width(),
|
||||
1091.0
|
||||
+ if self.position_layer_point.is_some() {
|
||||
136.0
|
||||
} else {
|
||||
28.0
|
||||
}
|
||||
+ (row_count as f32 - 2.0) * 44.0,
|
||||
1071.0 + (row_count as f32 - 2.0) * 44.0,
|
||||
),
|
||||
egui::Sense::hover(),
|
||||
);
|
||||
|
|
@ -1530,124 +1524,47 @@ impl Editor {
|
|||
"Changes the crop values inside this layer. Drag content to reposition it; the visible box stays fixed."
|
||||
).size(12.0).color(palette.muted)).wrap().halign(egui::Align::Min),
|
||||
);
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 108.0)));
|
||||
ink.text(
|
||||
0.0,
|
||||
267.0,
|
||||
if self.position_layer_point.is_some() {
|
||||
"FROM SCREEN POINT"
|
||||
} else {
|
||||
"MEASURE POSITION FROM"
|
||||
},
|
||||
11.0,
|
||||
palette.muted,
|
||||
ink.text(0.0, 375.0, "MEASURE POSITION FROM", 11.0, palette.muted);
|
||||
let label = format!(
|
||||
"{} to {}",
|
||||
position_point_name(self.corner),
|
||||
position_point_name(self.position_layer_point.unwrap_or(self.corner))
|
||||
);
|
||||
ink.card(0.0, 292.0, 94.0, 58.0, palette.field, palette.line);
|
||||
for (x, y, c) in [
|
||||
(8.0, 300.0, PositionPoint::TopLeft),
|
||||
(84.0, 300.0, PositionPoint::TopRight),
|
||||
(8.0, 342.0, PositionPoint::BottomLeft),
|
||||
(84.0, 342.0, PositionPoint::BottomRight),
|
||||
(46.0, 321.0, PositionPoint::Center),
|
||||
] {
|
||||
ink.rect(
|
||||
x - 3.0,
|
||||
y - 3.0,
|
||||
6.0,
|
||||
6.0,
|
||||
if c == self.corner {
|
||||
palette.cyan
|
||||
} else {
|
||||
palette.muted
|
||||
},
|
||||
);
|
||||
if click(
|
||||
ui,
|
||||
&ink,
|
||||
[x - 10.0, y - 10.0, 20.0, 20.0],
|
||||
format!("corner-{c:?}"),
|
||||
) {
|
||||
self.corner = c;
|
||||
self.sync();
|
||||
self.autosave_position_points();
|
||||
}
|
||||
let button = ui.put(
|
||||
Rect::from_min_size(ink.point(0.0, 394.0), Vec2::new(w, 34.0)),
|
||||
egui::Button::new(label),
|
||||
);
|
||||
let arrow = button.rect.right_center() - Vec2::new(13.0, 0.0);
|
||||
ui.painter().add(egui::Shape::convex_polygon(
|
||||
vec![
|
||||
arrow + Vec2::new(-4.0, -2.0),
|
||||
arrow + Vec2::new(4.0, -2.0),
|
||||
arrow + Vec2::new(0.0, 3.0),
|
||||
],
|
||||
palette.muted,
|
||||
Stroke::NONE,
|
||||
));
|
||||
let popup = ui.id().with("measurement-points");
|
||||
if button.clicked() {
|
||||
ui.memory_mut(|m| m.toggle_popup(popup));
|
||||
}
|
||||
let (name, horizontal, vertical) = match self.corner {
|
||||
PositionPoint::Center => ("Center", "Center X offset", "Center Y offset"),
|
||||
PositionPoint::TopLeft => ("Top left", "From left", "From top"),
|
||||
PositionPoint::TopRight => ("Top right", "From right", "From top"),
|
||||
PositionPoint::BottomLeft => ("Bottom left", "From left", "From bottom"),
|
||||
PositionPoint::BottomRight => ("Bottom right", "From right", "From bottom"),
|
||||
egui::popup_below_widget(
|
||||
ui,
|
||||
popup,
|
||||
&button,
|
||||
egui::PopupCloseBehavior::CloseOnClickOutside,
|
||||
|ui| {
|
||||
self.measurement_points_menu(ui);
|
||||
},
|
||||
);
|
||||
let (horizontal, vertical) = match self.corner {
|
||||
PositionPoint::Center => ("Center X offset", "Center Y offset"),
|
||||
PositionPoint::TopLeft => ("From left", "From top"),
|
||||
PositionPoint::TopRight => ("From right", "From top"),
|
||||
PositionPoint::BottomLeft => ("From left", "From bottom"),
|
||||
PositionPoint::BottomRight => ("From right", "From bottom"),
|
||||
};
|
||||
ink.text(112.0, 299.0, name, 18.0, palette.text);
|
||||
ink.text(
|
||||
112.0,
|
||||
326.0,
|
||||
if self.corner == PositionPoint::Center {
|
||||
"+ right / + down · px"
|
||||
} else {
|
||||
"Offsets inward · px"
|
||||
},
|
||||
12.0,
|
||||
palette.muted,
|
||||
);
|
||||
let mut independent = self.position_layer_point.is_some();
|
||||
if ui
|
||||
.put(
|
||||
Rect::from_min_size(ink.point(0.0, 360.0), Vec2::new(w, 24.0)),
|
||||
egui::Checkbox::new(&mut independent, "Use a different measure point"),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
self.position_layer_point = independent.then_some(self.corner);
|
||||
self.sync();
|
||||
self.autosave_position_points();
|
||||
}
|
||||
if let Some(mut point) = self.position_layer_point {
|
||||
ink.text(0.0, 396.0, "TO LAYER POINT", 11.0, palette.muted);
|
||||
ink.card(0.0, 416.0, 94.0, 58.0, palette.field, palette.line);
|
||||
for (x, y, candidate) in [
|
||||
(8.0, 424.0, PositionPoint::TopLeft),
|
||||
(84.0, 424.0, PositionPoint::TopRight),
|
||||
(8.0, 466.0, PositionPoint::BottomLeft),
|
||||
(84.0, 466.0, PositionPoint::BottomRight),
|
||||
(46.0, 445.0, PositionPoint::Center),
|
||||
] {
|
||||
ink.rect(
|
||||
x - 3.0,
|
||||
y - 3.0,
|
||||
6.0,
|
||||
6.0,
|
||||
if point == candidate {
|
||||
palette.cyan
|
||||
} else {
|
||||
palette.muted
|
||||
},
|
||||
);
|
||||
if click(
|
||||
ui,
|
||||
&ink,
|
||||
[x - 10.0, y - 10.0, 20.0, 20.0],
|
||||
format!("layer-point-{candidate:?}"),
|
||||
) {
|
||||
point = candidate;
|
||||
self.position_layer_point = Some(point);
|
||||
self.sync();
|
||||
self.autosave_position_points();
|
||||
}
|
||||
}
|
||||
let name = match point {
|
||||
PositionPoint::TopLeft => "Top left",
|
||||
PositionPoint::TopRight => "Top right",
|
||||
PositionPoint::BottomLeft => "Bottom left",
|
||||
PositionPoint::BottomRight => "Bottom right",
|
||||
PositionPoint::Center => "Center",
|
||||
};
|
||||
ink.text(112.0, 423.0, name, 18.0, palette.text);
|
||||
ink.text(112.0, 450.0, "From screen to layer", 12.0, palette.muted);
|
||||
}
|
||||
let measure_extra = if independent { 136.0 } else { 28.0 };
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 108.0 + measure_extra)));
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 88.0)));
|
||||
let half = (w - 12.0) / 2.0;
|
||||
let mut enter = false;
|
||||
for (index, x, y, title) in [
|
||||
|
|
@ -1696,7 +1613,7 @@ impl Editor {
|
|||
)),
|
||||
|ui| self.resize_ratio_option(ui),
|
||||
);
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 160.0 + measure_extra)));
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 140.0)));
|
||||
let pending = self.fields_pending();
|
||||
if enter && pending {
|
||||
self.apply_fields();
|
||||
|
|
@ -1713,7 +1630,7 @@ impl Editor {
|
|||
.wrap(),
|
||||
);
|
||||
}
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 139.0 + measure_extra)));
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 119.0)));
|
||||
ink.line([0.0, 640.0], [w, 640.0], palette.line);
|
||||
ink.text(
|
||||
0.0,
|
||||
|
|
@ -1911,6 +1828,45 @@ impl Editor {
|
|||
self.settings.save(&options);
|
||||
}
|
||||
}
|
||||
fn measurement_points_menu(&mut self, ui: &mut egui::Ui) {
|
||||
let before = (self.corner, self.position_layer_point);
|
||||
let mut independent = self.position_layer_point.is_some();
|
||||
ui.horizontal(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label("From · screen");
|
||||
position_point_square(ui, &mut self.corner, "corner");
|
||||
ui.label(position_point_name(self.corner));
|
||||
});
|
||||
ui.add_space(16.0);
|
||||
ui.vertical(|ui| {
|
||||
ui.label("To · layer");
|
||||
let mut point = self.position_layer_point.unwrap_or(self.corner);
|
||||
ui.add_enabled_ui(independent, |ui| {
|
||||
position_point_square(ui, &mut point, "layer-point");
|
||||
});
|
||||
ui.label(position_point_name(point));
|
||||
if independent {
|
||||
self.position_layer_point = Some(point);
|
||||
}
|
||||
});
|
||||
});
|
||||
if ui
|
||||
.checkbox(&mut independent, "Use a different measure point")
|
||||
.changed()
|
||||
{
|
||||
self.position_layer_point = independent.then_some(self.corner);
|
||||
}
|
||||
ui.weak(if self.corner == PositionPoint::Center {
|
||||
"Offsets: positive right / down, in pixels."
|
||||
} else {
|
||||
"Offsets: inward from the screen corner, in pixels."
|
||||
});
|
||||
if before != (self.corner, self.position_layer_point) {
|
||||
self.sync();
|
||||
self.autosave_position_points();
|
||||
}
|
||||
}
|
||||
|
||||
fn layer_context_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.set_min_width(210.0);
|
||||
if let Some(id) = self.layer_ui.context_layer {
|
||||
|
|
@ -3476,6 +3432,52 @@ fn click_shift_modifier(ui: &egui::Ui) -> bool {
|
|||
.unwrap_or(input.modifiers.shift)
|
||||
})
|
||||
}
|
||||
fn position_point_name(point: PositionPoint) -> &'static str {
|
||||
match point {
|
||||
PositionPoint::TopLeft => "Top left",
|
||||
PositionPoint::TopRight => "Top right",
|
||||
PositionPoint::BottomLeft => "Bottom left",
|
||||
PositionPoint::BottomRight => "Bottom right",
|
||||
PositionPoint::Center => "Center",
|
||||
}
|
||||
}
|
||||
|
||||
fn position_point_square(ui: &mut egui::Ui, point: &mut PositionPoint, prefix: &str) {
|
||||
let palette = theme::palette(ui.ctx());
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(104.0, 76.0), egui::Sense::hover());
|
||||
let ink = Ink::new(ui, rect);
|
||||
ink.card(5.0, 9.0, 94.0, 58.0, palette.field, palette.line);
|
||||
for (x, y, candidate) in [
|
||||
(13.0, 17.0, PositionPoint::TopLeft),
|
||||
(89.0, 17.0, PositionPoint::TopRight),
|
||||
(13.0, 59.0, PositionPoint::BottomLeft),
|
||||
(89.0, 59.0, PositionPoint::BottomRight),
|
||||
(51.0, 38.0, PositionPoint::Center),
|
||||
] {
|
||||
ink.rect(
|
||||
x - 3.0,
|
||||
y - 3.0,
|
||||
6.0,
|
||||
6.0,
|
||||
if *point == candidate {
|
||||
palette.cyan
|
||||
} else {
|
||||
palette.muted
|
||||
},
|
||||
);
|
||||
let response = ui
|
||||
.interact(
|
||||
Rect::from_center_size(ink.point(x, y), Vec2::splat(20.0)),
|
||||
egui::Id::new(format!("{prefix}-{candidate:?}")),
|
||||
egui::Sense::click(),
|
||||
)
|
||||
.on_hover_text(position_point_name(candidate));
|
||||
if response.clicked() {
|
||||
*point = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn click(ui: &egui::Ui, ink: &Ink, b: [f32; 4], id: impl std::hash::Hash) -> bool {
|
||||
let clicked = ui
|
||||
.interact(
|
||||
|
|
@ -4395,30 +4397,16 @@ mod tests {
|
|||
};
|
||||
app.sync();
|
||||
let before = app.layout.layers().clone();
|
||||
let has_advanced = |out: &egui::FullOutput| {
|
||||
out.shapes.iter().any(
|
||||
|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == "TO LAYER POINT"),
|
||||
)
|
||||
};
|
||||
assert!(!has_advanced(&frame(&mut app, &ctx, vec![])));
|
||||
click_text(&mut app, &ctx, "Use a different measure point");
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let center = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == "TO LAYER POINT" => {
|
||||
Some(t.pos + Vec2::new(46.0, 49.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
open_measurement_menu(&mut app, &ctx);
|
||||
let from = ctx.read_response(egui::Id::new("corner-Center")).unwrap();
|
||||
let to = ctx
|
||||
.read_response(egui::Id::new("layer-point-Center"))
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(center), mouse(center, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(center, false)]);
|
||||
assert_eq!(from.rect.center().y, to.rect.center().y);
|
||||
assert!(from.rect.right() < to.rect.left());
|
||||
assert!(!to.enabled());
|
||||
click_text(&mut app, &ctx, "Use a different measure point");
|
||||
click_measurement_point(&mut app, &ctx, "layer-point-Center");
|
||||
assert_eq!(app.position_layer_point, Some(PositionPoint::Center));
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
let center = before[1].center();
|
||||
|
|
@ -4430,7 +4418,6 @@ mod tests {
|
|||
let resized = app.layout.layers().clone();
|
||||
click_text(&mut app, &ctx, "Use a different measure point");
|
||||
assert!(app.position_layer_point.is_none());
|
||||
assert!(!has_advanced(&frame(&mut app, &ctx, vec![])));
|
||||
assert_eq!(app.layout.layers(), &resized);
|
||||
assert_eq!(app.fields[0], number(resized[1].x));
|
||||
}
|
||||
|
|
@ -5447,6 +5434,38 @@ mod tests {
|
|||
assert!(warning(&frame(&mut app, &ctx, vec![])));
|
||||
}
|
||||
|
||||
pub(super) fn open_measurement_menu(app: &mut Editor, ctx: &egui::Context) {
|
||||
frame(app, ctx, vec![]);
|
||||
let output = frame(app, ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == "MEASURE POSITION FROM" => {
|
||||
Some(t.pos + Vec2::new(46.0, 34.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
app,
|
||||
ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
frame(app, ctx, vec![]);
|
||||
}
|
||||
pub(super) fn click_measurement_point(app: &mut Editor, ctx: &egui::Context, id: &str) {
|
||||
frame(app, ctx, vec![]);
|
||||
let pos = ctx.read_response(egui::Id::new(id)).unwrap().rect.center();
|
||||
frame(
|
||||
app,
|
||||
ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn center_marker_switches_reference_without_moving_and_resizes_about_center() {
|
||||
let ctx = egui::Context::default();
|
||||
|
|
@ -5454,23 +5473,8 @@ mod tests {
|
|||
frame(&mut app, &ctx, vec![]);
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let before = app.layout.layers().clone();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|shape| match &shape.shape {
|
||||
egui::Shape::Text(text) if text.galley.text() == "MEASURE POSITION FROM" => {
|
||||
Some(text.pos + Vec2::new(46.0, 54.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
open_measurement_menu(&mut app, &ctx);
|
||||
click_measurement_point(&mut app, &ctx, "corner-Center");
|
||||
assert_eq!(app.corner, PositionPoint::Center);
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
let i = app.layout.selected().unwrap();
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn measurement_clicks_autosave_only_points_and_exports_keep_project_target() {
|
||||
use super::super::tests::{click_text, frame, mouse};
|
||||
use super::super::tests::click_text;
|
||||
let ctx = egui::Context::default();
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("layout.json");
|
||||
|
|
@ -695,46 +695,14 @@ mod tests {
|
|||
external.editor.backdrop_title = "External title".into();
|
||||
write_file(&path, external.to_json().unwrap().as_bytes(), true).unwrap();
|
||||
app.sync();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == "MEASURE POSITION FROM" => {
|
||||
Some(t.pos + Vec2::new(84.0, 75.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
super::super::tests::open_measurement_menu(&mut app, &ctx);
|
||||
super::super::tests::click_measurement_point(&mut app, &ctx, "corner-BottomRight");
|
||||
external.editor.position_point = PositionPoint::BottomRight;
|
||||
assert_eq!(Project::read(&path).unwrap(), external);
|
||||
click_text(&mut app, &ctx, "Use a different measure point");
|
||||
external.editor.position_layer_point = Some(PositionPoint::BottomRight);
|
||||
assert_eq!(Project::read(&path).unwrap(), external);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == "TO LAYER POINT" => {
|
||||
Some(t.pos + Vec2::new(46.0, 49.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
super::super::tests::click_measurement_point(&mut app, &ctx, "layer-point-Center");
|
||||
external.editor.position_layer_point = Some(PositionPoint::Center);
|
||||
assert_eq!(Project::read(&path).unwrap(), external);
|
||||
click_text(&mut app, &ctx, "Use a different measure point");
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Compact Measure position from into a dropdown with side-by-side From screen
|
||||
and To layer pickers and a summary of both points. Preserve linked/independent
|
||||
point selection and project autosave; regression checks exercise the popup.
|
||||
|
||||
- Record a distant-future stretch goal for multiple editor screens in one project,
|
||||
selected through a dropdown with one screen displayed at a time.
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ not affect device links or source assignments. All document edits support Undo.
|
|||
deltas and preserves fractional starting positions, sizes and relative spacing.
|
||||
Drag a corner handle to resize that layer, or use the single-layer numeric fields.
|
||||
- Arrow keys move the selection by **1 px**; Shift-arrow moves it by **10 px**.
|
||||
- Under **Measure position from**, choose a corner or the center marker. Center offsets measure layer center from screen center (positive right/down); zero centers the layer. Switching reference changes the displayed
|
||||
- Open the **Measure position from** dropdown to choose a corner or the center marker. The **From · screen** and **To · layer** squares sit side by side; To follows From until **Use a different measure point** is enabled. The closed dropdown summarizes both points. Center offsets measure layer center from screen center (positive right/down); zero centers the layer. Switching reference changes the displayed
|
||||
offsets without moving the layer. Position and size edits apply when you leave
|
||||
a field or press Enter. Resizing preserves that
|
||||
reference point's offsets. Invalid values leave the document unchanged.
|
||||
|
|
|
|||
Loading…
Reference in New Issue