Skip to content

Commit ba221ba

Browse files
INCOMPLETE: More improvements to Column View
+ Fixed padding when changing viewport width Still to come: + INCOMPLETE: Fix showing list items when changing viewport width + INCOMPLETE: Scroll wheel to scroll horizontal scrollbar + TODO: Fix size/position of Empty folder view + TODO: Code cleanup
1 parent 4295707 commit ba221ba

3 files changed

Lines changed: 64 additions & 41 deletions

File tree

src/app.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use crate::operation::{
7979
use crate::spawn_detached::spawn_detached;
8080
use crate::tab::{
8181
self, HOVER_DURATION, HeadingOptions, ItemMetadata, Location, SORT_OPTION_FALLBACK,
82-
SearchLocation, Tab,
82+
ScrollDirection, SearchLocation, Tab,
8383
};
8484
use crate::trash::{Trash, TrashExt};
8585
use crate::zoom::{zoom_in_view, zoom_out_view, zoom_to_default};
@@ -434,7 +434,7 @@ pub enum Message {
434434
ReplaceResult(ReplaceResult),
435435
RestoreFromTrash(Option<Entity>),
436436
SaveSortNames,
437-
ScrollTab(i16),
437+
ScrollTab(i16, Option<ScrollDirection>),
438438
SearchActivate,
439439
SearchClear,
440440
SearchInput(String),
@@ -4363,11 +4363,11 @@ impl Application for App {
43634363
return self.operation(Operation::Restore { items: trash_items });
43644364
}
43654365
}
4366-
Message::ScrollTab(scroll_speed) => {
4366+
Message::ScrollTab(scroll_speed, scroll_dir) => {
43674367
let entity = self.tab_model.active();
43684368
return self.update(Message::TabMessage(
43694369
Some(entity),
4370-
tab::Message::ScrollTab(f32::from(scroll_speed) / 10.0),
4370+
tab::Message::ScrollTab(f32::from(scroll_speed) / 10.0, scroll_dir),
43714371
));
43724372
}
43734373
Message::SearchActivate => {
@@ -7084,11 +7084,25 @@ impl Application for App {
70847084
];
70857085

70867086
if let Some(scroll_speed) = self.auto_scroll_speed {
7087-
subscriptions.push(
7088-
iced::time::every(time::Duration::from_millis(10))
7089-
.with(scroll_speed)
7090-
.map(|(scroll_speed, _)| Message::ScrollTab(scroll_speed)),
7091-
);
7087+
let mut scroll_horizontal = false;
7088+
if let Some(tab) = self.tab_model.data::<Tab>(self.tab_model.active()) {
7089+
if tab.config.view == tab::View::Column {
7090+
scroll_horizontal = true;
7091+
}
7092+
}
7093+
if scroll_horizontal {
7094+
subscriptions.push(
7095+
iced::time::every(time::Duration::from_millis(10))
7096+
.with(scroll_speed)
7097+
.map(|(scroll_speed, _)| Message::ScrollTab(scroll_speed, Some(ScrollDirection::Horizontal))),
7098+
);
7099+
} else {
7100+
subscriptions.push(
7101+
iced::time::every(time::Duration::from_millis(10))
7102+
.with(scroll_speed)
7103+
.map(|(scroll_speed, _)| Message::ScrollTab(scroll_speed, Some(ScrollDirection::Vertical))),
7104+
);
7105+
}
70927106
}
70937107

70947108
subscriptions.extend(MOUNTERS.iter().map(|(key, mounter)| {

src/dialog.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::config::{Config, DialogConfig, TIME_CONFIG_ID, ThumbCfg, TimeConfig,
3636
use crate::key_bind::key_binds;
3737
use crate::localize::LANGUAGE_SORTER;
3838
use crate::mounter::{MOUNTERS, MounterItem, MounterItems, MounterKey, MounterMessage};
39-
use crate::tab::{self, ItemMetadata, Location, SearchLocation, Tab};
39+
use crate::tab::{self, ItemMetadata, Location, ScrollDirection, SearchLocation, Tab};
4040
use crate::zoom::{zoom_in_view, zoom_out_view, zoom_to_default};
4141
use crate::{fl, home_dir, menu, mime_icon};
4242

@@ -464,7 +464,7 @@ enum Message {
464464
Open,
465465
Preview,
466466
Save(bool),
467-
ScrollTab(i16),
467+
ScrollTab(i16, Option<ScrollDirection>),
468468
SearchActivate,
469469
SearchClear,
470470
SearchInput(String),
@@ -492,7 +492,7 @@ impl From<AppMessage> for Message {
492492
AppMessage::None => Self::None,
493493
AppMessage::Preview(_entity_opt) => Self::Preview,
494494
AppMessage::SearchActivate => Self::SearchActivate,
495-
AppMessage::ScrollTab(scroll_speed) => Self::ScrollTab(scroll_speed),
495+
AppMessage::ScrollTab(scroll_speed, scroll_dir) => Self::ScrollTab(scroll_speed, scroll_dir),
496496
AppMessage::TabMessage(_entity_opt, tab_message) => Self::TabMessage(tab_message),
497497
AppMessage::TabView(_entity_opt, view) => Self::TabView(view),
498498
AppMessage::ToggleFoldersFirst => Self::ToggleFoldersFirst,
@@ -1716,9 +1716,10 @@ impl Application for App {
17161716
return window::close(self.flags.window_id);
17171717
}
17181718
}
1719-
Message::ScrollTab(scroll_speed) => {
1719+
Message::ScrollTab(scroll_speed, scroll_dir) => {
17201720
return self.update(Message::TabMessage(tab::Message::ScrollTab(
17211721
f32::from(scroll_speed) / 10.0,
1722+
scroll_dir
17221723
)));
17231724
}
17241725
Message::SearchActivate => {
@@ -2196,7 +2197,7 @@ impl Application for App {
21962197
subscriptions.push(
21972198
iced::time::every(time::Duration::from_millis(10))
21982199
.with(scroll_speed)
2199-
.map(|(scroll_speed, _)| Message::ScrollTab(scroll_speed)),
2200+
.map(|(scroll_speed, _)| Message::ScrollTab(scroll_speed, None)),
22002201
);
22012202
}
22022203

src/tab.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ pub enum Message {
18701870
MiddleClick(usize),
18711871
Resize(Rectangle),
18721872
Scroll(Viewport),
1873-
ScrollTab(f32),
1873+
ScrollTab(f32, Option<ScrollDirection>),
18741874
ScrollToFocused,
18751875
SearchContext(Location, SearchContextWrapper),
18761876
SearchReady(bool),
@@ -3000,7 +3000,7 @@ pub fn parse_hidden_file(path: &PathBuf) -> Box<[String]> {
30003000
.collect()
30013001
}
30023002

3003-
#[derive(Clone)]
3003+
#[derive(Debug, Clone)]
30043004
pub enum ScrollDirection {
30053005
Vertical,
30063006
Horizontal,
@@ -4600,13 +4600,21 @@ impl Tab {
46004600
self.scroll_opt = Some(viewport.absolute_offset());
46014601
self.watch_drag = true;
46024602
}
4603-
Message::ScrollTab(scroll_speed) => {
4603+
Message::ScrollTab(scroll_speed, scroll_dir) => {
4604+
let mut scroll_x_speed = 0.0;
4605+
let mut scroll_y_speed = 0.0;
4606+
match scroll_dir {
4607+
Some(ScrollDirection::Horizontal) => { scroll_x_speed = scroll_speed },
4608+
Some(ScrollDirection::Vertical) => { scroll_y_speed = scroll_speed },
4609+
Some(ScrollDirection::Both) => { scroll_y_speed = scroll_speed },
4610+
None => { scroll_y_speed = scroll_speed },
4611+
}
46044612
commands.push(Command::Iced(
46054613
scrollable::scroll_by(
46064614
self.scrollable_id.clone(),
46074615
AbsoluteOffset {
4608-
x: 0.0,
4609-
y: scroll_speed,
4616+
x: scroll_x_speed,
4617+
y: scroll_y_speed,
46104618
},
46114619
)
46124620
.into(),
@@ -6719,7 +6727,7 @@ impl Tab {
67196727
let mut count = 0;
67206728
let mut col = 0;
67216729
let mut row = 0;
6722-
let mut page_row = 0;
6730+
let mut page_col = 0;
67236731
let mut hidden = 0;
67246732
let mut grid_elements = Vec::new();
67256733
for &(i, item) in &items {
@@ -6917,15 +6925,15 @@ impl Tab {
69176925
}
69186926

69196927
count += 1;
6920-
row += 1;
6921-
if row >= page_row + rows {
6922-
row = 0;
6923-
col += 1;
6924-
}
6925-
if col >= cols {
6928+
col += 1;
6929+
if col >= page_col + cols {
69266930
col = 0;
6927-
page_row += rows;
6928-
row = page_row;
6931+
row += 1;
6932+
}
6933+
if row >= rows {
6934+
row = 0;
6935+
page_col += cols;
6936+
col = page_col;
69296937
}
69306938
}
69316939

@@ -6942,34 +6950,34 @@ impl Tab {
69426950

69436951
column = column.push(grid);
69446952

6945-
//TODO: HACK If we don't reach the right of the view, go ahead and add a spacer to do that
6953+
//TODO: HACK If we don't reach the bottom of the view, go ahead and add a spacer to do that
69466954
{
6947-
let mut max_right = 0;
6955+
let mut max_bottom = 0;
69486956
for (_, item) in items {
69496957
if let Some(rect) = item.rect_opt.get() {
6950-
let right = (rect.x + rect.width).ceil() as usize;
6951-
if right > max_right {
6952-
max_right = right;
6958+
let bottom = (rect.y + rect.height).ceil() as usize;
6959+
if bottom > max_bottom {
6960+
max_bottom = bottom;
69536961
}
69546962
}
69556963
}
69566964

6957-
// Cache content width for scroll clamping on next frame
6958-
self.content_width_opt.set(Some(max_right as f32));
6965+
// Cache content height for scroll clamping on next frame
6966+
self.content_height_opt.set(Some(max_bottom as f32));
69596967

69606968
// TODO: Don't have 'magic' number (10) here
6961-
let left_deduct = 10 * (space_xxs as usize);
6969+
let top_deduct = 10 * (space_xxs as usize);
69626970

69636971
self.item_view_size_opt
69646972
.set(self.size_opt.get().map(|s| Size {
6965-
width: s.width - left_deduct as f32,
6966-
height: s.height,
6973+
width: s.width,
6974+
height: s.height - top_deduct as f32,
69676975
}));
69686976

6969-
let spacer_width = width.saturating_sub(max_right + left_deduct);
6970-
if spacer_width > 0 {
6977+
let spacer_height = height.saturating_sub(max_bottom + top_deduct);
6978+
if spacer_height > 0 {
69716979
column = column.push(widget::container(
6972-
space::horizontal().width(Length::Fixed(spacer_width as f32)),
6980+
space::vertical().height(Length::Fixed(spacer_height as f32)),
69736981
));
69746982
}
69756983
}

0 commit comments

Comments
 (0)