From ec506c0a4343c220c9ecda9b07b1dfea8d675934 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 22 Aug 2023 15:35:27 +0200 Subject: [PATCH] Use the minus character instead of "dash" (#3271) * Use the minus character instead of "dash" See https://github.com/rerun-io/rerun/issues/3053 * docstring * fix --- crates/egui/src/data/input.rs | 2 +- crates/egui/src/lib.rs | 5 ++++- crates/egui/src/widgets/drag_value.rs | 8 ++++---- crates/egui/src/widgets/slider.rs | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/egui/src/data/input.rs b/crates/egui/src/data/input.rs index ed61aa216e1..bf28a8b00cc 100644 --- a/crates/egui/src/data/input.rs +++ b/crates/egui/src/data/input.rs @@ -788,7 +788,7 @@ impl Key { Key::ArrowLeft => "⏴", Key::ArrowRight => "⏵", Key::ArrowUp => "⏶", - Key::Minus => "-", + Key::Minus => crate::MINUS_CHAR_STR, Key::PlusEquals => "+", _ => self.name(), } diff --git a/crates/egui/src/lib.rs b/crates/egui/src/lib.rs index aab9049b664..924724aa8ae 100644 --- a/crates/egui/src/lib.rs +++ b/crates/egui/src/lib.rs @@ -25,7 +25,7 @@ //! fn ui_counter(ui: &mut egui::Ui, counter: &mut i32) { //! // Put the buttons and label on the same row: //! ui.horizontal(|ui| { -//! if ui.button("-").clicked() { +//! if ui.button("−").clicked() { //! *counter -= 1; //! } //! ui.label(counter.to_string()); @@ -467,6 +467,9 @@ macro_rules! egui_assert { // ---------------------------------------------------------------------------- +/// The minus character: +pub(crate) const MINUS_CHAR_STR: &str = "−"; + /// The default egui fonts supports around 1216 emojis in total. /// Here are some of the most useful: /// ∞⊗⎗⎘⎙⏏⏴⏵⏶⏷ diff --git a/crates/egui/src/widgets/drag_value.rs b/crates/egui/src/widgets/drag_value.rs index 0e1b5460501..5cd01ef06a0 100644 --- a/crates/egui/src/widgets/drag_value.rs +++ b/crates/egui/src/widgets/drag_value.rs @@ -271,7 +271,7 @@ impl<'a> DragValue<'a> { self.custom_formatter(move |n, _| format!("{:0>min_width$b}", n as i64)) } else { self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$b}", n.abs() as i64) }) } @@ -306,7 +306,7 @@ impl<'a> DragValue<'a> { self.custom_formatter(move |n, _| format!("{:0>min_width$o}", n as i64)) } else { self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$o}", n.abs() as i64) }) } @@ -345,11 +345,11 @@ impl<'a> DragValue<'a> { self.custom_formatter(move |n, _| format!("{:0>min_width$x}", n as i64)) } (false, true) => self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$X}", n.abs() as i64) }), (false, false) => self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$x}", n.abs() as i64) }), } diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index f793d86e768..4314498c5e2 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -395,7 +395,7 @@ impl<'a> Slider<'a> { self.custom_formatter(move |n, _| format!("{:0>min_width$b}", n as i64)) } else { self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$b}", n.abs() as i64) }) } @@ -430,7 +430,7 @@ impl<'a> Slider<'a> { self.custom_formatter(move |n, _| format!("{:0>min_width$o}", n as i64)) } else { self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$o}", n.abs() as i64) }) } @@ -469,11 +469,11 @@ impl<'a> Slider<'a> { self.custom_formatter(move |n, _| format!("{:0>min_width$x}", n as i64)) } (false, true) => self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$X}", n.abs() as i64) }), (false, false) => self.custom_formatter(move |n, _| { - let sign = if n < 0.0 { "-" } else { "" }; + let sign = if n < 0.0 { MINUS_CHAR_STR } else { "" }; format!("{sign}{:0>min_width$x}", n.abs() as i64) }), }