Browse Source

[slider] show value with monospace font

pull/20/head
Emil Ernerfeldt 4 years ago
parent
commit
1874f238eb
  1. 15
      egui/src/widgets/slider.rs

15
egui/src/widgets/slider.rs

@ -185,9 +185,20 @@ impl<'a> Slider<'a> {
let aim_radius = ui.input().aim_radius(); let aim_radius = ui.input().aim_radius();
let value_text = self.format_value(aim_radius, x_range); let value_text = self.format_value(aim_radius, x_range);
let label_text = self.text.as_deref().unwrap_or_default(); let label_text = self.text.as_deref().unwrap_or_default();
let text = format!("{}: {}", label_text, value_text); let label_text = format!("{}: ", label_text);
let text_color = self.text_color.unwrap_or_else(|| ui.style().text_color); let text_color = self.text_color.unwrap_or_else(|| ui.style().text_color);
ui.add(Label::new(text).multiline(false).text_color(text_color)); ui.style_mut().item_spacing.x = 0.0;
ui.add(
Label::new(label_text)
.multiline(false)
.text_color(text_color),
);
ui.add(
Label::new(value_text)
.multiline(false)
.text_color(text_color)
.text_style(TextStyle::Monospace),
);
} }
fn format_value(&mut self, aim_radius: f32, x_range: RangeInclusive<f32>) -> String { fn format_value(&mut self, aim_radius: f32, x_range: RangeInclusive<f32>) -> String {

Loading…
Cancel
Save