make initial score also behave positive

This commit is contained in:
Alexander Mohr 2025-04-23 22:21:35 +02:00
parent 12dc85e928
commit e18684e8a4
3 changed files with 11 additions and 10 deletions

View file

@ -315,7 +315,6 @@ pub struct Config {
// #[serde(default = "default_text_wrap_length")]
// #[clap(long = "text-wrap-length")]
// pub text_wrap_length: Option<usize>,
/// Defines how long it takes for the show animation to finish
/// Defaults to 70ms
#[serde(default = "default_show_animation_time")]

View file

@ -14,8 +14,8 @@ use gdk4::prelude::{Cast, DisplayExt, MonitorExt};
use gdk4::{Display, Key};
use gtk4::glib::ControlFlow;
use gtk4::prelude::{
ApplicationExt, ApplicationExtManual, BoxExt, EditableExt, FlowBoxChildExt,
GestureSingleExt, GtkWindowExt, ListBoxRowExt, NativeExt, WidgetExt,
ApplicationExt, ApplicationExtManual, BoxExt, EditableExt, FlowBoxChildExt, GestureSingleExt,
GtkWindowExt, ListBoxRowExt, NativeExt, WidgetExt,
};
use gtk4::{
Align, EventControllerKey, Expander, FlowBox, FlowBoxChild, GestureClick, Image, Label,
@ -463,7 +463,7 @@ fn sort_menu_items_by_score<T: std::clone::Clone>(
} else {
Ordering::Larger
}
} else if menu1.initial_sort_score < menu2.initial_sort_score {
} else if menu1.initial_sort_score > menu2.initial_sort_score {
Ordering::Smaller
} else {
Ordering::Larger
@ -527,7 +527,6 @@ fn ease_in_out_cubic(t: f32) -> f32 {
}
}
fn animate_window<Func>(
window: ApplicationWindow,
animation_time: u64,
@ -820,7 +819,7 @@ fn set_menu_visibility_for_search<T: Clone>(
if query.is_empty() {
for menu_item in items.iter_mut() {
// todo make initial score and search score both follow same logic.
menu_item.search_sort_score = -menu_item.initial_sort_score as f64;
menu_item.search_sort_score = menu_item.initial_sort_score as f64;
menu_item.visible = true;
}
} else {
@ -877,7 +876,7 @@ fn set_menu_visibility_for_search<T: Clone>(
// todo turn initial score init f64
menu_item.search_sort_score =
search_sort_score - menu_item.initial_sort_score as f64;
search_sort_score + menu_item.initial_sort_score as f64;
menu_item.visible = visible;
}
}
@ -921,13 +920,16 @@ fn percent_or_absolute(value: Option<&String>, base_value: i32) -> Option<i32> {
pub fn sort_menu_items_alphabetically_honor_initial_score<T: std::clone::Clone>(
items: &mut [MenuItem<T>],
) {
let mut regular_score = items.len() as i64;
let special_score = items.len() as i64;
let mut regular_score = 0;
items.sort_by(|l, r| l.label.cmp(&r.label));
for item in items.iter_mut() {
if item.initial_sort_score == 0 {
item.initial_sort_score = regular_score;
item.initial_sort_score += regular_score;
regular_score += 1;
} else {
item.initial_sort_score += special_score;
}
}
}

View file

@ -112,7 +112,7 @@ impl<T: Clone> DRunProvider<T> {
action,
sub_elements: Vec::default(),
working_dir: working_dir.clone(),
initial_sort_score: -(*sort_score),
initial_sort_score: *sort_score,
search_sort_score: 0.0,
data: Some(menu_item_data.clone()),
visible: true,