Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migration from rstk to afrish #80

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ rhai = ["afrim/rhai"]
afrim = { version = "0.6.0", default-features = false, git = "https://github.com/pythonbrad/afrim", rev = "5f40469" }
anyhow = "1.0.82"
clap = "4.5.4"
rstk = "0.3.0"
afrish = { version = "0.1.0", default-features = false, git = "https://github.com/fodydev/afrish", rev = "e8c4fa2" }
serde = { version = "1.0.197", features = ["serde_derive"] }
toml = "0.8.12"
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ mod window;

use afrim::frontend::{Command, Frontend};
use anyhow::{anyhow, Result};
use rstk::*;
use afrish::*;
use std::sync::{
mpsc::{Receiver, Sender},
OnceLock,
};
use std::thread;
use window::{rstk_ext::init_rstk_ext, toolkit::ToolKit, tooltip::ToolTip};
use window::{toolkit::ToolKit, tooltip::ToolTip};

pub use config::Config;

pub struct Wish {
window: &'static rstk::TkTopLevel,
window: &'static afrish::TkTopLevel,
tooltip: ToolTip,
toolkit: ToolKit,
tx: Option<Sender<Command>>,
rx: Option<Receiver<Command>>,
}

impl Wish {
fn init() -> &'static rstk::TkTopLevel {
static WISH: OnceLock<rstk::TkTopLevel> = OnceLock::new();
fn init() -> &'static afrish::TkTopLevel {
static WISH: OnceLock<afrish::TkTopLevel> = OnceLock::new();
WISH.get_or_init(|| {
let wish = if cfg!(debug_assertions) {
rstk::trace_with("wish").unwrap()
afrish::trace_with("wish").unwrap()
} else {
rstk::start_wish().unwrap()
afrish::start_wish().unwrap()
};

// The default behavior is to close the window.
Expand All @@ -39,8 +39,6 @@ impl Wish {
// Note that, this close button is on the title bar.
wish.on_close(Self::kill);

init_rstk_ext();

wish
})
}
Expand All @@ -60,7 +58,7 @@ impl Wish {
}

pub fn raise_error<T: std::fmt::Debug>(message: &str, detail: T) {
rstk::message_box()
afrish::message_box()
.parent(Self::init())
.icon(IconImage::Error)
.title("Unexpected Error")
Expand All @@ -71,15 +69,15 @@ impl Wish {
}

fn build(&mut self) {
self.tooltip.build(rstk::make_toplevel(self.window));
self.tooltip.build(afrish::make_toplevel(self.window));
self.toolkit.build(self.window.to_owned());
}

/// End the process (wish and rust).
///
/// Note that a `process::exit` is called internally.
pub fn kill() {
rstk::end_wish();
afrish::end_wish();
}
}

Expand All @@ -97,7 +95,7 @@ impl Frontend for Wish {
}

// We shouldn't forget to listen for GUI events.
thread::spawn(rstk::mainloop);
thread::spawn(afrish::mainloop);

let tx = self.tx.as_ref().unwrap();

Expand Down
1 change: 0 additions & 1 deletion src/window/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod rstk_ext;
pub mod toolkit;
pub mod tooltip;

Expand Down
67 changes: 0 additions & 67 deletions src/window/rstk_ext.rs

This file was deleted.

35 changes: 17 additions & 18 deletions src/window/toolkit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::config::Config;
use super::rstk_ext::*;
use rstk::*;
use afrish::*;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

Expand All @@ -10,8 +9,8 @@ const GUI_RATIO: f64 = 0.8;
#[derive(Clone, Default)]
pub struct ToolKit {
themes: HashMap<&'static str, Style>,
window: Option<rstk::TkTopLevel>,
idle_state_widget: Option<rstk::TkButton>,
window: Option<afrish::TkTopLevel>,
idle_state_widget: Option<afrish::TkButton>,
new_idle_state: Arc<Mutex<bool>>,
curr_idle_state: bool,
config: Config,
Expand Down Expand Up @@ -108,15 +107,15 @@ impl ToolKit {
);

// Header
let frame = rstk::make_frame(window);
let frame = afrish::make_frame(window);
frame.style(&self.themes["TFrame"]);
// Header label
let label = rstk::make_label(&frame);
let label = afrish::make_label(&frame);
label.text("AFRIM Toolkit");
label.style(&self.themes["TLabel"]);
label.pack().side(PackSide::Left).layout();
// Header idle state button
let button = rstk::make_button(&frame);
let button = afrish::make_button(&frame);
button.text("State");
{
let idle_state = Arc::clone(&self.new_idle_state);
Expand All @@ -141,12 +140,12 @@ impl ToolKit {
.layout();

// Separator
rstk::make_frame(window)
afrish::make_frame(window)
.pack()
.fill(PackFill::X)
.padx((30.0 * GUI_RATIO) as u64)
.layout();
let frame = rstk::make_frame(window);
let frame = afrish::make_frame(window);
frame.style(&self.themes["TFrame"]);
frame
.pack()
Expand All @@ -155,23 +154,23 @@ impl ToolKit {
.layout();

// Body
let notebook = rstk::make_notebook(window);
let notebook = afrish::make_notebook(window);
notebook.style(&self.themes["TNotebook"]);

// Page builder
macro_rules! make_page {
( $tabname: expr, $($fieldname: expr => $fieldvalue: expr => $see_more: stmt)*) => {
let frame = rstk::make_frame(window);
let frame = afrish::make_frame(window);
frame.style(&self.themes["TFrame"]);

$(
let subframe = rstk::make_frame(&frame);
let subframe = afrish::make_frame(&frame);
subframe.style(&self.themes["TFrame"]);
let label = rstk::make_label(&subframe);
let label = afrish::make_label(&subframe);
label.text($fieldname);
label.style(&self.themes["TLabel"]);
label.pack().side(PackSide::Left).layout();
let button = rstk::make_button(&subframe);
let button = afrish::make_button(&subframe);
button.text($fieldvalue);
button.width((25.0 * GUI_RATIO) as i64);
button.style(&self.themes["TButton"]);
Expand Down Expand Up @@ -204,7 +203,7 @@ impl ToolKit {
let config_version = info.version.clone();

move || {
rstk::message_box()
afrish::message_box()
.parent(&window)
.icon(IconImage::Information)
.title("Configuration file")
Expand All @@ -230,7 +229,7 @@ impl ToolKit {
let window = window.clone();

move || {
rstk::message_box()
afrish::message_box()
.parent(&window)
.icon(IconImage::Information)
.title("Keyboard shortcuts")
Expand All @@ -250,7 +249,7 @@ impl ToolKit {
let window = window.clone();

move || {
rstk::message_box()
afrish::message_box()
.parent(&window)
.icon(IconImage::Information)
.title("About")
Expand Down Expand Up @@ -283,7 +282,7 @@ impl ToolKit {
.layout();
}

pub fn build(&mut self, window: rstk::TkTopLevel) {
pub fn build(&mut self, window: afrish::TkTopLevel) {
self.window = Some(window);
self.build_theme();
self.build_window();
Expand Down
15 changes: 7 additions & 8 deletions src/window/tooltip.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use super::config::Theme;
use super::rstk_ext::*;
use afrim::frontend::Predicate;
use rstk::*;
use afrish::*;
use std::collections::HashMap;

#[derive(Clone, Default)]
pub struct ToolTip {
themes: HashMap<&'static str, Style>,
window: Option<rstk::TkTopLevel>,
cursor_widget: Option<rstk::TkLabel>,
predicates_widget: Option<rstk::TkLabel>,
window: Option<afrish::TkTopLevel>,
cursor_widget: Option<afrish::TkLabel>,
predicates_widget: Option<afrish::TkLabel>,
predicates: Vec<Predicate>,
current_predicate_id: usize,
page_size: usize,
Expand Down Expand Up @@ -61,20 +60,20 @@ impl ToolTip {
window.deiconify();

// Cursor
let cursor_widget = rstk::make_label(window);
let cursor_widget = afrish::make_label(window);
cursor_widget.text("Afrim is ready for input!");
cursor_widget.style(&self.themes["PHLabel"]);
cursor_widget.pack().fill(PackFill::X).layout();
self.cursor_widget = Some(cursor_widget);

// Predication
let predicates_widget = rstk::make_label(window);
let predicates_widget = afrish::make_label(window);
predicates_widget.style(&self.themes["PBLabel"]);
predicates_widget.pack().fill(PackFill::X).layout();
self.predicates_widget = Some(predicates_widget);
}

pub fn build(&mut self, window: rstk::TkTopLevel) {
pub fn build(&mut self, window: afrish::TkTopLevel) {
self.window = Some(window);
self.build_theme();
self.build_window();
Expand Down
Loading