Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DragValue panics when min_decimals is set #3065

Closed
YgorSouza opened this issue Jun 8, 2023 · 0 comments · Fixed by #3231
Closed

DragValue panics when min_decimals is set #3065

YgorSouza opened this issue Jun 8, 2023 · 0 comments · Fixed by #3231
Assignees
Labels
bug Something is broken
Milestone

Comments

@YgorSouza
Copy link
Contributor

Describe the bug

Creating a DragValue with min_decimals set to a value greater than 2 without setting max_decimals makes the application panic.

To Reproduce
Steps to reproduce the behavior:

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
    eframe::run_native(
        "My egui App",
        Default::default(),
        Box::new(|_cc| Box::<MyApp>::default()),
    )
}

#[derive(Default)]
struct MyApp {
    value: f64,
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.add(egui::DragValue::new(&mut self.value).min_decimals(3));
        });
    }
}

Expected behavior

The documentation does not say this is not allowed, so it should not panic.

Additional context

  • This is the code that causes the panic:

let auto_decimals = (aim_rad / speed.abs()).log10().ceil().clamp(0.0, 15.0) as usize;
let auto_decimals = auto_decimals + is_slow_speed as usize;
let max_decimals = max_decimals.unwrap_or(auto_decimals + 2);
let auto_decimals = auto_decimals.clamp(min_decimals, max_decimals);

  • It also panics if you set max_decimals less than min_decimals, which is somewhat expected, but also not documented. We could just use at_least and at_most to decide a priority between the two and solve both problems at once.
@YgorSouza YgorSouza added the bug Something is broken label Jun 8, 2023
@emilk emilk added this to the 0.23.0 milestone Aug 10, 2023
@emilk emilk self-assigned this Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants