[slider] show value with monospace font

This commit is contained in:
Emil Ernerfeldt 2020-08-28 00:24:51 +02:00
parent ec1e8b9966
commit 1874f238eb

View file

@ -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 {