Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_feathers/src/lib.rs
6595 views
1
//! `bevy_feathers` is a collection of styled and themed widgets for building editors and
2
//! inspectors.
3
//!
4
//! The aesthetic choices made here are designed with a future Bevy Editor in mind,
5
//! but this crate is deliberately exposed to the public to allow the broader ecosystem to easily create
6
//! tooling for themselves and others that fits cohesively together.
7
//!
8
//! While it may be tempting to use this crate for your game's UI, it's deliberately not intended for that.
9
//! We've opted for a clean, functional style, and prioritized consistency over customization.
10
//! That said, if you like what you see, it can be a helpful learning tool.
11
//! Consider copying this code into your own project,
12
//! and refining the styles and abstractions provided to meet your needs.
13
//!
14
//! ## Warning: Experimental!
15
//! All that said, this crate is still experimental and unfinished!
16
//! It will change in breaking ways, and there will be both bugs and limitations.
17
//!
18
//! Please report issues, submit fixes and propose changes.
19
//! Thanks for stress-testing; let's build something better together.
20
21
use bevy_app::{HierarchyPropagatePlugin, Plugin, PostUpdate, PropagateSet};
22
use bevy_asset::embedded_asset;
23
use bevy_ecs::{query::With, schedule::IntoScheduleConfigs};
24
use bevy_text::{TextColor, TextFont};
25
use bevy_ui::UiSystems;
26
use bevy_ui_render::UiMaterialPlugin;
27
28
use crate::{
29
alpha_pattern::{AlphaPatternMaterial, AlphaPatternResource},
30
controls::ControlsPlugin,
31
cursor::{CursorIconPlugin, DefaultCursor, EntityCursor},
32
theme::{ThemedText, UiTheme},
33
};
34
35
mod alpha_pattern;
36
pub mod constants;
37
pub mod controls;
38
pub mod cursor;
39
pub mod dark_theme;
40
pub mod font_styles;
41
pub mod handle_or_path;
42
pub mod palette;
43
pub mod rounded_corners;
44
pub mod theme;
45
pub mod tokens;
46
47
/// Plugin which installs observers and systems for feathers themes, cursors, and all controls.
48
pub struct FeathersPlugin;
49
50
impl Plugin for FeathersPlugin {
51
fn build(&self, app: &mut bevy_app::App) {
52
app.init_resource::<UiTheme>();
53
54
// Embedded font
55
embedded_asset!(app, "assets/fonts/FiraSans-Bold.ttf");
56
embedded_asset!(app, "assets/fonts/FiraSans-BoldItalic.ttf");
57
embedded_asset!(app, "assets/fonts/FiraSans-Regular.ttf");
58
embedded_asset!(app, "assets/fonts/FiraSans-Italic.ttf");
59
embedded_asset!(app, "assets/fonts/FiraMono-Medium.ttf");
60
61
// Embedded shader
62
embedded_asset!(app, "assets/shaders/alpha_pattern.wgsl");
63
64
app.add_plugins((
65
ControlsPlugin,
66
CursorIconPlugin,
67
HierarchyPropagatePlugin::<TextColor, With<ThemedText>>::new(PostUpdate),
68
HierarchyPropagatePlugin::<TextFont, With<ThemedText>>::new(PostUpdate),
69
UiMaterialPlugin::<AlphaPatternMaterial>::default(),
70
));
71
72
// This needs to run in UiSystems::Propagate so the fonts are up-to-date for `measure_text_system`
73
// and `detect_text_needs_rerender` in UiSystems::Content
74
app.configure_sets(
75
PostUpdate,
76
PropagateSet::<TextFont>::default().in_set(UiSystems::Propagate),
77
);
78
79
app.insert_resource(DefaultCursor(EntityCursor::System(
80
bevy_window::SystemCursorIcon::Default,
81
)));
82
83
app.add_systems(PostUpdate, theme::update_theme)
84
.add_observer(theme::on_changed_background)
85
.add_observer(theme::on_changed_border)
86
.add_observer(theme::on_changed_font_color)
87
.add_observer(font_styles::on_changed_font);
88
89
app.init_resource::<AlphaPatternResource>();
90
}
91
}
92
93