2个版本
0.1.1 | 2024年7月19日 |
---|---|
0.1.0 | 2024年6月28日 |
0.0.2-rc.2 |
|
在游戏开发中排名第967
每月下载量75次
290KB
5K SLoC
haalka হালকা
in bengali, haalka means "light" (e.g. not heavy) and can also be used to mean "easy"
haalka 是一个由 Bevy 提供支持的,人体工程学的反应式 UI 库,它由令人难以置信的 FRP 信号 futures-signals 和方便的异步ECS bevy-async-ecs 驱动,API 从网络UI库 MoonZoon 和 Dominator 端口。
虽然haalka主要针对UI,并提供高级UI抽象,但其 核心抽象 可以用于管理任何实体(不仅仅是 bevy_ui 节点)的信号驱动的反应性。
示例
use bevy::prelude::*;
use haalka::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, HaalkaPlugin))
.add_systems(Startup, (ui_root, camera))
.run();
}
#[derive(Component)]
struct Counter(Mutable<i32>);
fn ui_root(world: &mut World) {
let counter = Mutable::new(0);
El::<NodeBundle>::new()
.height(Val::Percent(100.))
.width(Val::Percent(100.))
.align_content(Align::center())
.child(
Row::<NodeBundle>::new()
.with_style(|mut style| style.column_gap = Val::Px(15.0))
.item(counter_button(counter.clone(), "-", -1))
.item(El::<TextBundle>::new().text_signal(counter.signal().map(text)))
.item(counter_button(counter.clone(), "+", 1))
.update_raw_el(move |raw_el| raw_el.insert(Counter(counter))),
)
.spawn(world);
}
fn counter_button(counter: Mutable<i32>, label: &str, step: i32) -> impl Element {
let hovered = Mutable::new(false);
El::<NodeBundle>::new()
.width(Val::Px(45.0))
.align_content(Align::center())
.background_color_signal(
hovered
.signal()
.map_bool(|| Color::hsl(300., 0.75, 0.85), || Color::hsl(300., 0.75, 0.75))
.map(BackgroundColor),
)
.hovered_sync(hovered)
.on_click(move || *counter.lock_mut() += step)
.child(El::<TextBundle>::new().text(text(label)))
}
fn text(text: impl ToString) -> Text {
Text::from_section(
text.to_string(),
TextStyle {
font_size: 30.0,
..default()
},
)
}
fn camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}
cargo run --example counter # the example above
cargo run --example button # port of https://github.com/bevyengine/bevy/blob/main/examples/ui/button.rs
cargo run --example align # alignment API demo, port of https://github.com/MoonZoon/MoonZoon/tree/main/examples/align and https://github.com/MoonZoon/MoonZoon/tree/main/examples/align_content
cargo run --example scroll # scrollability API demo, inspired by https://github.com/mintlu8/bevy-rectray/blob/main/examples/scroll_discrete.rs
cargo run --example scroll_grid # i can't believe it's not scrolling !
cargo run --example snake # with adjustable grid size and tick rate
cargo run --example ecs_ui_sync # forward ecs changes to the ui
cargo run --example key_values_sorted # text inputs, scrolling/viewport control, and reactive lists; promises made promises kept ! https://discord.com/channels/691052431525675048/1192585689460658348/1193431789465776198 (yes i take requests)
# ui challenges from https://github.com/bevyengine/bevy/discussions/11100
cargo run --example challenge01 # game menu
cargo run --example challenge02 # inventory
cargo run --example challenge03 # health bar
cargo run --example challenge04 # responsive menu
cargo run --example challenge05 # character editor
您也可以使用 just
(cargo install just
) 运行示例,例如 just example snake -r
。
Bevy兼容性
bevy | haalka |
---|---|
0.13 |
0.1 |
许可证
此存储库中的所有代码均可根据您的选择在以下两种许可证下使用
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
- Apache许可证2.0版本 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
。
示例中使用的资产可能根据不同的条款进行许可,请参阅examples
README。
您的贡献
除非您明确表示,否则根据Apache-2.0许可证定义的,您有意提交以包含在作品中并由您提交的贡献,将如上所述双重许可,而无需任何额外的条款或条件。
依赖项
~21–66MB
~1M SLoC