Skip to content

Commit

Permalink
Update to egui 0.24 & new icon
Browse files Browse the repository at this point in the history
Signed-off-by: Visual Ehrmanntraut <[email protected]>
  • Loading branch information
VisualEhrmanntraut committed Nov 27, 2023
1 parent c78861c commit 5711ae9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 49 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ strip = true

[dependencies]
winit = { version = "0.28.7", default-features = true }
eframe = { version = "0.23.0", default-features = false, features = [
eframe = { version = "0.24.0", default-features = false, features = [
"accesskit",
"persistence",
"wgpu",
"wayland",
"x11",
] }
egui = { version = "0.23.0", default-features = false, features = [
egui = { version = "0.24.0", default-features = false, features = [
"persistence",
] }
egui_extras = "0.23.0"
egui_extras = "0.24.0"
hex = "0.4.3"
plist = "1.5.1"
rfd = "0.12.1"
serde = { version = "1.0.189", features = ["derive"] }
egui-modal = "0.2.5"
egui-modal = "0.3.0"

[target.'cfg(target_os = "macos")'.dependencies]
objc = "0.2.7"
Expand Down
56 changes: 21 additions & 35 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Copyright © 2022-2023 ChefKiss Inc. Licensed under the Thou Shalt Not Profit License version 1.5.
//! See LICENSE for details.
use egui::{Align, Layout};
use egui::{Align, Layout, ViewportCommand};
use egui_extras::{Column, TableBuilder};
#[cfg(target_os = "macos")]
use objc::{
Expand Down Expand Up @@ -34,9 +34,6 @@ pub struct PlistOxide {
dialogue: Option<egui_modal::Modal>,
closing: bool,
can_close: bool,
#[serde(skip)]
egui_ctx: egui::Context,
title: String,
}

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -153,8 +150,6 @@ impl PlistOxide {
dialogue: Some(egui_modal::Modal::new(&cc.egui_ctx, "Modal")),
can_close: false,
closing: false,
egui_ctx: cc.egui_ctx.clone(),
title: "Untitled.plist".into(),
})
}

Expand Down Expand Up @@ -188,19 +183,18 @@ impl PlistOxide {
}
}

fn update_title(&mut self, frame: &mut eframe::Frame) {
self.title = format!(
fn update_title(&mut self, ctx: &egui::Context) {
ctx.send_viewport_cmd(ViewportCommand::Title(format!(
"{}{}",
self.path
.as_ref()
.and_then(|v| v.to_str())
.unwrap_or("Untitled.plist"),
if self.unsaved { " *" } else { "" }
);
frame.set_window_title(&self.title);
)));
}

fn save_file(&mut self, frame: &mut eframe::Frame) {
fn save_file(&mut self, ctx: &egui::Context) {
self.path = self.path.clone().or_else(|| {
rfd::FileDialog::new()
.set_file_name("Untitled.plist")
Expand All @@ -213,7 +207,7 @@ impl PlistOxide {
self.error = plist::to_file_xml(path, &self.root).err();
self.unsaved = self.error.is_some();
self.handle_error("saving");
self.update_title(frame);
self.update_title(ctx);
}
}

Expand All @@ -222,16 +216,12 @@ impl eframe::App for PlistOxide {
eframe::set_value(storage, eframe::APP_KEY, self);
}

fn on_close_event(&mut self) -> bool {
if self.unsaved && !self.can_close {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
if ctx.input(|i| i.viewport().close_requested()) && self.unsaved && !self.can_close {
self.closing = true;
self.egui_ctx.request_repaint();
return false;
ctx.send_viewport_cmd(ViewportCommand::CancelClose);
}
true
}

fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
if self.closing {
let dialogue = self.dialogue.as_mut().unwrap();
dialogue.show(|ui| {
Expand All @@ -246,7 +236,7 @@ impl eframe::App for PlistOxide {
dialogue.buttons(ui, |ui| {
if dialogue.caution_button(ui, "Yes").clicked() {
self.can_close = true;
frame.close();
ctx.send_viewport_cmd(ViewportCommand::Close);
}
if dialogue.button(ui, "No").clicked() {
self.closing = false;
Expand All @@ -255,7 +245,7 @@ impl eframe::App for PlistOxide {
});
dialogue.open();
}
let mut new_title = None;

self.open_file.call_once(|| {
let Some(path) = &self.path else {
return;
Expand All @@ -265,14 +255,13 @@ impl eframe::App for PlistOxide {
}
self.root = match plist::from_file(path) {
Ok(v) => {
let title: String = self
.path
.as_ref()
.and_then(|v| v.to_str())
.unwrap_or("Untitled.plist *")
.into();
frame.set_window_title(&title);
new_title = Some(title);
ctx.send_viewport_cmd(ViewportCommand::Title(
self.path
.as_ref()
.and_then(|v| v.to_str())
.unwrap_or("Untitled.plist *")
.into(),
));
self.error = None;
v
}
Expand All @@ -282,9 +271,6 @@ impl eframe::App for PlistOxide {
}
};
});
if let Some(new_title) = new_title {
self.title = new_title;
}

self.handle_error("opening");

Expand Down Expand Up @@ -341,14 +327,14 @@ impl eframe::App for PlistOxide {
#[cfg(not(target_os = "macos"))]
let saving = ctx.input_mut(|v| v.consume_shortcut(&save_shortcut));
if saving {
self.save_file(frame);
self.save_file(ctx);
#[cfg(target_os = "macos")]
Self::saving_file_false();
}

egui::CentralPanel::default().show(ctx, |ui| {
#[cfg(target_os = "macos")]
ui.add_sized((ui.available_width(), 14.0), egui::Label::new(&self.title));
ui.add_space(18.0);

TableBuilder::new(ui)
.striped(true)
Expand All @@ -374,7 +360,7 @@ impl eframe::App for PlistOxide {
crate::widgets::entry::PlistEntry::new(Arc::clone(&self.root), vec![])
.show(&mut body);
self.unsaved |= changed.is_some();
self.update_title(frame);
self.update_title(ctx);
});
});
}
Expand Down
Binary file modified src/app_icon/icon128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/app_icon/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/app_icon/icon256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/app_icon/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/app_icon/icon512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/app_icon/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 12 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use std::path::PathBuf;

use app::PlistOxide;
use eframe::{IconData, NativeOptions};
use eframe::NativeOptions;
use egui::ViewportBuilder;

mod app;
mod style;
Expand All @@ -23,15 +24,16 @@ fn main() {
eframe::run_native(
"Untitled.plist",
NativeOptions {
icon_data: Some(IconData {
rgba: include_bytes!("app_icon/[email protected]").to_vec(),
width: 1024,
height: 1024,
}),
#[cfg(target_os = "macos")]
fullsize_content: true,
drag_and_drop_support: true,
app_id: Some("com.ChefKissInc.PlistOxide".into()),
viewport: ViewportBuilder::default()
.with_icon(
eframe::icon_data::from_png_bytes(include_bytes!(
"app_icon/[email protected]"
))
.unwrap(),
)
.with_fullsize_content_view(true)
.with_titlebar_shown(false)
.with_app_id("com.ChefKissInc.PlistOxide"),
..Default::default()
},
Box::new(|cc| {
Expand Down

0 comments on commit 5711ae9

Please sign in to comment.