Support dynamic rectangle resizing via grip editing

This commit is contained in:
Marcel committed 2026-09-11 20:52:33 +02:00
1 parent f30b490831
commit 913705106e
8 files changed
+282 -41

No files matched your search

+101 -14
View File
@@ -423,13 +423,37 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
let i = self.active_tab;
if let Some(grip) = self.tabs[i].active_grip.clone() {
if grip.mode == GripEditMode::Stretch {
if matches!(grip.mode, GripEditMode::Stretch | GripEditMode::RectangleResize) {
let dyn_locked = self.tabs[i]
.dyn_fields
.iter()
.any(|field| field.buffer.is_some());
let target = if dyn_locked {
let target = if matches!(grip.mode, GripEditMode::RectangleResize) {
grip.rectangle_frame.map(|(opposite, width_axis, height_axis)| {
let cursor_delta = self.tabs[i].last_cursor_world - opposite;
let mut width = cursor_delta.dot(width_axis);
let mut height = cursor_delta.dot(height_axis);
for field in &self.tabs[i].dyn_fields {
let value = field
.buffer
.as_ref()
.and_then(|buffer| crate::app::expr_eval::eval_number(buffer));
if let Some(value) = value {
match field.role {
crate::command::DynRole::Width => {
width = value.abs().copysign(width);
}
crate::command::DynRole::Height => {
height = value.abs().copysign(height);
}
_ => {}
}
}
}
opposite + width_axis * width + height_axis * height
})
} else if dyn_locked {
// Distance only:
// keep the cursor's current direction.
//
@@ -506,10 +530,32 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
}
let delta = target - grip.last_world;
let actions: Vec<_> = grip
.targets
.iter()
.map(|target_grip| {
let actions: Vec<_> = if let Some((opposite, width_axis, height_axis)) = grip.rectangle_frame {
let opposite_id = (grip.grip_id + 2) % 4;
let mut edits = Vec::with_capacity(3);
for adjacent_id in [(opposite_id + 1) % 4, (opposite_id + 3) % 4] {
if let Some(original) = self.tabs[i]
.selected_grip_handles
.iter()
.zip(self.tabs[i].selected_grips.iter())
.find(|(owner, candidate)| **owner == grip.handle && candidate.id == adjacent_id)
.map(|(_, candidate)| candidate.world)
{
let d = original - opposite;
let axis = if d.dot(width_axis).abs() >= d.dot(height_axis).abs() {
width_axis
} else {
height_axis
};
edits.push((grip.handle, adjacent_id, GripApply::Absolute(
opposite + axis * (target - opposite).dot(axis),
)));
}
}
edits.push((grip.handle, grip.grip_id, GripApply::Absolute(target)));
edits
} else {
grip.targets.iter().map(|target_grip| {
let apply = if target_grip.is_translate {
GripApply::Translate(delta)
} else {
@@ -523,8 +569,8 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
target_grip.grip_id,
apply,
)
})
.collect();
}).collect()
};
for (handle, grip_id, apply) in actions {
self.tabs[i]
@@ -1340,6 +1386,7 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
if matches!(
item.action,
GripMenuAction::Stretch
| GripMenuAction::RectangleResize
| GripMenuAction::MoveWithText
| GripMenuAction::MoveWithDimLine
| GripMenuAction::MoveWithLeader
@@ -1397,12 +1444,52 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
|| (!is_dimension && g.is_midpoint),
)
};
self.tabs[i].active_grip = Some(GripEdit::single(
popup.handle,
grip_id,
is_translate,
g.world,
));
if matches!(item.action, GripMenuAction::RectangleResize) {
let corner = |id| {
self.tabs[i]
.selected_grip_handles
.iter()
.zip(self.tabs[i].selected_grips.iter())
.find(|(owner, grip)| **owner == popup.handle && grip.id == id)
.map(|(_, grip)| grip.world)
};
if let (Some(p0), Some(p1), Some(p2), Some(opposite)) = (
corner(0),
corner(1),
corner(2),
corner((popup.grip_id + 2) % 4),
) {
if let (Some(width_axis), Some(height_axis)) =
((p1 - p0).try_normalize(), (p2 - p1).try_normalize())
{
if self.grip_originals.is_empty() {
self.grip_originals = self.tabs[i]
.scene
.document
.get_entity(popup.handle)
.cloned()
.map(|entity| vec![(popup.handle, entity)])
.unwrap_or_default();
}
self.tabs[i].active_grip = Some(GripEdit::rectangle_resize(
popup.handle,
popup.grip_id,
g.world,
opposite,
width_axis,
height_axis,
));
self.sync_dyn_fields();
}
}
} else {
self.tabs[i].active_grip = Some(GripEdit::single(
popup.handle,
grip_id,
is_translate,
g.world,
));
}
}
return Task::none();
}