shortcut for saving and zoom is better by default rip

This commit is contained in:
2025-04-13 19:36:55 +02:00
parent 3251523039
commit 8f0b7d872d
2 changed files with 22 additions and 13 deletions

View File

@@ -1,4 +1,8 @@
use eframe::egui::{self}; use ::egui::os;
use eframe::{
egui::{self},
emath::Float,
};
use std::fs::File; use std::fs::File;
use crate::read_and_write; use crate::read_and_write;
@@ -8,6 +12,7 @@ pub struct Omelt {
file_name: String, file_name: String,
text: String, text: String,
file: File, file: File,
save_short: KeyboardShortcut,
} }
impl Omelt { impl Omelt {
@@ -16,6 +21,16 @@ impl Omelt {
file_name: file_name.to_owned(), file_name: file_name.to_owned(),
text: "".to_owned(), text: "".to_owned(),
file: file, file: file,
save_short: KeyboardShortcut::new(
egui::Key::S,
Modifiers {
alt: false,
ctrl: true,
shift: false,
mac_cmd: false,
command: true,
},
),
}; };
out.update_txt(); out.update_txt();
out out
@@ -31,21 +46,16 @@ impl Omelt {
impl eframe::App for Omelt { impl eframe::App for Omelt {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let save = KeyboardShortcut::new(egui::Key::S, Modifiers::CTRL);
ctx.set_zoom_factor(2.0);
ctx.input(|i| { ctx.input(|i| {
//eprintln!("i = {:?}", i); if self.save_short.matches(i) {
if save.matches(i) {
let _ = save_action(&self.text, &mut self.file); let _ = save_action(&self.text, &mut self.file);
println!("save");
} }
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
ui.heading(&self.file_name); ui.heading(&self.file_name);
if ui.add(egui::Button::new("Click me")).clicked() { if ui.add(egui::Button::new("Save")).clicked() {
let _ = self.file.set_len(0); let _ = self.file.set_len(0);
let _ = save_action(&self.text, &mut self.file); let _ = save_action(&self.text, &mut self.file);
eprintln!("self.text = {:?}", self.text);
} }
egui::ScrollArea::vertical().show(ui, |ui| { egui::ScrollArea::vertical().show(ui, |ui| {
//let visible_text = self.text.lines().take(100).collect::<Vec<_>>().join("\n"); //let visible_text = self.text.lines().take(100).collect::<Vec<_>>().join("\n");
@@ -57,6 +67,9 @@ impl eframe::App for Omelt {
}); });
} }
} }
//---------------------ShortCuts-----------------------
use egui::Modifiers; use egui::Modifiers;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -71,6 +84,6 @@ impl KeyboardShortcut {
} }
fn matches(&self, input: &egui::InputState) -> bool { fn matches(&self, input: &egui::InputState) -> bool {
input.key_down(self.key) && input.modifiers == self.modifiers input.key_pressed(self.key) && input.modifiers == self.modifiers
} }
} }

View File

@@ -44,13 +44,9 @@ pub fn save_action(txt: &str, file: &mut File) -> Result<(), std::io::Error> {
file.write_all(string.as_bytes())?; file.write_all(string.as_bytes())?;
let map = tree_to_map(&mut tree, true); let map = tree_to_map(&mut tree, true);
eprintln!("&txt = {:?}", &txt);
let trad = body_to_bin(&txt, map); let trad = body_to_bin(&txt, map);
eprintln!("trad = {:?}", trad);
let trad_bin = string_to_binary(&trad); let trad_bin = string_to_binary(&trad);
eprintln!("trad_bin = {:?}", trad_bin);
let len_body = trad.len() as u32; let len_body = trad.len() as u32;
eprintln!("len_body = {:?}", len_body);
file.write_all(&len_body.to_be_bytes())?; file.write_all(&len_body.to_be_bytes())?;
file.write_all(&trad_bin)?; file.write_all(&trad_bin)?;
Ok(()) Ok(())