Skip to content

Commit

Permalink
Add lookup table
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Jul 25, 2024
1 parent e11b812 commit 94f053e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rawaccel_convert = { git = "https://github.com/Kuuuube/rawaccel_convert.git", rev = "a41c12b20af06f95c1d53286ffd60abc4cb1205b" }
rawaccel_convert = { git = "https://github.com/Kuuuube/rawaccel_convert.git", rev = "2e02357f0c57d5604bc65ee8096160d792bad21b" }
egui = "0.28.1"
eframe = { version = "0.28.1", features = [ "default_fonts", "glow", "persistence" ] }
env_logger = "0.11.3"
Expand Down
66 changes: 65 additions & 1 deletion src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct RawaccelConvertSettings {
pub scale_string: String,
pub exponent_power_string: String,
pub output_offset_string: String,

pub lookup_table_string: String,
}

impl Default for RawaccelConvertSettings {
Expand Down Expand Up @@ -69,6 +71,9 @@ impl Default for RawaccelConvertSettings {
scale_string: "1".to_string(),
exponent_power_string: "0.05".to_string(),
output_offset_string: "0".to_string(),

//lookup
lookup_table_string: "".to_string(),
}
}
}
Expand Down Expand Up @@ -363,6 +368,13 @@ impl eframe::App for RawaccelConvertGui {
add_output_offset(self, ui);
ui.end_row();
}
AccelMode::Lookup => {
add_lookup_table_box(self, ui);
ui.end_row();

add_apply_as(self, ui);
ui.end_row();
}
AccelMode::Noaccel => {}
}
});
Expand All @@ -387,6 +399,12 @@ impl eframe::App for RawaccelConvertGui {
plot.show(ui, |plot_ui| {
let bounds = get_bounds(&plot_accel_args);
plot_ui.set_plot_bounds(egui_plot::PlotBounds::from_min_max(bounds.0, bounds.1));
match plot_accel_args.mode {
AccelMode::Lookup => {
plot_ui.set_auto_bounds(egui::Vec2b { x: false, y: true });
}
_ => {}
}
plot_ui.line(
egui_plot::Line::new(egui_plot::PlotPoints::new(convert_points(plot_points)))
.color(egui::Color32::from_rgb(100, 100, 200))
Expand Down Expand Up @@ -418,6 +436,7 @@ fn get_point(x: f64, args: &AccelArgs) -> f64 {
}
AccelMode::Power => rawaccel_convert::accel_curves::power::power(x, &args),
AccelMode::Motivity => rawaccel_convert::accel_curves::motivity::motivity(x, args),
AccelMode::Lookup => rawaccel_convert::accel_curves::motivity::motivity(x, args),
AccelMode::Noaccel => rawaccel_convert::accel_curves::noaccel::noaccel(x, &args),
};
match args.point_scaling {
Expand All @@ -436,7 +455,7 @@ fn get_point(x: f64, args: &AccelArgs) -> f64 {

fn get_bounds(args: &AccelArgs) -> ([f64; 2], [f64; 2]) {
let plot_min_x = match args.mode {
AccelMode::Power => 0.1,
AccelMode::Power | AccelMode::Lookup => 0.1,
_ => 0.0,
};
let plot_max_x = (args.dpi.clone() / 20) as f64;
Expand Down Expand Up @@ -540,6 +559,11 @@ fn add_curve_type(rawaccel_convert_gui: &mut RawaccelConvertGui, ui: &mut egui::
AccelMode::Motivity,
"Motivity",
);
ui.selectable_value(
&mut rawaccel_convert_gui.accel_args.mode,
AccelMode::Lookup,
"Lookup",
);
});
});
}
Expand Down Expand Up @@ -945,6 +969,46 @@ fn add_output_offset(rawaccel_convert_gui: &mut RawaccelConvertGui, ui: &mut egu
);
}

fn add_lookup_table_box(rawaccel_convert_gui: &mut RawaccelConvertGui, ui: &mut egui::Ui) {
let mut color = ui.visuals().text_color();
match rawaccel_convert::args_parser::parse_lookup_table(
&rawaccel_convert_gui.settings.lookup_table_string,
) {
Some(some) => rawaccel_convert_gui.accel_args.lookup_data = some,
None => {
color = ui.visuals().error_fg_color;
}
}
ui.add_sized(
ui.available_size(),
egui::Label::new(egui::RichText::new("Points").color(color)).selectable(false),
);
ui.add_sized(
ui.available_size(),
egui::TextEdit::singleline(&mut rawaccel_convert_gui.settings.lookup_table_string),
);
}

fn add_apply_as(rawaccel_convert_gui: &mut RawaccelConvertGui, ui: &mut egui::Ui) {
ui.add_sized(
ui.available_size(),
egui::Label::new(egui::RichText::new("Apply As")).selectable(false),
);
ui.push_id("apply_as_dropdown", |ui| {
egui::ComboBox::from_label("")
.selected_text({
match rawaccel_convert_gui.accel_args.gain {
true => "Velocity".to_string(),
false => "Sens".to_string(),
}
})
.show_ui(ui, |ui| {
ui.selectable_value(&mut rawaccel_convert_gui.accel_args.gain, false, "Sens");
ui.selectable_value(&mut rawaccel_convert_gui.accel_args.gain, true, "Velocity");
});
});
}

fn add_points_dump(rawaccel_convert_gui: &mut RawaccelConvertGui, ui: &mut egui::Ui) {
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| {
ui.add_sized(
Expand Down

0 comments on commit 94f053e

Please sign in to comment.