Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse Area: add mouse wheel #112

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leb-kuchen
Copy link

No description provided.

@leb-kuchen leb-kuchen marked this pull request as draft March 7, 2024 02:19
@leb-kuchen
Copy link
Author

This would be useful for the sound applet, to enable changing the volume with the mouse wheel. I am not sure about the exact implementation and API. Should there be multiple functions, e.g. for vertical and horizontal scroll or a configurable duration for scrolling, considering touchpads?

@leb-kuchen
Copy link
Author

leb-kuchen commented Mar 7, 2024

I tested it with the example applet. It kinda works on touchpads, but works great with a mouse.

  fn view(&self) -> Element<Self::Message> {
        widget::mouse_area(
            self.core
                .applet
                .icon_button("display-symbolic")
                .on_press(Message::TogglePopup),
        )
        .on_mouse_wheel(|delta| {
            let change = match delta {
                mouse::ScrollDelta::Lines { y, .. } => y * 5.,
                mouse::ScrollDelta::Pixels { y, .. } => y.clamp(-1., 1.) * 5.,
            };
            Message::SoundChange((self.sound_percentage + change as i32).clamp(0, 100))
        })
        .into()
    }
   fn view_window(&self, _id: Id) -> Element<Self::Message> {
        let content_list = list_column().padding(5).spacing(0).add(settings::item(
            self.sound_percentage.to_string(),
            widget::slider(0..=100, self.sound_percentage, Message::SoundChange),
        ));

        self.core.applet.popup_container(content_list).into()
    }

It might be a good idea to add additional methods to the applet context, so you do not need to wrap in a mouse area. Other widgets like the slider, should be wrapped inside a mouse area and be made scroll able.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant