Joe232
January 19, 2022, 3:53am
1
I wanted to implement the sliders using egui as you can see in the screenshot.
ui.add(
Slider::new(value, (*min)..=(*max))
.logarithmic(*logarithmic)
.clamp_to_range(*clamp_to_range)
.smart_aim(*smart_aim)
.orientation(orientation)
.text("f64 demo slider"),
);
I was wondering if this is the correct code?
If it compiles and does what you intend, we should assume it is correct.
Joe232
January 19, 2022, 4:51am
4
In regards to Slider::new()
pub fn new<Num: Numeric>(value: &'a mut Num, range: RangeInclusive<Num>) -> Self
What is the Numeric
object?
Slider::new(value, (*min)..=(*max))
What am I passing over here in value
(in terrms of datatype)?
According to source code , it is emath::Numeric
, which is implemented for all primitive number types. Not sure why rustdoc didn't add the link, however - cc @GuillaumeGomez ?
Joe232
January 19, 2022, 5:19am
6
pub trait Numeric: Clone + Copy + PartialEq + PartialOrd + 'static {
const INTEGRAL: bool;
const MIN: Self;
const MAX: Self;
fn to_f64(self) -> f64;
fn from_f64(num: f64) -> Self;
}
Ok so I can see it as a trait, but in this code:
ui.add(
Slider::new(value, 0..=100)
.logarithmic(false)
.clamp_to_range(true)
.smart_aim(true)
.orientation(orientation)
.text("f64 demo slider"),
);
How do I exactly define value
?
Slider::new
requires &mut Num
for some Num: Numeric
. That is, you have to store a mutable numeric value (i32
, u8
, f64
, etc. depending on your needs) somewhere in scope and pass an exclusive reference to it.
Do you have a small test code I can use to see if I can reproduce the issue by any chance?
Joe232
January 19, 2022, 11:53am
9
Cerber-Ursi:
Slider::new
requires &mut Num
for some Num: Numeric
. That is, you have to store a mutable numeric value ( i32
, u8
, f64
, etc. depending on your needs)
How do I declare a Numeric
value?
For example for f32
I can do let value: f32 = 10f32;
So how I would do the same for Numeric
data type?
Joe232
January 19, 2022, 11:53am
10
Are you asking me or @Cerber-Ursi ?
system
Closed
April 19, 2022, 11:54am
11
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.