Functional GUI with eframe
This commit is contained in:
		
					parent
					
						
							
								3280a03a1b
							
						
					
				
			
			
				commit
				
					
						b1c58ce93d
					
				
			
		
					 5 changed files with 2777 additions and 23 deletions
				
			
		
							
								
								
									
										2654
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										2654
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -6,5 +6,5 @@ edition = "2021"
 | 
				
			||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 | 
					# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
egui = "0.16.1"
 | 
					eframe = { version = "*", features = ["screen_reader", "dark-light"] }
 | 
				
			||||||
json = "0.12.4"
 | 
					json = "*"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								src/lib.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/lib.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					pub mod sheet;
 | 
				
			||||||
							
								
								
									
										60
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										60
									
								
								src/main.rs
									
										
									
									
									
								
							| 
						 | 
					@ -1,3 +1,61 @@
 | 
				
			||||||
 | 
					use eframe::egui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn main() {
 | 
					fn main() {
 | 
				
			||||||
    println!("Hello, world!");
 | 
					    let options = eframe::NativeOptions::default();
 | 
				
			||||||
 | 
					    eframe::run_native(
 | 
				
			||||||
 | 
					        "Billy Sheet editor",
 | 
				
			||||||
 | 
					        options,
 | 
				
			||||||
 | 
					        Box::new(|ctx| {
 | 
				
			||||||
 | 
					            ctx.egui_ctx.options().screen_reader = true;
 | 
				
			||||||
 | 
					            Box::new(Gui::default())
 | 
				
			||||||
 | 
					        }),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					struct Gui {
 | 
				
			||||||
 | 
					    test: billy_sheet::sheet::CharacterSheet,
 | 
				
			||||||
 | 
					    edit_mode: bool,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for Gui {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        Self {
 | 
				
			||||||
 | 
					            test: billy_sheet::sheet::CharacterSheet::default(),
 | 
				
			||||||
 | 
					            edit_mode: true,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl eframe::App for Gui {
 | 
				
			||||||
 | 
					    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
 | 
				
			||||||
 | 
					        egui::TopBottomPanel::top("menu").show(ctx, |ui| {
 | 
				
			||||||
 | 
					            egui::menu::bar(ui, |ui| {
 | 
				
			||||||
 | 
					                egui::widgets::global_dark_light_mode_buttons(ui);
 | 
				
			||||||
 | 
					                ui.menu_button("File", |ui| {
 | 
				
			||||||
 | 
					                    if ui.button("Open (Ctrl + O)").clicked() {}
 | 
				
			||||||
 | 
					                    if ui.button("Quit (Ctrl + Q)").clicked() {
 | 
				
			||||||
 | 
					                        _frame.close();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					                if ui.button(format!("Edit mode {}", self.edit_mode)).clicked() {
 | 
				
			||||||
 | 
					                    self.edit_mode = !self.edit_mode;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        egui::CentralPanel::default().show(ctx, |ui| {
 | 
				
			||||||
 | 
					            ui.heading("My egui Application");
 | 
				
			||||||
 | 
					            ui.separator();
 | 
				
			||||||
 | 
					            ui.vertical_centered_justified(|ui| {
 | 
				
			||||||
 | 
					                ui.label("Hello");
 | 
				
			||||||
 | 
					                // ui.text_edit_multiline(self.test.name());
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        if ctx
 | 
				
			||||||
 | 
					            .input_mut()
 | 
				
			||||||
 | 
					            .consume_key(egui::Modifiers::CTRL, egui::Key::Q)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            _frame.close();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										81
									
								
								src/sheet.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								src/sheet.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,81 @@
 | 
				
			||||||
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					pub enum Classe {
 | 
				
			||||||
 | 
					    Warrior,
 | 
				
			||||||
 | 
					    Cautious,
 | 
				
			||||||
 | 
					    Farmer,
 | 
				
			||||||
 | 
					    Resourceful,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					enum CharacteristicType {
 | 
				
			||||||
 | 
					    Address,
 | 
				
			||||||
 | 
					    Stamina,
 | 
				
			||||||
 | 
					    Luck,
 | 
				
			||||||
 | 
					    Skill,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					pub struct CharacterSheet {
 | 
				
			||||||
 | 
					    character_class: Classe,
 | 
				
			||||||
 | 
					    name: String,
 | 
				
			||||||
 | 
					    address: Characteristic,
 | 
				
			||||||
 | 
					    stamina: Characteristic,
 | 
				
			||||||
 | 
					    luck: Characteristic,
 | 
				
			||||||
 | 
					    skill: Characteristic,
 | 
				
			||||||
 | 
					    health: u32,
 | 
				
			||||||
 | 
					    armor: u32,
 | 
				
			||||||
 | 
					    damage: u32,
 | 
				
			||||||
 | 
					    glory: u32,
 | 
				
			||||||
 | 
					    money: u32,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					pub struct Characteristic {
 | 
				
			||||||
 | 
					    characteristic_type: CharacteristicType,
 | 
				
			||||||
 | 
					    pub base: u32,
 | 
				
			||||||
 | 
					    pub carac: u32,
 | 
				
			||||||
 | 
					    pub materiel: u32,
 | 
				
			||||||
 | 
					    pub additional: u32,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for CharacterSheet {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        Self {
 | 
				
			||||||
 | 
					            character_class: Classe::Warrior,
 | 
				
			||||||
 | 
					            name: "Billy".to_string(),
 | 
				
			||||||
 | 
					            address: Characteristic {
 | 
				
			||||||
 | 
					                characteristic_type: CharacteristicType::Address,
 | 
				
			||||||
 | 
					                base: 0,
 | 
				
			||||||
 | 
					                carac: 0,
 | 
				
			||||||
 | 
					                materiel: 0,
 | 
				
			||||||
 | 
					                additional: 1,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            stamina: Characteristic {
 | 
				
			||||||
 | 
					                characteristic_type: CharacteristicType::Stamina,
 | 
				
			||||||
 | 
					                base: 2,
 | 
				
			||||||
 | 
					                carac: 0,
 | 
				
			||||||
 | 
					                materiel: 0,
 | 
				
			||||||
 | 
					                additional: 0,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            luck: Characteristic {
 | 
				
			||||||
 | 
					                characteristic_type: CharacteristicType::Luck,
 | 
				
			||||||
 | 
					                base: 3,
 | 
				
			||||||
 | 
					                carac: 0,
 | 
				
			||||||
 | 
					                materiel: 0,
 | 
				
			||||||
 | 
					                additional: 0,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            skill: Characteristic {
 | 
				
			||||||
 | 
					                characteristic_type: CharacteristicType::Skill,
 | 
				
			||||||
 | 
					                base: 2,
 | 
				
			||||||
 | 
					                carac: 0,
 | 
				
			||||||
 | 
					                materiel: 0,
 | 
				
			||||||
 | 
					                additional: 0,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            health: 0,
 | 
				
			||||||
 | 
					            armor: 0,
 | 
				
			||||||
 | 
					            damage: 0,
 | 
				
			||||||
 | 
					            glory: 0,
 | 
				
			||||||
 | 
					            money: 0,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue