math mode support hex
This commit is contained in:
parent
340b0fbfea
commit
2f03bda3a8
2 changed files with 21 additions and 7 deletions
|
@ -771,9 +771,12 @@ fn build_ui_from_menu_items<T: Clone + 'static + Send>(
|
|||
let meta_clone = Rc::<MetaData<T>>::clone(meta);
|
||||
let ui_clone = Rc::<UiElements<T>>::clone(ui);
|
||||
|
||||
|
||||
|
||||
glib::idle_add_local(move || {
|
||||
let mut done = false;
|
||||
{
|
||||
ui_clone.main_box.unset_sort_func();
|
||||
let mut lock = ui_clone.menu_rows.write().unwrap();
|
||||
|
||||
for _ in 0..25 {
|
||||
|
@ -793,14 +796,15 @@ fn build_ui_from_menu_items<T: Clone + 'static + Send>(
|
|||
meta_clone.search_ignored_words.as_ref(),
|
||||
);
|
||||
}
|
||||
let items_sort = ArcMenuMap::clone(&ui_clone.menu_rows);
|
||||
ui_clone.main_box.set_sort_func(move |child1, child2| {
|
||||
sort_flow_box_childs(child1, child2, &items_sort)
|
||||
});
|
||||
|
||||
|
||||
if done {
|
||||
let lock = ui_clone.menu_rows.read().unwrap();
|
||||
let items_sort = ArcMenuMap::clone(&ui_clone.menu_rows);
|
||||
ui_clone.main_box.set_sort_func(move |child1, child2| {
|
||||
sort_flow_box_childs(child1, child2, &items_sort)
|
||||
});
|
||||
|
||||
|
||||
select_first_visible_child(&lock, &ui_clone.main_box);
|
||||
|
||||
log::debug!(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use regex::Regex;
|
||||
use crate::config::Config;
|
||||
use crate::gui;
|
||||
use crate::gui::{ItemProvider, MenuItem};
|
||||
|
@ -21,10 +22,19 @@ impl<T: Clone> MathProvider<T> {
|
|||
}
|
||||
|
||||
impl<T: Clone> ItemProvider<T> for MathProvider<T> {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
fn get_elements(&mut self, search: Option<&str>) -> (bool, Vec<MenuItem<T>>) {
|
||||
if let Some(search_text) = search {
|
||||
let result = match meval::eval_str(search_text) {
|
||||
Ok(result) => result.to_string(),
|
||||
|
||||
let re = Regex::new(r"0x[0-9a-fA-F]+").unwrap();
|
||||
let result = re.replace_all(search_text, |caps: ®ex::Captures| {
|
||||
let hex_str = &caps[0][2..]; // Skip "0x"
|
||||
let decimal = u64::from_str_radix(hex_str, 16).unwrap();
|
||||
decimal.to_string()
|
||||
});
|
||||
|
||||
let result = match meval::eval_str(result) {
|
||||
Ok(result) => format!("{} (0x{:X})", result, result as i64),
|
||||
Err(e) => format!("failed to calculate {e:?}"),
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue