Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_ui_widgets/src/lib.rs
6849 views
1
//! This crate provides a set of standard widgets for Bevy UI, such as buttons, checkboxes, and sliders.
2
//! These widgets have no inherent styling, it's the responsibility of the user to add styling
3
//! appropriate for their game or application.
4
//!
5
//! ## Warning: Experimental
6
//!
7
//! This crate is currently experimental and under active development.
8
//! The API is likely to change substantially: be prepared to migrate your code.
9
//!
10
//! We are actively seeking feedback on the design and implementation of this crate, so please
11
//! file issues or create PRs if you have any comments or suggestions.
12
//!
13
//! ## State Management
14
//!
15
//! Most of the widgets use external state management: this means that the widgets do not
16
//! automatically update their own internal state, but instead rely on the app to update the widget
17
//! state (as well as any other related game state) in response to a change event emitted by the
18
//! widget. The primary motivation for this is to avoid two-way data binding in scenarios where the
19
//! user interface is showing a live view of dynamic data coming from deeper within the game engine.
20
21
mod button;
22
mod callback;
23
mod checkbox;
24
mod radio;
25
mod scrollbar;
26
mod slider;
27
28
pub use button::*;
29
pub use callback::*;
30
pub use checkbox::*;
31
pub use radio::*;
32
pub use scrollbar::*;
33
pub use slider::*;
34
35
use bevy_app::{PluginGroup, PluginGroupBuilder};
36
use bevy_ecs::entity::Entity;
37
38
/// A plugin group that registers the observers for all of the widgets in this crate. If you don't want to
39
/// use all of the widgets, you can import the individual widget plugins instead.
40
pub struct UiWidgetsPlugins;
41
42
impl PluginGroup for UiWidgetsPlugins {
43
fn build(self) -> PluginGroupBuilder {
44
PluginGroupBuilder::start::<Self>()
45
.add(ButtonPlugin)
46
.add(CheckboxPlugin)
47
.add(RadioGroupPlugin)
48
.add(ScrollbarPlugin)
49
.add(SliderPlugin)
50
}
51
}
52
53
/// Notification sent by a button or menu item.
54
#[derive(Copy, Clone, Debug, PartialEq)]
55
pub struct Activate(pub Entity);
56
57
/// Notification sent by a widget that edits a scalar value.
58
#[derive(Copy, Clone, Debug, PartialEq)]
59
pub struct ValueChange<T> {
60
/// The id of the widget that produced this value.
61
pub source: Entity,
62
/// The new value.
63
pub value: T,
64
}
65
66