Skip to content

Commit

Permalink
rename enable_web_scroll -> enable_web_page_scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Sep 2, 2022
1 parent af8ae9b commit 6ae6207
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, added `WindowExtWindows::set_undecorated_shadow` and `WindowBuilderExtWindows::with_undecorated_shadow` to draw the drop shadow behind a borderless window.
- On Windows, fixed default window features (ie snap, animations, shake, etc.) when decorations are disabled.
- **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`.
- On web, by default, when the canvas is focused, scrolling of the webpage is disabled. It can however be enabled via the `WindowBuilderExtWebSys::enable_web_page_scroll` method.
- On Wayland, `wayland-csd-adwaita` now uses `ab_glyph` instead of `crossfont` to render the title for decorations.
- On Wayland, a new `wayland-csd-adwaita-crossfont` feature was added to use `crossfont` instead of `ab_glyph` for decorations.
- On Wayland, if not otherwise specified use upstream automatic CSD theme selection.
Expand Down Expand Up @@ -58,7 +59,6 @@ And please only add new entries to the top of this list, right below the `# Unre
- Added `Window::is_decorated`.
- On X11, fix for repeated event loop iteration when `ControlFlow` was `Wait`
- On X11, fix scale factor calculation when the only monitor is reconnected
- On web, by default, when the canvas is focused, scrolling of the webpage is disabled. It can however be enabled via the `WindowBuilderExtWebSys::enable_web_scroll` method.
- On Wayland, report unaccelerated mouse deltas in `DeviceEvent::MouseMotion`.
- On Web, a focused event is manually generated when a click occurs to emulate behaviour of other backends.
- **Breaking:** Bump `ndk` version to 0.6, ndk-sys to `v0.3`, `ndk-glue` to `0.6`.
Expand Down
6 changes: 3 additions & 3 deletions src/platform/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait WindowBuilderExtWebSys {
///
/// So only call this method if you know that you will never need to handle mouse wheel inputs
/// or click and dragging.
fn enable_web_scroll(self) -> Self;
fn enable_web_page_scroll(self) -> Self;

fn with_canvas(self, canvas: Option<HtmlCanvasElement>) -> Self;

Expand All @@ -43,8 +43,8 @@ pub trait WindowBuilderExtWebSys {
}

impl WindowBuilderExtWebSys for WindowBuilder {
fn enable_web_scroll(mut self) -> Self {
self.platform_specific.enable_web_scroll = true;
fn enable_web_page_scroll(mut self) -> Self {
self.platform_specific.enable_web_page_scroll = true;

self
}
Expand Down
10 changes: 6 additions & 4 deletions src/platform_impl/web/web_sys/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use web_sys::{
mod mouse_handler;
mod pointer_handler;

type EventListener = EventListenerHandle<dyn FnMut(Event)>;

#[allow(dead_code)]
pub struct Canvas {
common: Common,
Expand All @@ -27,10 +29,10 @@ pub struct Canvas {
on_keyboard_press: Option<EventListenerHandle<dyn FnMut(KeyboardEvent)>>,
on_received_character: Option<EventListenerHandle<dyn FnMut(KeyboardEvent)>>,
on_mouse_wheel: Option<EventListenerHandle<dyn FnMut(WheelEvent)>>,
on_fullscreen_change: Option<EventListenerHandle<dyn FnMut(Event)>>,
on_fullscreen_change: Option<EventListener>,
on_dark_mode: Option<MediaQueryListHandle>,
mouse_state: MouseState,
disable_web_scroll: Option<[EventListenerHandle<dyn FnMut(Event)>; 5]>,
disable_web_scroll: Option<[EventListener; 5]>,
}

struct Common {
Expand Down Expand Up @@ -80,7 +82,7 @@ impl Canvas {
wants_fullscreen: Rc::new(RefCell::new(false)),
};

let disable_web_scroll = if !attr.enable_web_scroll {
let disable_web_scroll = if !attr.enable_web_page_scroll && attr.prevent_default {
Some([
common.add_event("pointermove", move |event: Event| {
event.prevent_default();
Expand Down Expand Up @@ -298,7 +300,7 @@ impl Canvas {
}
}

pub fn on_mouse_wheel<F>(&mut self, mut handler: F, prevent_default: bool)
pub fn on_mouse_wheel<F>(&mut self, mut handler: F, _prevent_default: bool)
where
F: 'static + FnMut(i32, MouseScrollDelta, ModifiersState),
{
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub(crate) canvas: Option<backend::RawCanvasType>,
pub(crate) prevent_default: bool,
pub(crate) focusable: bool,
pub(crate) enable_web_scroll: bool,
pub(crate) enable_web_page_scroll: bool,
}

impl Default for PlatformSpecificWindowBuilderAttributes {
Expand All @@ -413,7 +413,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
canvas: None,
prevent_default: true,
focusable: true,
enable_web_scroll: false,
enable_web_page_scroll: false,
}
}
}

0 comments on commit 6ae6207

Please sign in to comment.