added icon

This commit is contained in:
Penwing 2024-01-21 10:24:16 +01:00
parent 03064225ef
commit 121c1b4a4e
5 changed files with 202 additions and 5 deletions

166
Cargo.lock generated
View file

@ -433,6 +433,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bit_field"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitflags"
version = "1.3.2"
@ -570,6 +576,7 @@ dependencies = [
"egui_code_editor",
"egui_extras",
"env_logger",
"image",
"rfd",
]
@ -770,12 +777,37 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -942,6 +974,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "emath"
version = "0.25.0"
@ -1098,6 +1136,22 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "exr"
version = "1.71.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "832a761f35ab3e6664babfbdc6cef35a4860e816ec3916dcfd0882954e98a8a8"
dependencies = [
"bit_field",
"flume",
"half",
"lebe",
"miniz_oxide",
"rayon-core",
"smallvec",
"zune-inflate",
]
[[package]]
name = "fastrand"
version = "1.9.0"
@ -1132,6 +1186,15 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "flume"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
dependencies = [
"spin",
]
[[package]]
name = "foreign-types"
version = "0.5.0"
@ -1307,6 +1370,16 @@ dependencies = [
"wasi",
]
[[package]]
name = "gif"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045"
dependencies = [
"color_quant",
"weezl",
]
[[package]]
name = "gio-sys"
version = "0.18.1"
@ -1447,6 +1520,15 @@ dependencies = [
"system-deps",
]
[[package]]
name = "half"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0"
dependencies = [
"crunchy",
]
[[package]]
name = "hashbrown"
version = "0.14.3"
@ -1516,8 +1598,13 @@ dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"exr",
"gif",
"jpeg-decoder",
"num-traits",
"png",
"qoi",
"tiff",
]
[[package]]
@ -1592,6 +1679,15 @@ dependencies = [
"libc",
]
[[package]]
name = "jpeg-decoder"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
dependencies = [
"rayon",
]
[[package]]
name = "js-sys"
version = "0.3.67"
@ -1607,6 +1703,12 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "lebe"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]]
name = "libc"
version = "0.2.152"
@ -2079,6 +2181,15 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "qoi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
dependencies = [
"bytemuck",
]
[[package]]
name = "quick-xml"
version = "0.30.0"
@ -2139,6 +2250,26 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544"
[[package]]
name = "rayon"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
@ -2415,6 +2546,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
@ -2516,6 +2656,17 @@ dependencies = [
"syn 2.0.48",
]
[[package]]
name = "tiff"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]
[[package]]
name = "tiny-skia"
version = "0.11.3"
@ -2948,6 +3099,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "weezl"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "winapi"
version = "0.3.9"
@ -3458,6 +3615,15 @@ dependencies = [
"syn 2.0.48",
]
[[package]]
name = "zune-inflate"
version = "0.2.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
dependencies = [
"simd-adler32",
]
[[package]]
name = "zvariant"
version = "3.15.0"

View file

@ -14,4 +14,5 @@ env_logger = { version = "0.10.1", default-features = false, features = [
rfd = "0.12.1"
egui_extras = { version = "0.25.0" }
egui_code_editor = "0.2.3"
image = "0.24.8"
#syntect = "4.6"

BIN
assets/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View file

@ -3,7 +3,7 @@ mod tools;
use eframe::egui;
use egui_code_editor::{CodeEditor, ColorTheme};
use std::{path::Path, path::PathBuf, fs, io, env, cmp::max, cmp::min};
use std::{path::Path, path::PathBuf, fs, io, env, cmp::max, cmp::min, sync::Arc};
const TERMINAL_HEIGHT : f32 = 200.0;
const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
@ -12,11 +12,14 @@ const HISTORY_LENGTH : usize = 2;
fn main() -> Result<(), eframe::Error> {
tools::loaded();
let icon_data = tools::load_icon();
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([1200.0, 800.0])
.with_drag_and_drop(true),
.with_icon(Arc::new(icon_data)),
..Default::default()
};
eframe::run_native(
@ -55,6 +58,7 @@ impl eframe::App for Calcifer {
if let Some(path) = self.save_tab() {
println!("File saved successfully at: {:?}", path);
self.tabs[self.selected_tab.to_n()].path = path;
self.tabs[self.selected_tab.to_n()].saved = true;
} else {
println!("File save failed.");
}
@ -64,6 +68,7 @@ impl eframe::App for Calcifer {
if let Some(path) = self.save_tab_as() {
println!("File saved successfully at: {:?}", path);
self.tabs[self.selected_tab.to_n()].path = path;
self.tabs[self.selected_tab.to_n()].saved = true;
} else {
println!("File save failed.");
}
@ -128,7 +133,7 @@ impl Calcifer {
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.label("");
ui.horizontal(|ui| {
ui.style_mut().visuals.extreme_bg_color = egui::Color32::from_hex("#101010").expect("Could not convert color");
ui.style_mut().visuals.extreme_bg_color = egui::Color32::from_hex(self.theme.bg).expect("Could not convert color");
let Self { command, .. } = self;
ui.label(format!("{}>", env::current_dir().expect("Could not find Shell Environnment").file_name().expect("Could not get Shell Environnment Name").to_string_lossy().to_string()));
let response = ui.add(egui::TextEdit::singleline(command).desired_width(f32::INFINITY).lock_focus(true));
@ -169,14 +174,20 @@ impl Calcifer {
.resizable(false)
.show(ctx, |ui| {
ui.horizontal(|ui| {
ui.style_mut().visuals.selection.bg_fill = egui::Color32::from_hex("#b56524").expect("Could not convert color");
ui.style_mut().visuals.hyperlink_color = egui::Color32::from_hex("#ffad69").expect("Could not convert color");
ui.style_mut().visuals.selection.bg_fill = egui::Color32::from_hex(self.theme.functions).expect("Could not convert color");
ui.style_mut().visuals.hyperlink_color = egui::Color32::from_hex(self.theme.functions).expect("Could not convert color");
for (index, tab) in self.tabs.clone().iter().enumerate() {
let mut title = tab.get_name();
if !tab.saved {
title += " ~";
}
if self.selected_tab == tools::TabNumber::from_n(index) {
ui.style_mut().visuals.override_text_color = Some(egui::Color32::from_hex(self.theme.bg).expect("Could not convert color"));
}
ui.selectable_value(&mut self.selected_tab, tools::TabNumber::from_n(index), title);
ui.style_mut().visuals.override_text_color = None;
if ui.link("X").clicked() {
self.selected_tab = self.delete_tab(index);
}

View file

@ -2,6 +2,7 @@
//use std::io;
use std::{process::Command, cmp::Ordering, env, path::PathBuf};
use egui_code_editor::Syntax;
use eframe::egui::IconData;
//use std::fs;
pub mod themes;
@ -103,6 +104,24 @@ pub fn loaded() {
println!("Tools loaded");
}
pub fn load_icon() -> IconData {
let (icon_rgba, icon_width, icon_height) = {
let icon = include_bytes!("../../assets/icon.png");
let image = image::load_from_memory(icon)
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
(rgba, width, height)
};
IconData {
rgba: icon_rgba,
width: icon_width,
height: icon_height,
}
}
pub fn to_syntax(language : &str) -> Syntax {
match language {