1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! A library for managing focusable elements in an application.
//!
//! STATUS: Experimental - expect breaking changes.
//!
//! This crate implements a generic focus handling approach for use in any application. This was
//! specifically crafted with the idea of providing a way to add focusable behavior widgets in
//! Ratatui, but does not depend on it.
//!
//! Documentation is available at [docs.rs](https://docs.rs/focusable).
//!
//! # Usage
//!
//! ```shell
//! cargo add focusable
//! ```
//!
//! And then implement or derive the [`Focus`] and [`FocusContainer`] traits for your types.
//!
//! Inspired by [iced_focus](https://crates.io/crates/iced_focus) and
//! [rat-focus](https://crates.io/crates/rat-focus).
//!
//! # Example
//!
//! ```rust
//! use focusable::{Focus, FocusContainer};
//!
//! #[derive(Focus)]
//! struct Button {
//! is_focused: bool,
//! }
//!
//! #[derive(Focus)]
//! struct TextBox {
//! is_focused: bool,
//! }
//!
//! #[derive(Clone, Focus)]
//! struct Label;
//!
//! #[derive(FocusContainer)]
//! struct App {
//! children: Vec<Box<dyn Focus>>,
//! }
//!
//! let label = Box::new(Label);
//! assert!(!label.can_focus(), "Label should not be focusable");
//!
//! let button = Box::new(Button { is_focused: false });
//! assert!(button.can_focus());
//!
//! let text_box = Box::new(TextBox { is_focused: false });
//! assert!(text_box.can_focus());
//!
//! let mut app = App {
//! children: vec![label.clone(), button, label, text_box],
//! };
//!
//! app.focus_first();
//! assert!(app.children[1].is_focused()); // skip the first label
//!
//! app.focus_next();
//! assert!(app.children[3].is_focused()); // skip the second label
//! ```
//!
//! [`Focus`]: crate::focus::Focus
//! [`FocusContainer`]: crate::focus_container::FocusContainer
extern crate focusable_derive;
pub use ;
pub use crate::;