Skip to content

Commit 265e37f

Browse files
committed
Make gui scrollable
1 parent 0f97f45 commit 265e37f

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

src/gui/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use crate::config::Config;
66
use crate::recording_session::SessionPath;
77
use anyhow::Result;
88
use iced::application::application;
9-
use iced::widget::{button, row};
9+
use iced::widget::{button, row, scrollable};
1010
use iced::{Element, Subscription, Task, Theme};
1111
use log::error;
1212

1313
use self::session_gui::{SessionGui, SessionMessage};
1414
use self::session_selector::SessionSelector;
1515

16+
const SCROLLBAR_WIDTH: f32 = 20.0;
17+
1618
pub struct Gui {
1719
session: Option<SessionGui>,
1820
session_selector: SessionSelector,
@@ -64,15 +66,19 @@ impl Gui {
6466

6567
fn view(&self) -> Element<Message> {
6668
let selector = self.session_selector.view();
67-
let session_view = self
68-
.session
69-
.as_ref()
70-
.map(|session| session.view())
71-
.unwrap_or(row![].into())
72-
.map(|message| Message::SessionMessage(message));
69+
let session_view = scrollable(
70+
self.session
71+
.as_ref()
72+
.map(|session| session.view())
73+
.unwrap_or(row![].into())
74+
.map(|message| Message::SessionMessage(message)),
75+
)
76+
.direction(scrollable::Direction::Vertical(
77+
scrollable::Scrollbar::new().width(SCROLLBAR_WIDTH),
78+
));
7379
let cut_songs =
7480
button("Cut songs").on_press(Message::SessionMessage(SessionMessage::CutSongs));
75-
row![session_view, cut_songs, selector].into()
81+
row![selector, cut_songs, session_view].into()
7682
}
7783

7884
fn subscription(&self) -> Subscription<Message> {

src/gui/session_gui.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,13 @@ use super::plot::{Plot, PlotMarkerMoved};
2020

2121
pub const CANVAS_HEIGHT: f32 = 80.0;
2222

23-
#[derive(Clone, Debug)]
24-
pub enum Direction {
25-
Up,
26-
Down,
27-
}
28-
2923
#[derive(Clone, Debug)]
3024
pub enum SessionMessage {
3125
SetCutPosition(SetCutPosition),
3226
CutSongs,
3327
FinishedCutting(CutInfo),
3428
PlaybackSong,
3529
UpdateProgress(Progress),
36-
Scroll(Direction),
3730
}
3831

3932
#[derive(Clone, Debug)]
@@ -45,14 +38,12 @@ pub struct SetCutPosition {
4538
pub struct SessionGui {
4639
plots: Vec<Plot>,
4740
reader: Mutex<WavFileReader>,
48-
session: RecordingSession,
4941
path: SessionPath,
5042
cuts: Manual,
5143
cutting_state: CuttingState,
5244
playback_state: PlaybackState,
5345
last_touched_song: usize,
5446
playback_index: usize,
55-
scroll_pos: i32,
5647
}
5748

5849
enum CuttingState {
@@ -106,7 +97,6 @@ impl SessionGui {
10697
let cuts = Manual::new(&mut reader, &session.session, DbusLengthsStrategy);
10798
let playback_state = PlaybackState::Waiting;
10899
Ok(Self {
109-
session: session.session,
110100
reader: Mutex::new(reader),
111101
plots,
112102
cuts,
@@ -115,7 +105,6 @@ impl SessionGui {
115105
last_touched_song: 0,
116106
playback_state,
117107
playback_index: 0,
118-
scroll_pos: 0,
119108
})
120109
}
121110

@@ -135,7 +124,6 @@ impl SessionGui {
135124
}
136125
SessionMessage::PlaybackSong => self.playback_song(),
137126
SessionMessage::UpdateProgress(_) => todo!(),
138-
SessionMessage::Scroll(dir) => self.scroll(dir),
139127
}
140128
}
141129

@@ -157,9 +145,11 @@ impl SessionGui {
157145
text(song.to_string_short().to_string()).align_x(Horizontal::Left)
158146
};
159147
let titles = Row::new()
148+
.push(horizontal_space())
160149
.push_maybe(plot.song_before().map(make_title))
161150
.push(horizontal_space())
162-
.push_maybe(plot.song_after().map(make_title));
151+
.push_maybe(plot.song_after().map(make_title))
152+
.push(horizontal_space());
163153
column![titles, canvas].into()
164154
})
165155
.collect();
@@ -193,8 +183,6 @@ impl SessionGui {
193183

194184
match key {
195185
key::Named::Space => Some(SessionMessage::PlaybackSong),
196-
key::Named::ArrowDown => Some(SessionMessage::Scroll(Direction::Down)),
197-
key::Named::ArrowUp => Some(SessionMessage::Scroll(Direction::Up)),
198186
_ => None,
199187
}
200188
})
@@ -232,12 +220,4 @@ impl SessionGui {
232220
fn get_wav_source(&self, info: &PlaybackInfo) -> WavSource {
233221
WavSource::new(&mut self.reader.lock().unwrap(), info.start, info.end)
234222
}
235-
236-
fn scroll(&mut self, dir: Direction) {
237-
self.scroll_pos += match dir {
238-
Direction::Up => 1,
239-
Direction::Down => -1,
240-
};
241-
self.scroll_pos = self.scroll_pos.max(0);
242-
}
243223
}

0 commit comments

Comments
 (0)