Angles: typing into a negative angle's degrees replaces its minus sign (#3367)

The degrees field of an angle (Rotation, an effect's angle) showed the
remainder's size, with the minus sign painted beside it, and a typed
number was taken as a size that kept the sign: 50 typed into 0x-20.0
gave -50. The minus sign is now part of the degrees' text, so it is
selected with the rest when typing starts, and a typed number is the
new remainder with its sign: 50 gives +50, -50 gives -50. A positive
remainder still shows its + beside the field.

Fixes #3367
This commit is contained in:
Zinadin Zidan committed 2026-11-14 22:18:48 +06:00
1 parent 53576d2232
commit 02e304a19b
2 files changed
+36 -12

No files matched your search

+14 -12
View File
@@ -41,15 +41,15 @@ pub fn parse_angle(s: &str) -> Option<f64> {
s.parse().ok()
}
/// The angle after the degrees field of `v` (which shows `shown`, the remainder's size) went to
/// The angle after the degrees field of `v` (which shows `shown`, the signed remainder) went to
/// `new`. A drag moves the angle by the pointer's distance, so it runs through zero into negative
/// angles; a typed number is a size, so the remainder keeps its sign.
/// angles; a typed number is the new remainder, its sign included (#3367).
fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 {
if dragging {
return v + (new - shown);
}
let (rev, deg) = split_angle(v);
rev as f64 * 360.0 + if deg < 0.0 || (deg == 0.0 && v < 0.0) { -new } else { new }
let (rev, _) = split_angle(v);
rev as f64 * 360.0 + new
}
/// An angle value, `0x+45.0°`, at `at` (top left): the revolutions and the degrees
@@ -58,13 +58,14 @@ fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 {
pub fn angle_field(ui: &mut egui::Ui, at: Pos2, id: egui::Id, v: f64, decimals: usize, t: &Tokens) -> (Rect, Rect, Option<f64>) {
let (rev, deg) = split_angle(v);
let (rr, new_rev, _) = widgets::hot_int_at(ui, at, id.with("rev"), rev, 0.1, "x", t);
let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "-" } else { "+" }, Tokens::ui(12.0), t.hot_text);
// A negative remainder's minus sign is part of the degrees' text, so typing replaces it (#3367).
let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "" } else { "+" }, Tokens::ui(12.0), t.hot_text);
let (dr, new_deg, _) =
widgets::hot_number_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg.abs(), &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t);
widgets::hot_number_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg, &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t);
let dragging = new_deg.is_some() && ui.ctx().is_being_dragged(id);
let out = match (new_rev, new_deg) {
(Some(r), _) => Some(r as f64 * 360.0 + deg),
(None, Some(d)) => Some(degrees_edit(v, deg.abs(), d, dragging)),
(None, Some(d)) => Some(degrees_edit(v, deg, d, dragging)),
(None, None) => None,
};
(rr, dr, out)
@@ -624,18 +625,19 @@ mod tests {
#[test]
fn dragging_degrees_crosses_zero_into_negative_angles() {
// The field shows the size (0.3), so a 1-degree drag left lands on -0.7, and keeps going.
// A 1-degree drag left from 0.3 lands on -0.7, and keeps going.
let mut v = 0.3;
for _ in 0..3 {
let (_, deg) = split_angle(v);
v = degrees_edit(v, deg.abs(), deg.abs() - 1.0, true);
v = degrees_edit(v, deg, deg - 1.0, true);
}
assert!((v + 2.7).abs() < 1e-9, "{v}");
// And back up through zero.
let (_, deg) = split_angle(v);
assert!((degrees_edit(v, deg.abs(), deg.abs() + 3.0, true) - 0.3).abs() < 1e-9);
// Typing keeps the sign shown.
assert_eq!(degrees_edit(-30.0, 30.0, 45.0, false), -45.0);
assert!((degrees_edit(v, deg, deg + 3.0, true) - 0.3).abs() < 1e-9);
// A typed number is the remainder with its sign; the revolutions stay (#3367).
assert_eq!(degrees_edit(-30.0, -30.0, 45.0, false), 45.0);
assert_eq!(degrees_edit(-30.0, -30.0, -45.0, false), -45.0);
assert_eq!(degrees_edit(405.0, 45.0, 10.0, false), 370.0);
}
+22
View File
@@ -191,3 +191,25 @@ fn commit_edits(click_away: bool) {
}
}
}
/// #3367: on a negative angle the minus sign is part of the degrees typing replaces, so typing
/// 50 into `0x-20.0°` sets +50°. It used to keep the sign (-50°). Committing the text as it
/// opened keeps the angle.
#[test]
fn typing_into_a_negative_angle_replaces_its_sign() {
for panel in [Panel::EffectControls, Panel::Timeline, Panel::Properties] {
for (start, text, expected) in
[(-20.0, Some("50"), 50.0), (-20.0, Some("-50"), -50.0), (-20.0, None, -20.0), (-400.0, None, -400.0), (45.0, Some("-30"), -30.0)]
{
let (mut h, layer, uid) = harness(panel, start);
let p = component(&h, panel, uid, false);
click(&mut h, p);
if let Some(text) = text {
h.input_mut().events.push(Event::Text(text.into()));
h.step();
}
key(&mut h, Key::Enter, Modifiers::NONE);
assert_eq!(angle(&h, layer, uid), expected, "{panel:?}: {start} then {text:?}");
}
}
}