Angle fields: a decimal point typed into an angle stays (#10582) (#10631)

* Angle fields: a decimal point typed into an angle stays (#10582)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Angle fields: a decimal point typed into an angle stays (#10582)

Edit Canvas applies its Angle box at each keystroke and keeps the angle
in radians, so the box gets back a hair off the value it set; egui's
DragValue takes that for a change made elsewhere and rewrites the text
being typed, dropping a decimal point just typed (-3.7 became -37).
angle_field now hands the DragValue the value it set while the value it
is given is within 1e-9 of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
austin62jake
2026-11-02 00:09:32 +00:00
committed by GitHub
parent da586bc048
commit 5e7f3651fb
2 changed files with 38 additions and 1 deletions
+14 -1
View File
@@ -1311,7 +1311,20 @@ pub(crate) fn bounded_length_field(
/// Angle in degrees, dragged or typed. Tokens: control_height, scope control/font tokens.
pub(crate) fn angle_field(ui: &mut Ui, value: &mut f64) -> Response {
let response = ui.add(egui::DragValue::new(value).speed(1.0).suffix(" deg").custom_parser(crate::prefs::parse_number));
// An owner that keeps the angle in radians gives back the value the field set a hair off
// (-3 deg as -2.9999999999999996). The field takes that for a change made elsewhere and
// rewrites what is being typed from it, which drops a decimal point just typed: "-3." became
// "-3", and the 7 after it made -37 (#10582). It is given the value it set instead.
let set = ui.next_auto_id().with("angle_field_set");
let mut shown = *value;
if let Some(last) = ui.data(|d| d.get_temp::<f64>(set)).filter(|last| (last - shown).abs() <= 1e-9 * last.abs().max(1.0)) {
shown = last;
}
let response = ui.add(egui::DragValue::new(&mut shown).speed(1.0).suffix(" deg").custom_parser(crate::prefs::parse_number));
if response.changed() {
*value = shown;
ui.data_mut(|d| d.insert_temp(set, shown));
}
Tokens::get().input_bevel(ui, &response);
scenario::publish_target(&format!("dialog:angle:{}", label(ui)), response.rect);
response
+24
View File
@@ -614,6 +614,30 @@ fn placement_field_keeps_focus_for_owner_validation_on_enter() {
assert!(value.contains('x'));
}
/// #10582: an angle typed a key at a time keeps its decimal point when its owner keeps it in
/// radians, as Edit Canvas does, and so gives back a hair off the value the field set.
#[test]
fn an_angle_kept_in_radians_takes_a_typed_decimal_point() {
let ctx = crate::fonts::test_context();
let mut radians = 0.0_f64;
let mut draw = |ui: &mut Ui| {
row(ui, "Angle", |ui| {
let mut degrees = radians.to_degrees();
if angle_field(ui, &mut degrees).changed() {
radians = degrees.to_radians();
}
});
};
frame(&ctx, vec![], &mut draw);
let at = scenario::rect_of("dialog:angle:Angle").expect("the angle field").center();
frame(&ctx, pointer(at, true), &mut draw);
frame(&ctx, pointer(at, false), &mut draw);
for typed in ["-", "3", ".", "7"] {
frame(&ctx, vec![egui::Event::Text(typed.into())], &mut draw);
}
assert!((radians.to_degrees() + 3.7).abs() < 1e-9, "typed -3.7, the angle is {}", radians.to_degrees());
}
#[test]
fn bounded_name_editor_keeps_unicode_character_cap() {
let ctx = crate::fonts::test_context();