Compare commits
2 Commits
a48220d3d7
...
a13a2e3105
| Author | SHA1 | Date | |
|---|---|---|---|
| a13a2e3105 | |||
| f9cb5ded06 |
48
src/app.rs
48
src/app.rs
@@ -1,25 +1,34 @@
|
||||
use std::{fs::File, io::Write};
|
||||
|
||||
use eframe::egui::{self, Id};
|
||||
use rfd::FileDialog;
|
||||
|
||||
use crate::template::{self, Template};
|
||||
|
||||
pub struct MyEguiApp {
|
||||
pub struct App {
|
||||
templates: Vec<Template>,
|
||||
selected_template: Option<usize>,
|
||||
error_modal: bool,
|
||||
error_value: Option<anyhow_serde::Error>,
|
||||
}
|
||||
|
||||
impl MyEguiApp {
|
||||
impl App {
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
MyEguiApp { templates: Vec::new(), selected_template: None, error_modal: false, error_value: None}
|
||||
Self { templates: Vec::new(), selected_template: None, error_value: None}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyEguiApp {
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Hello, World!");
|
||||
if self.error_value.is_some() {
|
||||
egui::Modal::new(Id::new("Error Box")).show(ui.ctx(), |ui| {
|
||||
ui.heading("An Error Has Occurred");
|
||||
ui.label(format!("{:?}", self.error_value));
|
||||
if ui.button("Okay").clicked() {
|
||||
self.error_value = None;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ui.button("Add Template").clicked() {
|
||||
let file = FileDialog::new().add_filter("text", &["txt"]).set_directory("/").pick_file();
|
||||
@@ -29,22 +38,29 @@ impl eframe::App for MyEguiApp {
|
||||
Ok(templ) => self.templates.push(templ),
|
||||
Err(e) => {
|
||||
self.error_value = Some(e);
|
||||
self.error_modal = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
if self.error_modal {
|
||||
egui::Modal::new(Id::new("Error Box")).show(ui.ctx(), |ui| {
|
||||
ui.heading("An Error Has Occurred");
|
||||
ui.label(format!("{:?}", self.error_value));
|
||||
if ui.button("Okay").clicked() {
|
||||
self.error_modal = false;
|
||||
self.error_value = None;
|
||||
if ui.button("New Template").clicked() {
|
||||
let file = FileDialog::new().add_filter("text", &["txt"]).set_directory("/").save_file();
|
||||
|
||||
if let Some(path) = file {
|
||||
let handle = std::fs::OpenOptions::new().write(true).create(true).truncate(true).open(path);
|
||||
|
||||
match handle {
|
||||
Ok(mut handle) => {
|
||||
let templ = Template::new();
|
||||
let var = ron::ser::to_string(&templ).unwrap();
|
||||
handle.write(var.as_bytes()).unwrap();
|
||||
handle.flush().unwrap();
|
||||
}
|
||||
Err(e) => {
|
||||
self.error_value = Some(e.into())
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let combo_text = match self.selected_template {
|
||||
|
||||
@@ -3,7 +3,7 @@ mod template;
|
||||
|
||||
fn main() {
|
||||
let native_options = eframe::NativeOptions::default();
|
||||
eframe::run_native("test app", native_options, Box::new(|cc| Ok(Box::new(app::MyEguiApp::new(cc)))));
|
||||
eframe::run_native("Bretting Templates", native_options, Box::new(|cc| Ok(Box::new(app::App::new(cc)))));
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
success.txt
Normal file
1
success.txt
Normal file
@@ -0,0 +1 @@
|
||||
(label:"Template",content:[])
|
||||
Reference in New Issue
Block a user