streamdeck_oxide/
navigation.rs

1//! Navigation traits and utilities for Stream Deck applications.
2//!
3//! This module provides traits and utilities for navigating between
4//! different views in a Stream Deck application.
5
6use crate::view::View;
7use generic_array::ArrayLength;
8
9type GetViewResult<W, H, C, N> = Result<Box<dyn View<W, H, C, N>>, Box<dyn std::error::Error>>;
10
11/// A trait for navigation entries in a Stream Deck application.
12///
13/// This trait is implemented by types that represent different views
14/// or screens in a Stream Deck application. It provides a method for
15/// getting the view associated with a navigation entry.
16pub trait NavigationEntry<W, H, C>: Default + Send + Sync + Clone + PartialEq + 'static
17where
18    W: ArrayLength,
19    H: ArrayLength,
20    C: Send + Clone + Sync + 'static,
21{
22    /// Get the view associated with this navigation entry.
23    ///
24    /// This method returns a boxed view that can be used to render
25    /// the buttons for this navigation entry.
26    fn get_view(&self) -> GetViewResult<W, H, C, Self>;
27}
28
29/// A helper trait for creating navigation entries.
30///
31/// This trait provides a method for creating a navigation entry
32/// with a specific view.
33pub trait IntoNavigationEntry<W, H, C, N>
34where
35    W: ArrayLength,
36    H: ArrayLength,
37    C: Send + Clone + Sync + 'static,
38    N: NavigationEntry<W, H, C>,
39{
40    /// Convert this type into a navigation entry.
41    fn into_navigation_entry(self) -> N;
42}