From 129c51791eda7252ecd874f02a6d36ca62df6886 Mon Sep 17 00:00:00 2001 From: Dukantic Date: Sat, 12 Apr 2025 18:27:22 +0200 Subject: [PATCH] change name and work on gui --- Cargo.lock | 18 +++++++++--------- Cargo.toml | 2 +- library/OMELETTE | 1 + src/gui.rs | 22 +++++++--------------- src/main.rs | 11 +++++------ src/node.rs | 14 +++++++++++++- 6 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 library/OMELETTE diff --git a/Cargo.lock b/Cargo.lock index ba6a51c..3075013 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "Omlet" +version = "0.1.0" +dependencies = [ + "eframe", + "egui 0.21.0", + "egui_extras", +] + [[package]] name = "ab_glyph" version = "0.2.29" @@ -2185,15 +2194,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "oeufman" -version = "0.1.0" -dependencies = [ - "eframe", - "egui 0.21.0", - "egui_extras", -] - [[package]] name = "once_cell" version = "1.21.3" diff --git a/Cargo.toml b/Cargo.toml index 635efa5..52dfb45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "oeufman" +name = "Omlet" version = "0.1.0" edition = "2024" diff --git a/library/OMELETTE b/library/OMELETTE new file mode 100644 index 0000000..b8720af --- /dev/null +++ b/library/OMELETTE @@ -0,0 +1 @@ +Omelette diff --git a/src/gui.rs b/src/gui.rs index 481743c..87ad907 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -1,14 +1,12 @@ use eframe::egui; pub struct Omelt { - name: String, - age: u32, + text: String, } impl Default for Omelt { fn default() -> Self { Self { - name: "Arthur".to_owned(), - age: 42, + text: "Test of text.".to_owned(), } } } @@ -16,17 +14,11 @@ impl Default for Omelt { impl eframe::App for Omelt { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { - ui.heading("My egui Application"); - ui.horizontal(|ui| { - let name_label = ui.label("Your name: "); - ui.text_edit_singleline(&mut self.name) - .labelled_by(name_label.id); - }); - ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age")); - if ui.button("Increment").clicked() { - self.age += 1; - } - ui.label(format!("Hello '{}', age {}", self.name, self.age)); + ui.heading("Omelt"); + ui.add_sized( + ui.available_size(), + egui::TextEdit::multiline(&mut self.text).code_editor(), + ); }); } } diff --git a/src/main.rs b/src/main.rs index 39be84a..7bee5ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,7 @@ fn main() -> std::io::Result<()> { after_compression.write_all(string.as_bytes())?; to_compress.seek(SeekFrom::Start(0))?; let map = tree_to_map(&mut tree, true); + eprintln!("map = {:?}", map); let trad = body_to_bin(&mut to_compress, map); let trad_bin = string_to_binary(&trad); let len_body = trad.len() as u32; @@ -69,7 +70,7 @@ fn main() -> std::io::Result<()> { let mut to_print = File::open(f)?; if is_valid_file(&mut to_print) { let untranslate = string_translate(&mut to_print); - eprintln!("untranslate = {}", untranslate); + println!("{}", untranslate); } else { println!("Error oppening file, check type file !") } @@ -110,16 +111,14 @@ fn main() -> std::io::Result<()> { } None => { let options = eframe::NativeOptions { - viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]), + viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]), ..Default::default() }; let _ = eframe::run_native( - "My egui App", + "Omelt", options, - Box::new(|cc| { + Box::new(|_| { // This gives us image support: - egui_extras::install_image_loaders(&cc.egui_ctx); - Ok(Box::::default()) }), ); diff --git a/src/node.rs b/src/node.rs index 3b447eb..f004916 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::collections::VecDeque; +use std::fmt; pub struct Node { pub val: Option, @@ -8,6 +9,15 @@ pub struct Node { pub n: i32, pub path: String, } +impl fmt::Debug for Node { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Node") + .field("Val", &self.val) + .field("n", &self.n) + .field("path", &self.path) + .finish() + } +} impl PartialEq for Node { fn eq(&self, other: &Self) -> bool { self.n == other.n @@ -91,7 +101,9 @@ pub fn create_tree(mut nodes: Vec) -> Node { new_root.insert(l, r); //nodes.push(new_root); match nodes.binary_search(&new_root) { - Ok(_) => {} + Ok(pos) => { + nodes.insert(pos, new_root); + } Err(pos) => { nodes.insert(pos, new_root); }