Initial commit

This commit is contained in:
Luke Else 2024-07-27 15:27:10 +00:00
commit 92e13e1c1d
10 changed files with 189 additions and 0 deletions

30
.gitignore vendored Normal file
View File

@ -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

45
.vscode/launch.json vendored Normal file
View File

@ -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}"
}
]
}

11
Cargo.toml Normal file
View File

@ -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.28.1"
eframe = "0.28.1"
tracing-subscriber = "0.3.16"

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
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.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# egui-template
Template repo for an egui application in rust

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

@ -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!")
}
}
}

26
src/app/ui/mod.rs Normal file
View File

@ -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));
}
}
);
}
}

23
src/main.rs Normal file
View File

@ -0,0 +1,23 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
mod app;
mod theme;
use app::App;
use egui::ViewportBuilder;
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 {
viewport: ViewportBuilder::default().with_inner_size(egui::vec2(300.0, 200.0)),
..Default::default()
};
//Start rendering and run the application
eframe::run_native(
"egui-template",
options,
Box::new(|_cc| Ok(Box::new(App::default()))),
)
}

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

@ -0,0 +1,16 @@
use egui::Color32;
pub mod onedark;
//struct to store the colours used in a theme;
#[allow(dead_code)]
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
};