chore: apply code formatting
This commit is contained in:
parent
7acda4c007
commit
b332fc6b1c
3 changed files with 42 additions and 22 deletions
|
|
@ -20,8 +20,8 @@ mod mime_app;
|
||||||
pub mod mime_icon;
|
pub mod mime_icon;
|
||||||
mod mounter;
|
mod mounter;
|
||||||
mod mouse_area;
|
mod mouse_area;
|
||||||
mod scroll_area;
|
|
||||||
mod operation;
|
mod operation;
|
||||||
|
mod scroll_area;
|
||||||
mod spawn_detached;
|
mod spawn_detached;
|
||||||
use tab::Location;
|
use tab::Location;
|
||||||
pub mod tab;
|
pub mod tab;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! A container for capturing mouse wheel events.
|
//! A container for reacting to scroll events.
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced_core::{
|
iced_core::{
|
||||||
|
|
@ -14,7 +14,7 @@ use cosmic::{
|
||||||
Element, Renderer, Theme,
|
Element, Renderer, Theme,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Emit messages on mouse wheel events.
|
/// Emit messages on scroll events. Optionally continue propogating scroll events.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct ScrollArea<'a, Message> {
|
pub struct ScrollArea<'a, Message> {
|
||||||
id: Id,
|
id: Id,
|
||||||
|
|
@ -24,7 +24,7 @@ pub struct ScrollArea<'a, Message> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message> ScrollArea<'a, Message> {
|
impl<'a, Message> ScrollArea<'a, Message> {
|
||||||
/// The message to emit on a forward button release.
|
/// The message to emit on a scroll.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn on_scroll(
|
pub fn on_scroll(
|
||||||
mut self,
|
mut self,
|
||||||
|
|
@ -189,8 +189,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes the given [`Event`] and updates the [`State`] of a [`ScrollArea`]
|
/// Processes the given [`Event`] and emit any messages produced by [ScrollArea::on_scroll].
|
||||||
/// accordingly.
|
|
||||||
fn update<Message: Clone>(
|
fn update<Message: Clone>(
|
||||||
widget: &mut ScrollArea<'_, Message>,
|
widget: &mut ScrollArea<'_, Message>,
|
||||||
event: &Event,
|
event: &Event,
|
||||||
|
|
@ -203,15 +202,18 @@ fn update<Message: Clone>(
|
||||||
return event::Status::Ignored;
|
return event::Status::Ignored;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
|
match event {
|
||||||
if let Some(message) = widget.on_scroll.as_ref() {
|
Event::Mouse(mouse::Event::WheelScrolled { delta }) => {
|
||||||
if let Some(msg) = message(Some(delta.clone())) {
|
if let Some(on_scroll) = widget.on_scroll.as_ref() {
|
||||||
shell.publish(msg);
|
if let Some(message) = on_scroll(Some(delta.clone())) {
|
||||||
if !widget.should_propogate_events {
|
shell.publish(message);
|
||||||
return event::Status::Captured;
|
if !widget.should_propogate_events {
|
||||||
|
return event::Status::Captured;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
event::Status::Ignored
|
event::Status::Ignored
|
||||||
|
|
|
||||||
32
src/tab.rs
32
src/tab.rs
|
|
@ -63,7 +63,8 @@ use crate::{
|
||||||
menu,
|
menu,
|
||||||
mime_app::{mime_apps, MimeApp},
|
mime_app::{mime_apps, MimeApp},
|
||||||
mime_icon::{mime_for_path, mime_icon},
|
mime_icon::{mime_for_path, mime_icon},
|
||||||
mouse_area, scroll_area::ScrollArea,
|
mouse_area,
|
||||||
|
scroll_area::ScrollArea,
|
||||||
};
|
};
|
||||||
use unix_permissions_ext::UNIXPermissionsExt;
|
use unix_permissions_ext::UNIXPermissionsExt;
|
||||||
use uzers::{get_group_by_gid, get_user_by_uid};
|
use uzers::{get_group_by_gid, get_user_by_uid};
|
||||||
|
|
@ -3581,7 +3582,9 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn respond_to_scroll_direction(delta: Option<cosmic::iced_core::mouse::ScrollDelta>) -> Option<Message> {
|
fn respond_to_scroll_direction(
|
||||||
|
delta: Option<cosmic::iced_core::mouse::ScrollDelta>,
|
||||||
|
) -> Option<Message> {
|
||||||
let delta_y = match delta {
|
let delta_y = match delta {
|
||||||
Some(cosmic::iced_core::mouse::ScrollDelta::Lines { y, .. }) => y,
|
Some(cosmic::iced_core::mouse::ScrollDelta::Lines { y, .. }) => y,
|
||||||
Some(cosmic::iced_core::mouse::ScrollDelta::Pixels { y, .. }) => y,
|
Some(cosmic::iced_core::mouse::ScrollDelta::Pixels { y, .. }) => y,
|
||||||
|
|
@ -3612,8 +3615,8 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
app::test_utils::{
|
app::test_utils::{
|
||||||
assert_eq_tab_path, assert_scroll_affects_item_zoom, empty_fs, eq_path_item,
|
assert_eq_tab_path, assert_scroll_affects_item_zoom, empty_fs, eq_path_item,
|
||||||
filter_dirs, read_dir_sorted, simple_fs, tab_click_new, NAME_LEN, NUM_DIRS,
|
filter_dirs, read_dir_sorted, simple_fs, tab_click_new, NAME_LEN, NUM_DIRS, NUM_FILES,
|
||||||
NUM_FILES, NUM_HIDDEN, NUM_NESTED,
|
NUM_HIDDEN, NUM_NESTED,
|
||||||
},
|
},
|
||||||
config::{IconSizes, TabConfig},
|
config::{IconSizes, TabConfig},
|
||||||
};
|
};
|
||||||
|
|
@ -3866,7 +3869,12 @@ mod tests {
|
||||||
|
|
||||||
let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default());
|
let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default());
|
||||||
let should_not_zoom = false;
|
let should_not_zoom = false;
|
||||||
assert_scroll_affects_item_zoom(&mut tab, Message::ScrollUp, Modifiers::empty(), should_not_zoom);
|
assert_scroll_affects_item_zoom(
|
||||||
|
&mut tab,
|
||||||
|
Message::ScrollUp,
|
||||||
|
Modifiers::empty(),
|
||||||
|
should_not_zoom,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -3878,7 +3886,12 @@ mod tests {
|
||||||
|
|
||||||
let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default());
|
let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default());
|
||||||
let should_zoom = true;
|
let should_zoom = true;
|
||||||
assert_scroll_affects_item_zoom(&mut tab, Message::ScrollDown, Modifiers::CTRL, should_zoom);
|
assert_scroll_affects_item_zoom(
|
||||||
|
&mut tab,
|
||||||
|
Message::ScrollDown,
|
||||||
|
Modifiers::CTRL,
|
||||||
|
should_zoom,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -3890,7 +3903,12 @@ mod tests {
|
||||||
|
|
||||||
let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default());
|
let mut tab = Tab::new(Location::Path(path.into()), TabConfig::default());
|
||||||
let should_not_zoom = false;
|
let should_not_zoom = false;
|
||||||
assert_scroll_affects_item_zoom(&mut tab, Message::ScrollDown, Modifiers::empty(), should_not_zoom);
|
assert_scroll_affects_item_zoom(
|
||||||
|
&mut tab,
|
||||||
|
Message::ScrollDown,
|
||||||
|
Modifiers::empty(),
|
||||||
|
should_not_zoom,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue