-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Work on directional navigation * Tab navigation is working now * Clean up interface, write a lil documentation
- Loading branch information
Showing
9 changed files
with
277 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Types and utilities for handling UI navigation with mice, keyboards, and | ||
//! gamepads. | ||
use crate::dom::Dom; | ||
use crate::input::InputState; | ||
use crate::layout::LayoutDom; | ||
use crate::widget::NavigateContext; | ||
use crate::WidgetId; | ||
|
||
/// Possible directions that a user can navigate in when using a gamepad or | ||
/// keyboard in a UI. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
#[allow(missing_docs)] | ||
pub enum NavDirection { | ||
/// The next widget in the layout, used when the user presses tab. | ||
Next, | ||
|
||
/// The previous widget in the layout, used if the user presses shift+tab. | ||
Previous, | ||
|
||
Down, | ||
Up, | ||
Left, | ||
Right, | ||
} | ||
|
||
pub(crate) fn navigate( | ||
dom: &Dom, | ||
layout: &LayoutDom, | ||
input: &InputState, | ||
dir: NavDirection, | ||
) -> Option<WidgetId> { | ||
let mut current = input.selection(); | ||
|
||
while let Some(id) = current { | ||
let node = dom.get(id).unwrap(); | ||
let ctx = NavigateContext { dom, layout, input }; | ||
|
||
if let Some(new_id) = ctx.try_navigate(id, dir) { | ||
return Some(new_id); | ||
} | ||
|
||
current = node.parent; | ||
} | ||
|
||
None | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.