Skip to content

Commit

Permalink
Make timer resolution in ms format
Browse files Browse the repository at this point in the history
  • Loading branch information
Zusier committed Feb 27, 2022
1 parent f45c6ac commit 097cf57
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gameutil-rs/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ mod app_gui {
.build(&mut data.timerresval_label)?;

nwg::TextInput::builder()
.text("5000")
.limit(5)
.text("0.5")
.limit(3)
.parent(&data.window)
.build(&mut data.timerresval)?;

Expand Down Expand Up @@ -113,9 +113,9 @@ mod app_gui {
} else {
sys::taskkill("explorer.exe");
}
if ui.timerresval.text().parse::<u32>().unwrap() != 0 {
if ui.timerresval.text().parse::<f32>().unwrap() != 0.0 {
sys::timerres(
ui.timerresval.text().parse::<u32>().unwrap(),
(ui.timerresval.text().parse::<f32>().unwrap() * 10000.0) as u32,
);
ui.timerresval.set_readonly(true);
}
Expand Down Expand Up @@ -166,18 +166,19 @@ mod app_gui {
#[allow(unused_variables)]
// don't check for incorrect types if input is empty
if !ui.timerresval.text().is_empty() {
if let Err(num) = ui.timerresval.text().parse::<u32>() {
if let Err(num) = ui.timerresval.text().parse::<f32>() {
// warn message
//nwg::modal_info_message(&ui.window, "Error", &format!("{} is not a valid number", ui.timerresval.text()));

// remove last typed character in text input
//ui.timerresval.set_text(&format!("{}", ui.timerresval.text().chars().take(ui.timerresval.text().chars().count() - 1).collect::<String>()));

// filter to only numbers
ui.timerresval.set_text(
&ui.timerresval
.text()
.chars()
.filter(|&c| c.is_numeric())
.filter(|&c| c.is_numeric() || c == '.')
.collect::<String>(),
);
}
Expand Down

0 comments on commit 097cf57

Please sign in to comment.