Made the project more moduler and added theming capabilities

This commit is contained in:
Luke Else 2023-06-03 17:50:12 +01:00
parent 37360a24d6
commit 68d2080030
6 changed files with 50 additions and 9 deletions

View File

@ -6,6 +6,6 @@ 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.21.0" egui = "0.22.0"
eframe = "0.21.3" eframe = "0.22.0"
tracing-subscriber = "0.3.16" tracing-subscriber = "0.3.16"

View File

@ -9,7 +9,7 @@ impl Default for App {
/// Creates the default startup state for the app; /// Creates the default startup state for the app;
fn default() -> Self { fn default() -> Self {
Self { Self {
name: "Hello, World!".to_owned() name: String::from("Hello, World!")
} }
} }
} }

View File

@ -1,9 +1,26 @@
use crate::app::App; use crate::app::App;
use crate::theme::onedark::ONE_DARK;
impl eframe::App for App { impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { let background_frame = egui::Frame::default().fill(ONE_DARK.bg);
egui::CentralPanel::default()
.frame(background_frame)
.show(ctx, |ui| {
ui.heading(&self.name); ui.heading(&self.name);
}); });
egui::Window::new("test window")
.collapsible(false)
.auto_sized()
.show(ctx, |ui| {
ui.heading(&self.name);
for _ in 0..10 {
ui.add(egui::Button::new(&self.name));
}
}
);
} }
} }

View File

@ -1,7 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
mod theme;
use eframe::egui;
mod app; mod app;
use app::App; use app::App;
@ -11,8 +9,8 @@ fn main() -> Result<(), eframe::Error> {
// Setup the options for the default window // Setup the options for the default window
let options = eframe::NativeOptions { let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(150.0, 50.0)), initial_window_size: Some(egui::vec2(300.0, 200.0)),
resizable: false, resizable: true,
..Default::default() ..Default::default()
}; };

15
src/theme/mod.rs Normal file
View File

@ -0,0 +1,15 @@
use egui::Color32;
pub mod onedark;
//struct to store the colours used in a theme;
pub struct Theme {
pub bg: Color32,
pub fg: Color32,
pub opt1: Color32,
pub opt2: Color32,
pub opt3: Color32,
pub opt4: Color32,
pub opt5: Color32,
pub opt6: Color32
}

11
src/theme/onedark.rs Normal file
View File

@ -0,0 +1,11 @@
use crate::theme::*;
pub const ONE_DARK: Theme = Theme {
bg: Color32::from_rgb(40, 44, 52), //Dark Grey
fg: Color32::from_rgb(171, 178, 191), //Light Grey
opt1: Color32::from_rgb(224, 108, 117), //Red
opt2: Color32::from_rgb(152, 195, 121), //Green
opt3: Color32::from_rgb(229, 192, 123), //Yellow
opt4: Color32::from_rgb(97, 175, 239), //Blue
opt5: Color32::from_rgb(198, 120, 221), //Purple
opt6: Color32::from_rgb(86, 182, 194) //Turqoise
};