start gui with exemple
This commit is contained in:
32
src/gui.rs
Normal file
32
src/gui.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use eframe::egui;
|
||||
pub struct MyApp {
|
||||
name: String,
|
||||
age: u32,
|
||||
}
|
||||
|
||||
impl Default for MyApp {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: "Arthur".to_owned(),
|
||||
age: 42,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
21
src/main.rs
21
src/main.rs
@@ -1,13 +1,18 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
use eframe::egui;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{Seek, SeekFrom};
|
||||
|
||||
mod byte_writer;
|
||||
mod gui;
|
||||
mod node;
|
||||
mod read_and_write;
|
||||
|
||||
use byte_writer::{binary_to_string, string_to_binary};
|
||||
use gui::MyApp;
|
||||
use node::{Node, create_tree, nodes_at_vec, read_tree, tree_to_map, tree_to_string};
|
||||
use read_and_write::{body_to_bin, get_map_file, is_valid_file, read_n_bytes};
|
||||
|
||||
@@ -104,8 +109,20 @@ fn main() -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
None => {
|
||||
println!("No argument to deal with !");
|
||||
display_options();
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
|
||||
..Default::default()
|
||||
};
|
||||
let _ = eframe::run_native(
|
||||
"My egui App",
|
||||
options,
|
||||
Box::new(|cc| {
|
||||
// This gives us image support:
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
|
||||
Ok(Box::<MyApp>::default())
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user