make rollover optional
This commit is contained in:
parent
3d9d5689c7
commit
acfaad5f06
2 changed files with 28 additions and 5 deletions
|
|
@ -637,6 +637,10 @@ pub struct Config {
|
||||||
/// Auto select when only 1 possible choice is left
|
/// Auto select when only 1 possible choice is left
|
||||||
#[clap(long = "auto-select-on-search")]
|
#[clap(long = "auto-select-on-search")]
|
||||||
auto_select_on_search: Option<bool>,
|
auto_select_on_search: Option<bool>,
|
||||||
|
|
||||||
|
/// Jump to the first/last entry when at the end/start and down/up is pressed
|
||||||
|
/// Defaults to true
|
||||||
|
rollover: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
@ -926,6 +930,11 @@ impl Config {
|
||||||
pub fn auto_select_on_search(&self) -> bool {
|
pub fn auto_select_on_search(&self) -> bool {
|
||||||
self.auto_select_on_search.unwrap_or(false)
|
self.auto_select_on_search.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn rollover(&self) -> bool {
|
||||||
|
self.rollover.unwrap_or(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_false() -> bool {
|
fn default_false() -> bool {
|
||||||
|
|
|
||||||
|
|
@ -1083,10 +1083,10 @@ fn handle_key_press<T: Clone + 'static + Send>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gdk4::Key::Up => {
|
gdk4::Key::Up => {
|
||||||
return move_selection(ui, true);
|
return move_selection(ui, meta, &Direction::Up);
|
||||||
}
|
}
|
||||||
gdk4::Key::Down => {
|
gdk4::Key::Down => {
|
||||||
return move_selection(ui, false);
|
return move_selection(ui, meta, &Direction::Down);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(c) = keyboard_key.to_unicode() {
|
if let Some(c) = keyboard_key.to_unicode() {
|
||||||
|
|
@ -1109,7 +1109,21 @@ fn handle_key_press<T: Clone + 'static + Send>(
|
||||||
Propagation::Proceed
|
Propagation::Proceed
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_selection<T: Clone + Send + 'static>(ui: &Rc<UiElements<T>>, up: bool) -> Propagation {
|
#[derive(PartialEq)]
|
||||||
|
enum Direction {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_selection<T: Clone + Send + 'static>(
|
||||||
|
ui: &Rc<UiElements<T>>,
|
||||||
|
meta: &Rc<MetaData<T>>,
|
||||||
|
direction: &Direction,
|
||||||
|
) -> Propagation {
|
||||||
|
if !meta.config.read().unwrap().rollover() {
|
||||||
|
return Propagation::Proceed;
|
||||||
|
}
|
||||||
|
|
||||||
let selected_children = ui.main_box.selected_children();
|
let selected_children = ui.main_box.selected_children();
|
||||||
let Some(selected) = selected_children.first() else {
|
let Some(selected) = selected_children.first() else {
|
||||||
return Propagation::Proceed;
|
return Propagation::Proceed;
|
||||||
|
|
@ -1131,7 +1145,7 @@ fn move_selection<T: Clone + Send + 'static>(ui: &Rc<UiElements<T>>, up: bool) -
|
||||||
return Propagation::Proceed;
|
return Propagation::Proceed;
|
||||||
};
|
};
|
||||||
|
|
||||||
if up && first_child == *selected {
|
if *direction == Direction::Up && first_child == *selected {
|
||||||
select_visible_child(
|
select_visible_child(
|
||||||
&ui.menu_rows.read().unwrap(),
|
&ui.menu_rows.read().unwrap(),
|
||||||
&ui.main_box,
|
&ui.main_box,
|
||||||
|
|
@ -1139,7 +1153,7 @@ fn move_selection<T: Clone + Send + 'static>(ui: &Rc<UiElements<T>>, up: bool) -
|
||||||
&ChildPosition::Back,
|
&ChildPosition::Back,
|
||||||
);
|
);
|
||||||
Propagation::Stop
|
Propagation::Stop
|
||||||
} else if !up && last_child == *selected {
|
} else if *direction == Direction::Down && last_child == *selected {
|
||||||
select_visible_child(
|
select_visible_child(
|
||||||
&ui.menu_rows.read().unwrap(),
|
&ui.menu_rows.read().unwrap(),
|
||||||
&ui.main_box,
|
&ui.main_box,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue