8 个版本

新版本 0.2.5 2024 年 8 月 12 日
0.2.4 2024 年 7 月 22 日
0.1.1 2024 年 7 月 1 日

#488Rust 模式

Download history 337/week @ 2024-06-28 165/week @ 2024-07-05 124/week @ 2024-07-12 151/week @ 2024-07-19 51/week @ 2024-07-26 1/week @ 2024-08-02 104/week @ 2024-08-09

每月 310 下载量

MIT/Apache

20KB
399

Focusable

Crate badge Docs.rs Badge Deps.rs Badge License Badge Codecov.io Badge Discord Badge

GitHub 仓库 · API 文档 · 示例 · 变更日志 · 贡献

用于管理应用程序中可聚焦元素的库。

状态:实验性 - 预期会有破坏性变更。

此包实现了一种通用的聚焦处理方法,可用于任何应用程序。这专门为在 Ratatui 中提供可聚焦行为小部件的方式而设计,但并不依赖于它。

文档可在 docs.rs 上找到。

使用

cargo add focusable

然后实现或推导出为您的类型实现的 FocusFocusContainer 特质。

iced_focusrat-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 许可证定义,将根据上述方式双重许可,不附加任何额外条款或条件。

请参阅 CONTRIBUTING.md

依赖项

~310–520KB