Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_core_widgets/src/lib.rs
6595 views
1
//! This crate provides a set of core 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
//! # State Management
6
//!
7
//! Most of the widgets use external state management: this means that the widgets do not
8
//! automatically update their own internal state, but instead rely on the app to update the widget
9
//! state (as well as any other related game state) in response to a change event emitted by the
10
//! widget. The primary motivation for this is to avoid two-way data binding in scenarios where the
11
//! user interface is showing a live view of dynamic data coming from deeper within the game engine.
12
13
// Note on naming: the `Core` prefix is used on components that would normally be internal to the
14
// styled/opinionated widgets that use them. Components which are directly exposed to users above
15
// the widget level, like `SliderValue`, should not have the `Core` prefix.
16
17
mod callback;
18
mod core_button;
19
mod core_checkbox;
20
mod core_radio;
21
mod core_scrollbar;
22
mod core_slider;
23
24
use bevy_app::{PluginGroup, PluginGroupBuilder};
25
26
use bevy_ecs::entity::Entity;
27
pub use callback::{Callback, Notify};
28
pub use core_button::{CoreButton, CoreButtonPlugin};
29
pub use core_checkbox::{CoreCheckbox, CoreCheckboxPlugin, SetChecked, ToggleChecked};
30
pub use core_radio::{CoreRadio, CoreRadioGroup, CoreRadioGroupPlugin};
31
pub use core_scrollbar::{
32
ControlOrientation, CoreScrollbar, CoreScrollbarDragState, CoreScrollbarPlugin,
33
CoreScrollbarThumb,
34
};
35
pub use core_slider::{
36
CoreSlider, CoreSliderDragState, CoreSliderPlugin, CoreSliderThumb, SetSliderValue,
37
SliderPrecision, SliderRange, SliderStep, SliderValue, TrackClick,
38
};
39
40
/// A plugin group that registers the observers for all of the core widgets. If you don't want to
41
/// use all of the widgets, you can import the individual widget plugins instead.
42
pub struct CoreWidgetsPlugins;
43
44
impl PluginGroup for CoreWidgetsPlugins {
45
fn build(self) -> PluginGroupBuilder {
46
PluginGroupBuilder::start::<Self>()
47
.add(CoreButtonPlugin)
48
.add(CoreCheckboxPlugin)
49
.add(CoreRadioGroupPlugin)
50
.add(CoreScrollbarPlugin)
51
.add(CoreSliderPlugin)
52
}
53
}
54
55
/// Notification sent by a button or menu item.
56
#[derive(Copy, Clone, Debug, PartialEq)]
57
pub struct Activate(pub Entity);
58
59
/// Notification sent by a widget that edits a scalar value.
60
#[derive(Copy, Clone, Debug, PartialEq)]
61
pub struct ValueChange<T> {
62
/// The id of the widget that produced this value.
63
pub source: Entity,
64
/// The new value.
65
pub value: T,
66
}
67
68