Use WidgetText for the slider's text (#2143)
This commit is contained in:
parent
c414af7aa2
commit
ae5294e63c
1 changed files with 6 additions and 10 deletions
|
@ -76,8 +76,7 @@ pub struct Slider<'a> {
|
||||||
orientation: SliderOrientation,
|
orientation: SliderOrientation,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
suffix: String,
|
suffix: String,
|
||||||
text: String,
|
text: WidgetText,
|
||||||
text_color: Option<Color32>,
|
|
||||||
/// Sets the minimal step of the widget value
|
/// Sets the minimal step of the widget value
|
||||||
step: Option<f64>,
|
step: Option<f64>,
|
||||||
min_decimals: usize,
|
min_decimals: usize,
|
||||||
|
@ -123,7 +122,6 @@ impl<'a> Slider<'a> {
|
||||||
prefix: Default::default(),
|
prefix: Default::default(),
|
||||||
suffix: Default::default(),
|
suffix: Default::default(),
|
||||||
text: Default::default(),
|
text: Default::default(),
|
||||||
text_color: None,
|
|
||||||
step: None,
|
step: None,
|
||||||
min_decimals: 0,
|
min_decimals: 0,
|
||||||
max_decimals: None,
|
max_decimals: None,
|
||||||
|
@ -152,13 +150,13 @@ impl<'a> Slider<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a text next to the slider (e.g. explaining what the slider controls).
|
/// Show a text next to the slider (e.g. explaining what the slider controls).
|
||||||
pub fn text(mut self, text: impl ToString) -> Self {
|
pub fn text(mut self, text: impl Into<WidgetText>) -> Self {
|
||||||
self.text = text.to_string();
|
self.text = text.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_color(mut self, text_color: Color32) -> Self {
|
pub fn text_color(mut self, text_color: Color32) -> Self {
|
||||||
self.text_color = Some(text_color);
|
self.text = self.text.color(text_color);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,9 +728,7 @@ impl<'a> Slider<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.text.is_empty() {
|
if !self.text.is_empty() {
|
||||||
let text_color = self.text_color.unwrap_or_else(|| ui.visuals().text_color());
|
ui.add(Label::new(self.text.clone()).wrap(false));
|
||||||
let text = RichText::new(&self.text).color(text_color);
|
|
||||||
ui.add(Label::new(text).wrap(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response
|
response
|
||||||
|
@ -751,7 +747,7 @@ impl<'a> Widget for Slider<'a> {
|
||||||
let mut response = inner_response.inner | inner_response.response;
|
let mut response = inner_response.inner | inner_response.response;
|
||||||
let value = self.get_value();
|
let value = self.get_value();
|
||||||
response.changed = value != old_value;
|
response.changed = value != old_value;
|
||||||
response.widget_info(|| WidgetInfo::slider(value, &self.text));
|
response.widget_info(|| WidgetInfo::slider(value, self.text.text()));
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue