Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_feathers/src/lib.rs
6849 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::{
22
HierarchyPropagatePlugin, Plugin, PluginGroup, PluginGroupBuilder, PostUpdate, PropagateSet,
23
};
24
use bevy_asset::embedded_asset;
25
use bevy_ecs::{query::With, schedule::IntoScheduleConfigs};
26
use bevy_input_focus::{tab_navigation::TabNavigationPlugin, InputDispatchPlugin};
27
use bevy_text::{TextColor, TextFont};
28
use bevy_ui::UiSystems;
29
use bevy_ui_render::UiMaterialPlugin;
30
use bevy_ui_widgets::UiWidgetsPlugins;
31
32
use crate::{
33
alpha_pattern::{AlphaPatternMaterial, AlphaPatternResource},
34
controls::ControlsPlugin,
35
cursor::{CursorIconPlugin, DefaultCursor, EntityCursor},
36
theme::{ThemedText, UiTheme},
37
};
38
39
mod alpha_pattern;
40
pub mod constants;
41
pub mod controls;
42
pub mod cursor;
43
pub mod dark_theme;
44
pub mod font_styles;
45
pub mod handle_or_path;
46
pub mod palette;
47
pub mod rounded_corners;
48
pub mod theme;
49
pub mod tokens;
50
51
/// Plugin which installs observers and systems for feathers themes, cursors, and all controls.
52
pub struct FeathersPlugin;
53
54
impl Plugin for FeathersPlugin {
55
fn build(&self, app: &mut bevy_app::App) {
56
app.init_resource::<UiTheme>();
57
58
// Embedded font
59
embedded_asset!(app, "assets/fonts/FiraSans-Bold.ttf");
60
embedded_asset!(app, "assets/fonts/FiraSans-BoldItalic.ttf");
61
embedded_asset!(app, "assets/fonts/FiraSans-Regular.ttf");
62
embedded_asset!(app, "assets/fonts/FiraSans-Italic.ttf");
63
embedded_asset!(app, "assets/fonts/FiraMono-Medium.ttf");
64
65
// Embedded shader
66
embedded_asset!(app, "assets/shaders/alpha_pattern.wgsl");
67
68
app.add_plugins((
69
ControlsPlugin,
70
CursorIconPlugin,
71
HierarchyPropagatePlugin::<TextColor, With<ThemedText>>::new(PostUpdate),
72
HierarchyPropagatePlugin::<TextFont, With<ThemedText>>::new(PostUpdate),
73
UiMaterialPlugin::<AlphaPatternMaterial>::default(),
74
));
75
76
// This needs to run in UiSystems::Propagate so the fonts are up-to-date for `measure_text_system`
77
// and `detect_text_needs_rerender` in UiSystems::Content
78
app.configure_sets(
79
PostUpdate,
80
PropagateSet::<TextFont>::default().in_set(UiSystems::Propagate),
81
);
82
83
app.insert_resource(DefaultCursor(EntityCursor::System(
84
bevy_window::SystemCursorIcon::Default,
85
)));
86
87
app.add_systems(PostUpdate, theme::update_theme)
88
.add_observer(theme::on_changed_background)
89
.add_observer(theme::on_changed_border)
90
.add_observer(theme::on_changed_font_color)
91
.add_observer(font_styles::on_changed_font);
92
93
app.init_resource::<AlphaPatternResource>();
94
}
95
}
96
97
/// A plugin group that adds all dependencies for Feathers
98
pub struct FeathersPlugins;
99
100
impl PluginGroup for FeathersPlugins {
101
fn build(self) -> PluginGroupBuilder {
102
PluginGroupBuilder::start::<Self>()
103
.add_group(UiWidgetsPlugins)
104
.add(InputDispatchPlugin)
105
.add(TabNavigationPlugin)
106
.add(FeathersPlugin)
107
}
108
}
109
110