diff --git a/crates/bevy_ui/src/widget/button.rs b/crates/bevy_ui/src/widget/button.rs index abb788f21bf6b..cbd1baf80070f 100644 --- a/crates/bevy_ui/src/widget/button.rs +++ b/crates/bevy_ui/src/widget/button.rs @@ -1,9 +1,31 @@ use crate::{FocusPolicy, Interaction, Node}; +use accesskit::Role; +use bevy_a11y::AccessibilityNode; use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; -/// Marker struct for buttons +/// Unified button component that combines UI layout, interaction handling, focus management, +/// and accessibility support. +/// +/// This component automatically includes all necessary components for a functional button +/// through the `#[require]` attribute: +/// - [`Node`]: For UI layout +/// - [`FocusPolicy::Block`]: For focus management +/// - [`Interaction`]: For tracking interaction state +/// - [`AccessibilityNode`]: For screen reader support +/// +/// # Interactive Behavior +/// +/// To enable full interactive behavior (pressed state, activation events), you need to: +/// 1. Add the [`bevy_ui_widgets::ButtonPlugin`] to your app +/// 2. Listen for [`bevy_ui_widgets::Activate`] events +/// ``` #[derive(Component, Debug, Default, Clone, Copy, PartialEq, Eq, Reflect)] #[reflect(Component, Default, Debug, PartialEq, Clone)] -#[require(Node, FocusPolicy::Block, Interaction)] +#[require( + Node, + FocusPolicy::Block, + Interaction, + AccessibilityNode(accesskit::Node::new(Role::Button)) +)] pub struct Button; diff --git a/crates/bevy_ui_widgets/src/button.rs b/crates/bevy_ui_widgets/src/button.rs index 4c98f6063d8d6..0d349c6fd5c39 100644 --- a/crates/bevy_ui_widgets/src/button.rs +++ b/crates/bevy_ui_widgets/src/button.rs @@ -1,9 +1,6 @@ -use accesskit::Role; -use bevy_a11y::AccessibilityNode; use bevy_app::{App, Plugin}; use bevy_ecs::query::Has; use bevy_ecs::{ - component::Component, entity::Entity, observer::On, query::With, @@ -17,12 +14,8 @@ use bevy_ui::{InteractionDisabled, Pressed}; use crate::Activate; -/// Headless button widget. This widget maintains a "pressed" state, which is used to -/// indicate whether the button is currently being pressed by the user. It emits an [`Activate`] -/// event when the button is un-pressed. -#[derive(Component, Default, Debug)] -#[require(AccessibilityNode(accesskit::Node::new(Role::Button)))] -pub struct Button; +// Re-export the Button component from bevy_ui +pub use bevy_ui::widget::Button; fn button_on_key_event( mut event: On>, diff --git a/crates/bevy_ui_widgets/src/lib.rs b/crates/bevy_ui_widgets/src/lib.rs index 3ab239412775e..402d878c8c73b 100644 --- a/crates/bevy_ui_widgets/src/lib.rs +++ b/crates/bevy_ui_widgets/src/lib.rs @@ -10,6 +10,12 @@ //! We are actively seeking feedback on the design and implementation of this crate, so please //! file issues or create PRs if you have any comments or suggestions. //! +//! ## Button Component +//! +//! The [`Button`] component is re-exported from [`bevy_ui::widget::Button`] to provide a unified +//! API. The component itself is defined in `bevy_ui`, while the interactive behavior (plugins and +//! observers) is provided by this crate through [`ButtonPlugin`]. +//! //! ## State Management //! //! Most of the widgets use external state management: this means that the widgets do not