Skip to content

Commit 091a98e

Browse files
authored
feat: add bevy feature (#48)
1 parent beb6d07 commit 091a98e

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ jobs:
2121
env:
2222
RUST_BACKTRACE: 1
2323
steps:
24+
- run: >
25+
sudo apt update && sudo apt install -y
26+
libx11-dev
27+
libasound2-dev
28+
libudev-dev
29+
libxkbcommon-x11-0
30+
libwayland-dev
31+
libxkbcommon-dev
2432
- uses: actions/checkout@v5
2533
- uses: dtolnay/rust-toolchain@master
2634
with:

Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ clippy.pedantic = "warn"
2020
clippy.nursery = "warn"
2121

2222
[dependencies]
23-
ansi_term = { version = "0.12.1", optional = true }
24-
css-colors = { version = "1.0.1", optional = true }
25-
ratatui = { version = "0.29.0", optional = true }
26-
serde = { version = "1.0.203", features = ["derive"], optional = true }
23+
ansi_term = { version = "0.12", optional = true }
24+
bevy = { version = "0.17", optional = true }
25+
css-colors = { version = "1.0", optional = true }
26+
ratatui = { version = "0.29", optional = true }
27+
serde = { version = "1.0", features = ["derive"], optional = true }
2728

2829
[build-dependencies]
2930
itertools = "0.14.0"
@@ -43,6 +44,7 @@ ansi-term = ["dep:ansi_term"]
4344
css-colors = ["dep:css-colors"]
4445
ratatui = ["dep:ratatui"]
4546
serde = ["dep:serde"]
47+
bevy = ["dep:bevy"]
4648

4749
[[example]]
4850
name = "css"
@@ -55,3 +57,7 @@ required-features = ["ansi-term"]
5557
[[example]]
5658
name = "ratatui"
5759
required-features = ["ratatui"]
60+
61+
[[example]]
62+
name = "bevy"
63+
required-features = ["bevy"]

examples/bevy.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//! Example demonstrating integration with the `bevy` crate.
2+
3+
use bevy::prelude::*;
4+
5+
use catppuccin::PALETTE;
6+
7+
fn main() {
8+
App::new()
9+
.add_plugins(DefaultPlugins)
10+
.add_systems(Startup, setup)
11+
.run();
12+
}
13+
14+
/// set up a simple 3D scene
15+
fn setup(
16+
mut commands: Commands,
17+
mut meshes: ResMut<Assets<Mesh>>,
18+
mut materials: ResMut<Assets<StandardMaterial>>,
19+
) {
20+
// circular base with catppuccin mocha surface color
21+
commands.spawn((
22+
Mesh3d(meshes.add(Circle::new(4.0))),
23+
MeshMaterial3d(materials.add(StandardMaterial::from_color(PALETTE.mocha.colors.surface0))),
24+
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
25+
));
26+
// cube with catppuccin mocha green color
27+
commands.spawn((
28+
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
29+
MeshMaterial3d(materials.add(StandardMaterial::from_color(PALETTE.mocha.colors.green))),
30+
Transform::from_xyz(0.0, 0.5, 0.0),
31+
));
32+
// Sphere on top of cube with catppuccin mocha red color
33+
commands.spawn((
34+
Mesh3d(meshes.add(Sphere::new(0.5))),
35+
MeshMaterial3d(materials.add(StandardMaterial::from_color(PALETTE.mocha.colors.red))),
36+
Transform::from_xyz(0.0, 1.5, 0.0),
37+
));
38+
// light
39+
commands.spawn((
40+
PointLight {
41+
shadows_enabled: true,
42+
..default()
43+
},
44+
Transform::from_xyz(4.0, 8.0, 4.0),
45+
));
46+
// camera
47+
commands.spawn((
48+
Camera3d::default(),
49+
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
50+
));
51+
}

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
//!
5454
//! Example: [`examples/ratatui.rs`](https://github.com/catppuccin/rust/blob/main/examples/ratatui.rs)
5555
//!
56+
//! ### Bevy
57+
//!
58+
//! Enable the `bevy` feature to enable the conversion of Catppuccin colors to
59+
//! [`bevy::prelude::Color`] instances.
60+
//! This adds [bevy](https://crates.io/crates/bevy) as a dependency.
61+
//!
62+
//! Example: [`examples/bevy.rs`](https://github.com/catppuccin/rust/blob/main/examples/bevy.rs)
63+
//!
5664
//! ### Serde
5765
//!
5866
//! Enable the `serde` feature to enable the serialization of Catppuccin's palette,
@@ -647,3 +655,20 @@ mod ratatui {
647655
}
648656
}
649657
}
658+
659+
#[cfg(feature = "bevy")]
660+
mod bevy {
661+
use crate::{AnsiColor, Color};
662+
663+
impl From<Color> for bevy::prelude::Color {
664+
fn from(value: Color) -> Self {
665+
Self::hsl(value.hsl.h as f32, value.hsl.s as f32, value.hsl.l as f32)
666+
}
667+
}
668+
669+
impl From<AnsiColor> for bevy::prelude::Color {
670+
fn from(value: AnsiColor) -> Self {
671+
Self::hsl(value.hsl.h as f32, value.hsl.s as f32, value.hsl.l as f32)
672+
}
673+
}
674+
}

0 commit comments

Comments
 (0)