Skip to main content

dear_imgui_rs/ui/
navigation.rs

1use super::*;
2
3impl Ui {
4    /// Returns the currently desired mouse cursor type
5    ///
6    /// Returns `None` if no cursor should be displayed
7    #[doc(alias = "GetMouseCursor")]
8    pub fn mouse_cursor(&self) -> Option<MouseCursor> {
9        unsafe {
10            match sys::igGetMouseCursor() {
11                sys::ImGuiMouseCursor_Arrow => Some(MouseCursor::Arrow),
12                sys::ImGuiMouseCursor_TextInput => Some(MouseCursor::TextInput),
13                sys::ImGuiMouseCursor_ResizeAll => Some(MouseCursor::ResizeAll),
14                sys::ImGuiMouseCursor_ResizeNS => Some(MouseCursor::ResizeNS),
15                sys::ImGuiMouseCursor_ResizeEW => Some(MouseCursor::ResizeEW),
16                sys::ImGuiMouseCursor_ResizeNESW => Some(MouseCursor::ResizeNESW),
17                sys::ImGuiMouseCursor_ResizeNWSE => Some(MouseCursor::ResizeNWSE),
18                sys::ImGuiMouseCursor_Hand => Some(MouseCursor::Hand),
19                sys::ImGuiMouseCursor_NotAllowed => Some(MouseCursor::NotAllowed),
20                _ => None,
21            }
22        }
23    }
24
25    /// Sets the desired mouse cursor type
26    ///
27    /// Passing `None` hides the mouse cursor
28    #[doc(alias = "SetMouseCursor")]
29    pub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>) {
30        unsafe {
31            let val: sys::ImGuiMouseCursor = cursor_type
32                .map(|x| x as sys::ImGuiMouseCursor)
33                .unwrap_or(sys::ImGuiMouseCursor_None);
34            sys::igSetMouseCursor(val);
35        }
36    }
37
38    // ============================================================================
39    // Focus and Navigation
40    // ============================================================================
41
42    /// Focuses keyboard on the next widget.
43    ///
44    /// This is the equivalent to [set_keyboard_focus_here_with_offset](Self::set_keyboard_focus_here_with_offset)
45    /// with `offset` set to 0.
46    #[doc(alias = "SetKeyboardFocusHere")]
47    pub fn set_keyboard_focus_here(&self) {
48        self.set_keyboard_focus_here_with_offset(0);
49    }
50
51    /// Focuses keyboard on a widget relative to current position.
52    ///
53    /// Use positive offset to focus on next widgets, negative offset to focus on previous widgets.
54    #[doc(alias = "SetKeyboardFocusHere")]
55    pub fn set_keyboard_focus_here_with_offset(&self, offset: i32) {
56        unsafe {
57            sys::igSetKeyboardFocusHere(offset);
58        }
59    }
60
61    /// Shows or hides the navigation cursor (a small marker indicating nav focus).
62    #[doc(alias = "SetNavCursorVisible")]
63    pub fn set_nav_cursor_visible(&self, visible: bool) {
64        self.run_with_bound_context(|| unsafe { sys::igSetNavCursorVisible(visible) });
65    }
66}