commit 3d10599858dc3686cda31b95d86572c0a3bfe32d Author: Luke Else Date: Mon Jun 5 22:31:06 2023 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24801c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# ---> VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# ---> Rust +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..de33542 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,45 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'egui-template'", + "cargo": { + "args": [ + "build", + "--bin=egui-template", + "--package=egui-template" + ], + "filter": { + "name": "egui-template", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'egui-template'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=egui-template", + "--package=egui-template" + ], + "filter": { + "name": "egui-template", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5412671 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "egui-template" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +egui = "0.22.0" +eframe = "0.22.0" +tracing-subscriber = "0.3.16" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5356532 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# egui-template + +Template repo for an egui application in rust \ No newline at end of file diff --git a/src/app/mod.rs b/src/app/mod.rs new file mode 100644 index 0000000..cdf8c70 --- /dev/null +++ b/src/app/mod.rs @@ -0,0 +1,15 @@ +mod ui; + +/// Stuct to store the state of the running application +pub struct App { + name: String +} + +impl Default for App { + /// Creates the default startup state for the app; + fn default() -> Self { + Self { + name: String::from("Hello, World!") + } + } +} \ No newline at end of file diff --git a/src/app/ui/mod.rs b/src/app/ui/mod.rs new file mode 100644 index 0000000..d9b386d --- /dev/null +++ b/src/app/ui/mod.rs @@ -0,0 +1,26 @@ +use crate::app::App; +use crate::theme::onedark::ONE_DARK; + +impl eframe::App for App { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + let background_frame = egui::Frame::default().fill(ONE_DARK.bg); + + egui::CentralPanel::default() + .frame(background_frame) + .show(ctx, |ui| { + 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)); + } + } + ); + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..2487267 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,23 @@ +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +mod theme; +mod app; +use app::App; + +fn main() -> Result<(), eframe::Error> { + // Log to stdout (if you run with `RUST_LOG=debug`). + tracing_subscriber::fmt::init(); + + // Setup the options for the default window + let options = eframe::NativeOptions { + initial_window_size: Some(egui::vec2(300.0, 200.0)), + resizable: true, + ..Default::default() + }; + + //Start rendering and run the application + eframe::run_native( + "egui-template", + options, + Box::new(|_cc| Box::new(App::default())), + ) +} \ No newline at end of file diff --git a/src/theme/mod.rs b/src/theme/mod.rs new file mode 100644 index 0000000..9e3a2b1 --- /dev/null +++ b/src/theme/mod.rs @@ -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 +} \ No newline at end of file diff --git a/src/theme/onedark.rs b/src/theme/onedark.rs new file mode 100644 index 0000000..f4a6b3a --- /dev/null +++ b/src/theme/onedark.rs @@ -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 +}; \ No newline at end of file