Skip to main content

ferroui_diagnostics/diagnostics/
hot_key_configuration.rs

1//! Port of `Diagnostics/HotKeyConfiguration.cs`.
2
3use ferroui_base::input::{Key, KeyGesture, KeyModifiers};
4use std::cell::Cell;
5use std::rc::Rc;
6
7/// The key gestures that activate the features of DevTools.
8///
9/// A class upstream whose members are set once, when it is created (`init`): the members are
10/// read with `foo()` and given with the chaining `with_foo(v)` while the configuration is built.
11#[derive(Debug)]
12pub struct HotKeyConfiguration {
13    value_frames_freeze: Cell<KeyGesture>,
14    value_frames_unfreeze: Cell<KeyGesture>,
15    inspect_hovered_control: Cell<KeyGesture>,
16    toggle_popup_freeze: Cell<KeyGesture>,
17    screenshot_selected_control: Cell<KeyGesture>,
18}
19
20impl PartialEq for HotKeyConfiguration {
21    fn eq(&self, other: &Self) -> bool {
22        std::ptr::eq(self, other)
23    }
24}
25
26impl Default for HotKeyConfiguration {
27    fn default() -> Self {
28        Self {
29            value_frames_freeze: Cell::new(KeyGesture::new(Key::S, KeyModifiers::ALT)),
30            value_frames_unfreeze: Cell::new(KeyGesture::new(Key::D, KeyModifiers::ALT)),
31            inspect_hovered_control: Cell::new(KeyGesture::new(
32                Key::None,
33                KeyModifiers::SHIFT.union(KeyModifiers::CONTROL),
34            )),
35            toggle_popup_freeze: Cell::new(KeyGesture::new(Key::F, KeyModifiers::ALT.union(KeyModifiers::CONTROL))),
36            screenshot_selected_control: Cell::new(KeyGesture::from_key(Key::F8)),
37        }
38    }
39}
40
41impl HotKeyConfiguration {
42    /// C# `new HotKeyConfiguration()`: the default gestures.
43    pub fn new() -> Rc<Self> {
44        Rc::new(Self::default())
45    }
46
47    /// Freezes refreshing the Value Frames inspector for the selected Control
48    pub fn value_frames_freeze(&self) -> KeyGesture {
49        self.value_frames_freeze.get()
50    }
51
52    /// Initializes [`value_frames_freeze`](Self::value_frames_freeze).
53    pub fn with_value_frames_freeze(self: Rc<Self>, value: KeyGesture) -> Rc<Self> {
54        self.value_frames_freeze.set(value);
55        self
56    }
57
58    /// Resumes refreshing the Value Frames inspector for the selected Control
59    pub fn value_frames_unfreeze(&self) -> KeyGesture {
60        self.value_frames_unfreeze.get()
61    }
62
63    /// Initializes [`value_frames_unfreeze`](Self::value_frames_unfreeze).
64    pub fn with_value_frames_unfreeze(self: Rc<Self>, value: KeyGesture) -> Rc<Self> {
65        self.value_frames_unfreeze.set(value);
66        self
67    }
68
69    /// Inspects the hovered Control in the Logical or Visual Tree Page
70    pub fn inspect_hovered_control(&self) -> KeyGesture {
71        self.inspect_hovered_control.get()
72    }
73
74    /// Initializes [`inspect_hovered_control`](Self::inspect_hovered_control).
75    pub fn with_inspect_hovered_control(self: Rc<Self>, value: KeyGesture) -> Rc<Self> {
76        self.inspect_hovered_control.set(value);
77        self
78    }
79
80    /// Toggles the freezing of Popups which prevents visible Popups from closing so they can be inspected
81    pub fn toggle_popup_freeze(&self) -> KeyGesture {
82        self.toggle_popup_freeze.get()
83    }
84
85    /// Initializes [`toggle_popup_freeze`](Self::toggle_popup_freeze).
86    pub fn with_toggle_popup_freeze(self: Rc<Self>, value: KeyGesture) -> Rc<Self> {
87        self.toggle_popup_freeze.set(value);
88        self
89    }
90
91    /// Saves a Screenshot of the Selected Control in the Logical or Visual Tree Page
92    pub fn screenshot_selected_control(&self) -> KeyGesture {
93        self.screenshot_selected_control.get()
94    }
95
96    /// Initializes [`screenshot_selected_control`](Self::screenshot_selected_control).
97    pub fn with_screenshot_selected_control(self: Rc<Self>, value: KeyGesture) -> Rc<Self> {
98        self.screenshot_selected_control.set(value);
99        self
100    }
101}