Merge pull request #5616 from Sylviromi/screen-mouse-scrolled

Native mods: screen_mouse_scrolled, the wheel over the open screen (API next)
This commit is contained in:
levzzz authored and GitHub committed 2026-11-01 15:09:48 +05:00
commit bd8c53bfa4
3 files changed
+64 -3

No files matched your search

+21
View File
@@ -16054,6 +16054,27 @@ impl Game<'_> {
}) * wheel_sensitivity
};
let d = scaled(raw_y) as f32;
// ScreenEvent.MouseScrolled.Pre: the open screen hears of
// the wheel before anything scrolls, and a cancelled turn
// scrolls nothing — no bundle, no list, slider or
// scrollbar. The hotbar below reads the wheel only while
// playing, which the gate excludes. A wheel the pad or the
// keyboard's focus made up is not the mouse: it fires
// nothing.
if !self.pad_synthetic_input()
&& let Some(screen) = self.screen_view_now()
{
let mut canceled = false;
self.native_screen_mouse_scrolled_pre(
&screen,
[scaled(raw_x), scaled(raw_y)],
glfw_modifiers(self.modifiers),
&mut canceled,
);
if canceled {
return Ok(());
}
}
if self.dialog_open() {
self.dialog_scroll(d);
} else if self.code_of_conduct.is_some() {
+35 -3
View File
@@ -805,9 +805,10 @@ pub struct NativeScreen {
}
/// The open screen, for the screen hooks (`native_screen_render_post`,
/// `native_screen_mouse_button_pressed_pre`, `..._released_pre`): what it is,
/// its menu and title, where its container panel is, how many slots its menu
/// has, and where the mouse and the frame's partial tick are.
/// `native_screen_mouse_button_pressed_pre`, `..._released_pre`,
/// `native_screen_mouse_scrolled_pre`): what it is, its menu and title, where
/// its container panel is, how many slots its menu has, and where the mouse
/// and the frame's partial tick are.
#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
pub struct NativeScreenView<'a> {
@@ -1570,6 +1571,37 @@ impl Game<'_> {
) {
let _ = (screen, button, modifiers, canceled);
}
/// The wheel turned over the open screen (`ScreenEvent.MouseScrolled.Pre`,
/// vanilla's `Screen.mouseScrolled`): `screen` is the screen it is,
/// `screen.mouse` where the pointer is (so there is no position of its
/// own), `scroll` the wheel's movement in x and y as the game's own scroll
/// handler scales it (a notch is ±1 — its sign only — times the wheel
/// sensitivity, and a touchpad's pixels are divided by 30), and
/// `modifiers` GLFW's bits (shift 1, control 2, alt 4, super 8). Set
/// `canceled` and nothing the screen would scroll moves: not the bundle
/// under the pointer, nor a list, slider, scrollbar or map. Nothing else
/// reads the wheel while a screen of the game's is open, so no hotbar slot
/// changes either.
///
/// It fires before the screen scrolls anything, on the window only, and
/// only while a screen of the game's is open (Options and the pack list
/// opened from the title screen count, with no player and no `menu`). It
/// does not fire on the title screen itself, the connect and loading
/// screens, nor for a server dialog, the server pack, link and
/// code-of-conduct prompts, a book or a sign editor drawn over gameplay,
/// nor while a world loads or saves: the scroll there stays the game's
/// own. A wheel a gamepad or the keyboard's focus sends is not the mouse
/// and fires nothing.
/// API @API:screen_mouse_scrolled@.
pub(super) fn native_screen_mouse_scrolled_pre(
&self,
screen: &NativeScreenView<'_>,
scroll: [f64; 2],
modifiers: u32,
canceled: &mut bool,
) {
let _ = (screen, scroll, modifiers, canceled);
}
/// The open screen as a native mod sees it (`NativeScreenView`): its id,
/// the open menu's type and title, its slot count, and its panel's
/// rectangle, with the mouse and the partial tick. `screen` is the screen
@@ -0,0 +1,8 @@
{
"hooks": [
{"name": "screen_mouse_scrolled_pre", "target": "horizon_client::game::native_hooks::Game<'_>::native_screen_mouse_scrolled_pre"}
],
"rust_summary": "the open screen hears of the wheel before it scrolls (`native_screen_mouse_scrolled_pre`,\nthe `ScreenEvent.MouseScrolled.Pre` point, with the screen, the scroll in x and y as the game's\nscroll handler scales it, and the modifiers), so a cancelled turn scrolls nothing.",
"doc_summary": "the open screen hears of the wheel (`native_screen_mouse_scrolled_pre`) before it scrolls, as vanilla's `ScreenEvent.MouseScrolled.Pre`: the screen, the scroll's x and y as the game's scroll handler scales them (a notch is ±1, its sign only, times the wheel sensitivity; a touchpad's pixels are divided by 30), GLFW's modifier bits (shift 1, control 2, alt 4, super 8) and the pointer in `screen.mouse`. A cancelled turn scrolls nothing: no bundle under the pointer, no list, slider or scrollbar, and no hotbar slot. It fires on the window only, never on the title screen itself (Options and the pack list opened from it do fire), the connect and loading screens, the prompts, books and sign editors drawn over gameplay, or while a world loads or saves, and never for a wheel a gamepad or the keyboard's focus sends. Bundles need \"hooks\": @API:screen_mouse_scrolled@.",
"comments": []
}