ferroui_base/platform/i_platform_settings.rs
1use super::PlatformColorValues;
2use crate::input::platform::PlatformHotkeyConfiguration;
3use crate::input::PointerType;
4use crate::reactive::{Disposable, IDisposable};
5use crate::Size;
6use std::rc::Rc;
7use std::time::Duration;
8
9/// A platform-specific settings contract.
10///
11/// This interface is not meant to be implemented by applications.
12pub trait IPlatformSettings {
13 /// The size of the rectangle around the location of a pointer down that
14 /// a pointer up must occur within in order to register a tap gesture, in
15 /// device-independent pixels.
16 fn get_tap_size(&self, type_: PointerType) -> Size;
17
18 /// The size of the rectangle around the location of a pointer down that
19 /// a pointer up must occur within in order to register a double-tap
20 /// gesture, in device-independent pixels.
21 fn get_double_tap_size(&self, type_: PointerType) -> Size;
22
23 /// The maximum time that may occur between the first and second click
24 /// of a double-tap gesture.
25 fn get_double_tap_time(&self, type_: PointerType) -> Duration;
26
27 /// The time a pointer must be held down for in order to register a
28 /// holding gesture.
29 fn hold_wait_duration(&self) -> Duration;
30
31 /// The key gestures of the platform for common commands.
32 fn hotkey_configuration(&self) -> Rc<PlatformHotkeyConfiguration>;
33
34 /// The preferred application language of the user: the tag of the
35 /// language (such as `en-US`) the platform reports for the application.
36 fn preferred_application_language(&self) -> String;
37
38 /// Whether the user lets the system play animations that are not essential (WinUI
39 /// `SharedHelpers::IsAnimationsEnabled`, which reads `UISettings.AnimationsEnabled`).
40 ///
41 /// The setting is asked for each animation, not kept: a change of it applies to the next
42 /// animation. A platform that does not report it lets animations play (the default).
43 /// A FerroUI addition for the ports of WinUI controls (DEVIATIONS.md, Platform settings).
44 fn animations_enabled(&self) -> bool {
45 true
46 }
47
48 /// Whether the system permits translucent materials and backdrop effects.
49 ///
50 /// A backend that does not expose a transparency preference preserves the
51 /// application's normal materials. Backends should query the current
52 /// preference rather than cache it for the process lifetime.
53 fn transparency_enabled(&self) -> bool {
54 true
55 }
56
57 /// Raised when motion, transparency, or other display accessibility
58 /// preferences change. The callback runs on the UI thread; consumers read
59 /// the current values and invalidate any derived resources.
60 ///
61 /// The default is an empty subscription so existing platform backends and
62 /// external implementations remain source-compatible.
63 fn accessibility_settings_changed(&self, _handler: Rc<dyn Fn()>) -> Rc<dyn IDisposable> {
64 Disposable::empty()
65 }
66
67 /// Gets current system color values including dark mode and accent
68 /// colors.
69 fn get_color_values(&self) -> PlatformColorValues;
70
71 /// Raises when current system color values are changed, including
72 /// changing of a dark mode and accent colors. Disposing the returned
73 /// handle unsubscribes.
74 fn color_values_changed(&self, handler: Rc<dyn Fn(&PlatformColorValues)>) -> Rc<dyn IDisposable>;
75
76 /// Raised when the system language preferences change. Disposing the
77 /// returned handle unsubscribes.
78 fn preferred_application_language_changed(&self, handler: Rc<dyn Fn()>) -> Rc<dyn IDisposable>;
79
80 /// Whether the energy saver of the system (battery saver, low power mode) is on: WinUI's
81 /// material policy (`MaterialHelper`) draws no acrylic while it is, from
82 /// `PowerManager.EnergySaverStatus`. A platform that does not report it answers `false`.
83 /// Backends should query the current state rather than cache it for the process lifetime.
84 /// A FerroUI addition (docs/porting/winui-materials.md).
85 fn energy_saver_enabled(&self) -> bool {
86 false
87 }
88
89 /// Raised when the energy saver is turned on or off. The callback runs on the UI thread;
90 /// consumers read [`energy_saver_enabled`](Self::energy_saver_enabled). The default is an
91 /// empty subscription, for platforms that do not report it.
92 fn energy_saver_changed(&self, _handler: Rc<dyn Fn()>) -> Rc<dyn IDisposable> {
93 Disposable::empty()
94 }
95}