Add scss colors into rust via build-script, flesh out math evaluation in launcher, Restructure some code

This commit is contained in:
jmb05
2026-11-02 19:31:21 +01:00
parent 11fb03427c
commit c3ad6f38cf
15 changed files with 167 additions and 114 deletions

View File

@@ -10,6 +10,7 @@ use gtk::prelude::{
};
use gtk::{Align, Application, ApplicationWindow, Orientation, PolicyType, gdk};
use gtk4_layer_shell::{Edge, KeyboardMode, Layer, LayerShell};
use jmb_bar::theme;
use jmb_logger_rs::*;
use nucleo_matcher::pattern::{CaseMatching, Normalization, Pattern};
use nucleo_matcher::{Config, Matcher};
@@ -92,20 +93,42 @@ impl RunMenu {
entry.connect_changed(clone!(
#[strong]
content_box,
move |e| {
move |entry| {
while let Some(child) = content_box.first_child() {
content_box.remove(&child);
}
if e.text_length() > 0 {
let text = e.text();
if entry.text_length() > 0 {
let text = entry.text();
if let Some(eval) = text.strip_prefix("=") {
let label = gtk::Label::new(Some(eval));
label.add_css_class("exec-button");
label.set_halign(Align::Start);
label.set_hexpand(true);
content_box.append(&label);
let new_eval = eval.replace("**", "^");
if new_eval != eval {
let cursor = entry.position() as usize;
let removed_before_cursor = text[..cursor].matches("**").count();
let new_cursor = cursor - removed_before_cursor;
glib::idle_add_local_once(clone!(
#[weak]
entry,
move || {
entry.set_text(&format!("={new_eval}"));
entry.set_position(new_cursor as i32);
}
));
}
if let Ok(result) = meval::eval_str(eval) {
let label = gtk::Label::new(Some(&format!("{}", result)));
label.add_css_class("exec-button");
label.set_halign(Align::Start);
label.set_hexpand(true);
content_box.append(&label);
instance_clone.window.set_default_size(500, -1);
}
} else {
instance_clone.list_matching(e, &content_box, &mut matcher_rc.borrow_mut());
instance_clone.list_matching(
entry,
&content_box,
&mut matcher_rc.borrow_mut(),
);
instance_clone.window.set_default_size(500, -1);
}
}
@@ -128,10 +151,17 @@ impl RunMenu {
#[strong]
content_box,
move |_| {
if let Some(child) = content_box.first_child()
&& let Ok(button) = child.downcast::<gtk::Button>()
{
button.activate();
if let Some(child) = content_box.first_child() {
if let Ok(button) = child.clone().downcast::<gtk::Button>() {
button.activate();
} else if let Ok(label) = child.downcast::<gtk::Label>() {
display.clipboard().set_text(&label.text());
label.set_markup(&format!(
"{}<span foreground=\"{}\"><i> - Copied</i></span>",
label.text(),
theme::LIGHTGRAY
));
}
}
}
));