Use positional ids for sliders
This means two sliders now can use the same label
This commit is contained in:
parent
a35fe7da12
commit
7db71eb875
1 changed files with 3 additions and 7 deletions
|
@ -46,7 +46,6 @@ pub struct Slider<'a> {
|
||||||
text: Option<String>,
|
text: Option<String>,
|
||||||
precision: Option<usize>,
|
precision: Option<usize>,
|
||||||
text_color: Option<Srgba>,
|
text_color: Option<Srgba>,
|
||||||
id: Option<Id>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Slider<'a> {
|
impl<'a> Slider<'a> {
|
||||||
|
@ -65,7 +64,6 @@ impl<'a> Slider<'a> {
|
||||||
text: None,
|
text: None,
|
||||||
precision: None,
|
precision: None,
|
||||||
text_color: None,
|
text_color: None,
|
||||||
id: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +215,7 @@ fn x_range(rect: &Rect) -> RangeInclusive<f32> {
|
||||||
impl<'a> Slider<'a> {
|
impl<'a> Slider<'a> {
|
||||||
/// Just the slider, no text
|
/// Just the slider, no text
|
||||||
fn allocate_slide_space(&self, ui: &mut Ui, height: f32) -> Response {
|
fn allocate_slide_space(&self, ui: &mut Ui, height: f32) -> Response {
|
||||||
let id = self.id.unwrap_or_else(|| ui.make_position_id());
|
let id = ui.make_position_id();
|
||||||
let desired_size = vec2(ui.style().spacing.slider_width, height);
|
let desired_size = vec2(ui.style().spacing.slider_width, height);
|
||||||
let rect = ui.allocate_space(desired_size);
|
let rect = ui.allocate_space(desired_size);
|
||||||
ui.interact(rect, id, Sense::click_and_drag())
|
ui.interact(rect, id, Sense::click_and_drag())
|
||||||
|
@ -285,7 +283,7 @@ impl<'a> Slider<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_ui(&mut self, ui: &mut Ui, x_range: RangeInclusive<f32>) {
|
fn value_ui(&mut self, ui: &mut Ui, x_range: RangeInclusive<f32>) {
|
||||||
let kb_edit_id = self.id.expect("We should have an id by now").with("edit");
|
let kb_edit_id = ui.make_position_id().with("edit");
|
||||||
let is_kb_editing = ui.memory().has_kb_focus(kb_edit_id);
|
let is_kb_editing = ui.memory().has_kb_focus(kb_edit_id);
|
||||||
|
|
||||||
let aim_radius = ui.input().aim_radius();
|
let aim_radius = ui.input().aim_radius();
|
||||||
|
@ -361,9 +359,7 @@ impl<'a> Widget for Slider<'a> {
|
||||||
.line_spacing()
|
.line_spacing()
|
||||||
.at_least(ui.style().spacing.interact_size.y);
|
.at_least(ui.style().spacing.interact_size.y);
|
||||||
|
|
||||||
if let Some(text) = &self.text {
|
if self.text.is_some() {
|
||||||
self.id = self.id.or_else(|| Some(ui.make_unique_child_id(text)));
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let slider_response = self.allocate_slide_space(ui, height);
|
let slider_response = self.allocate_slide_space(ui, height);
|
||||||
self.slider_ui(ui, &slider_response);
|
self.slider_ui(ui, &slider_response);
|
||||||
|
|
Loading…
Reference in a new issue