Skip to content

Commit

Permalink
Replace u64seed slider with custom integer field
Browse files Browse the repository at this point in the history
somehow when entering larger values into
the slider widget, it corrected the values
to some other ones. i dont know why this
happens. but i just replaced it with a
crappy string based implementation.
  • Loading branch information
iMilchshake committed Apr 26, 2024
1 parent c78e004 commit a145bea
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use tinyfiledialogs;
const STEPS_PER_FRAME: usize = 50;

use crate::random::Seed;
use crate::{
config::GenerationConfig, generator::Generator, map::Map, position::Position,
};
use crate::{config::GenerationConfig, generator::Generator, map::Map, position::Position};
use egui::{epaint::Shadow, CollapsingHeader, Color32, Frame, Label, Margin, Ui};

use macroquad::camera::{set_camera, Camera2D};
Expand Down Expand Up @@ -95,6 +93,17 @@ pub fn vec_edit_widget<T, F>(
});
}

fn field_edit_integer(ui: &mut egui::Ui, value: &mut u64) -> egui::Response {
let mut int_as_str = format!("{}", value);
let res = ui.text_edit_singleline(&mut int_as_str);
if int_as_str.is_empty() {
*value = 0;
} else if let Ok(result) = int_as_str.parse() {
*value = result;
}
res
}

pub fn field_edit_widget<T, F>(
ui: &mut Ui,
value: &mut T,
Expand Down Expand Up @@ -285,16 +294,16 @@ impl Editor {
.changed()
{
self.user_seed.seed_u64 = Seed::str_to_u64(&self.user_seed.seed_str);
dbg!(&self.user_seed);
}
});

ui.horizontal(|ui| {
ui.label("u64");
if ui
.add(egui::DragValue::new(&mut self.user_seed.seed_u64))
.changed()
{

if field_edit_integer(ui, &mut self.user_seed.seed_u64).changed() {
self.user_seed.seed_str = String::new();
dbg!(&self.user_seed);
}
});

Expand Down

0 comments on commit a145bea

Please sign in to comment.