shortcut for saving and zoom is better by default rip
This commit is contained in:
31
src/gui.rs
31
src/gui.rs
@@ -1,4 +1,8 @@
|
||||
use eframe::egui::{self};
|
||||
use ::egui::os;
|
||||
use eframe::{
|
||||
egui::{self},
|
||||
emath::Float,
|
||||
};
|
||||
use std::fs::File;
|
||||
|
||||
use crate::read_and_write;
|
||||
@@ -8,6 +12,7 @@ pub struct Omelt {
|
||||
file_name: String,
|
||||
text: String,
|
||||
file: File,
|
||||
save_short: KeyboardShortcut,
|
||||
}
|
||||
|
||||
impl Omelt {
|
||||
@@ -16,6 +21,16 @@ impl Omelt {
|
||||
file_name: file_name.to_owned(),
|
||||
text: "".to_owned(),
|
||||
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
|
||||
@@ -31,21 +46,16 @@ impl Omelt {
|
||||
|
||||
impl eframe::App for Omelt {
|
||||
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| {
|
||||
//eprintln!("i = {:?}", i);
|
||||
if save.matches(i) {
|
||||
if self.save_short.matches(i) {
|
||||
let _ = save_action(&self.text, &mut self.file);
|
||||
println!("save");
|
||||
}
|
||||
});
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
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 _ = save_action(&self.text, &mut self.file);
|
||||
eprintln!("self.text = {:?}", self.text);
|
||||
}
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
//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;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -71,6 +84,6 @@ impl KeyboardShortcut {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,13 +44,9 @@ pub fn save_action(txt: &str, file: &mut File) -> Result<(), std::io::Error> {
|
||||
file.write_all(string.as_bytes())?;
|
||||
|
||||
let map = tree_to_map(&mut tree, true);
|
||||
eprintln!("&txt = {:?}", &txt);
|
||||
let trad = body_to_bin(&txt, map);
|
||||
eprintln!("trad = {:?}", trad);
|
||||
let trad_bin = string_to_binary(&trad);
|
||||
eprintln!("trad_bin = {:?}", trad_bin);
|
||||
let len_body = trad.len() as u32;
|
||||
eprintln!("len_body = {:?}", len_body);
|
||||
file.write_all(&len_body.to_be_bytes())?;
|
||||
file.write_all(&trad_bin)?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user