bevy/crates/bevy_editor/src/widgets/expansion_button.rs
jbuehler23 be278fb1dc feat(editor): introduce reusable UI widgets for the editor interface
- Added a new module for editor UI widgets, including ScrollViewBuilder, CoreScrollArea, ExpansionButton, BasicPanel, and ScrollableContainer.
- Implemented basic theme support with EditorTheme struct.
- Created a Panel widget with collapsible and resizable features.
- Developed a scrollable area widget with mouse wheel support and content height calculation methods.
- Added examples for using scroll widgets and programmatic scrolling.
- Introduced a simple panel widget with configurable dimensions and styling.
- Implemented a simple scrollable container with mouse wheel support.
- Established a theming system compatible with bevy_feathers, including themed UI elements and a theme management plugin.
2025-07-18 14:39:07 +01:00

80 lines
3.4 KiB
Rust

//! Expansion button widget for expandable UI elements
use bevy::prelude::*;
use crate::themes::DarkTheme;
use crate::remote::types::{ComponentDataFetched, RemoteConnection};
use crate::panels::{ComponentDisplayState, EditorState};
/// Component for expansion button widgets
#[derive(Component)]
pub struct ExpansionButton {
pub path: String,
pub is_expanded: bool,
}
/// Handle clicks on expansion buttons
pub fn handle_expansion_clicks(
mut interaction_query: Query<
(&Interaction, &mut ExpansionButton, &mut BackgroundColor),
(Changed<Interaction>, With<Button>)
>,
mut display_state: ResMut<ComponentDisplayState>,
editor_state: Res<EditorState>,
remote_conn: Res<RemoteConnection>,
mut commands: Commands,
) {
for (interaction, mut expansion_button, mut bg_color) in &mut interaction_query {
match *interaction {
Interaction::Pressed => {
// Toggle the expansion state
if display_state.expanded_paths.contains(&expansion_button.path) {
display_state.expanded_paths.remove(&expansion_button.path);
expansion_button.is_expanded = false;
} else {
display_state.expanded_paths.insert(expansion_button.path.clone());
expansion_button.is_expanded = true;
}
// Refresh the component display
if let Some(selected_entity_id) = editor_state.selected_entity_id {
if let Some(selected_entity) = editor_state.entities.iter().find(|e| e.id == selected_entity_id) {
if !selected_entity.full_component_names.is_empty() {
match crate::remote::client::try_fetch_component_data_with_names(
&remote_conn.base_url,
selected_entity_id,
selected_entity.full_component_names.clone()
) {
Ok(component_data) => {
commands.trigger(ComponentDataFetched {
entity_id: selected_entity_id,
component_data,
});
}
Err(_) => {
let fallback_data = format!(
"Component names for Entity {}:\n\n{}",
selected_entity_id,
selected_entity.components.join("\n")
);
commands.trigger(ComponentDataFetched {
entity_id: selected_entity_id,
component_data: fallback_data,
});
}
}
}
}
}
*bg_color = BackgroundColor(DarkTheme::EXPANSION_BUTTON_PRESSED);
}
Interaction::Hovered => {
*bg_color = BackgroundColor(DarkTheme::EXPANSION_BUTTON_HOVER);
}
Interaction::None => {
*bg_color = BackgroundColor(DarkTheme::EXPANSION_BUTTON_DEFAULT);
}
}
}
}