feat: change volume on mousewheel scroll, #112
This commit is contained in:
parent
f74b05160d
commit
94982b4a4a
1 changed files with 34 additions and 0 deletions
34
src/main.rs
34
src/main.rs
|
|
@ -9,6 +9,7 @@ use cosmic::{
|
||||||
event::{self, Event},
|
event::{self, Event},
|
||||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||||
mouse::Event as MouseEvent,
|
mouse::Event as MouseEvent,
|
||||||
|
mouse::ScrollDelta,
|
||||||
subscription::Subscription,
|
subscription::Subscription,
|
||||||
window, Alignment, Background, Border, Color, ContentFit, Length, Limits,
|
window, Alignment, Background, Border, Color, ContentFit, Length, Limits,
|
||||||
},
|
},
|
||||||
|
|
@ -242,6 +243,7 @@ pub enum Message {
|
||||||
Pause,
|
Pause,
|
||||||
Play,
|
Play,
|
||||||
PlayPause,
|
PlayPause,
|
||||||
|
Scrolled(ScrollDelta),
|
||||||
Seek(f64),
|
Seek(f64),
|
||||||
SeekRelative(f64),
|
SeekRelative(f64),
|
||||||
SeekRelease,
|
SeekRelease,
|
||||||
|
|
@ -1143,6 +1145,37 @@ impl Application for App {
|
||||||
self.update_controls(true);
|
self.update_controls(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::Scrolled(delta) => {
|
||||||
|
if let Some(video) = &mut self.video_opt {
|
||||||
|
let mut volume = video.volume();
|
||||||
|
match delta {
|
||||||
|
ScrollDelta::Pixels { x, y } => {
|
||||||
|
if y < 0.0 {
|
||||||
|
// scrolling down, lower volume
|
||||||
|
volume -= 0.0125;
|
||||||
|
} else if y > 0.0 {
|
||||||
|
// scrolling up, increase volume
|
||||||
|
volume += 0.0125;
|
||||||
|
}
|
||||||
|
|
||||||
|
if x > 0.0 {
|
||||||
|
// scrolling left, lower volume
|
||||||
|
volume -= 0.0125;
|
||||||
|
} else if x < 0.0 {
|
||||||
|
// scrolling right, increase volume
|
||||||
|
volume += 0.0125;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[allow(dropping_copy_types)]
|
||||||
|
_ => drop(delta), // placeholder, does nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
if volume >= 0.0 && volume <= 1.0 {
|
||||||
|
video.set_volume(volume);
|
||||||
|
self.update_controls(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::Seek(secs) => {
|
Message::Seek(secs) => {
|
||||||
//TODO: cleanest way to close dropdowns
|
//TODO: cleanest way to close dropdowns
|
||||||
self.dropdown_opt = None;
|
self.dropdown_opt = None;
|
||||||
|
|
@ -1610,6 +1643,7 @@ impl Application for App {
|
||||||
Some(Message::Key(modifiers, key))
|
Some(Message::Key(modifiers, key))
|
||||||
}
|
}
|
||||||
Event::Mouse(MouseEvent::CursorMoved { .. }) => Some(Message::ShowControls),
|
Event::Mouse(MouseEvent::CursorMoved { .. }) => Some(Message::ShowControls),
|
||||||
|
Event::Mouse(MouseEvent::WheelScrolled { delta }) => Some(Message::Scrolled(delta)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}),
|
}),
|
||||||
cosmic_config::config_subscription(
|
cosmic_config::config_subscription(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue