8 个版本
新版本 0.2.5 | 2024 年 8 月 12 日 |
---|---|
0.2.4 | 2024 年 7 月 22 日 |
0.1.1 | 2024 年 7 月 1 日 |
#488 在 Rust 模式
每月 310 下载量
20KB
399 行
包 Focusable
GitHub 仓库 · API 文档 · 示例 · 变更日志 · 贡献
用于管理应用程序中可聚焦元素的库。
状态:实验性 - 预期会有破坏性变更。
此包实现了一种通用的聚焦处理方法,可用于任何应用程序。这专门为在 Ratatui 中提供可聚焦行为小部件的方式而设计,但并不依赖于它。
文档可在 docs.rs 上找到。
使用
cargo add focusable
然后实现或推导出为您的类型实现的 Focus
和 FocusContainer
特质。
受 iced_focus 和 rat-focus 启发。
示例
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
许可证
版权所有 (c) 2024 Josh McKinney
本项目采用以下任一许可证:
- Apache 许可证 2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非您明确声明,否则您有意提交的任何贡献,根据 Apache-2.0 许可证定义,将根据上述方式双重许可,不附加任何额外条款或条件。
请参阅 CONTRIBUTING.md。
依赖项
~310–520KB