Skip to content

Commit

Permalink
feat: feature gate dev_panels
Browse files Browse the repository at this point in the history
  • Loading branch information
eidloi committed Sep 24, 2024
1 parent 0f1f5fe commit f003cce
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 54 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ disable-ui-context-placeholder-warn = [
]
bevy_default_font = ["bevy/default_font"]
observable = []
dev_panels = []

[dependencies]
sickle_math = { path = "crates/sickle_math", version = "0.3.0" }
Expand All @@ -52,6 +53,4 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.127"

[dev-dependencies]
bevy = { version = "*", default-features = false, features = [
"bevy_gltf",
]}
bevy = { version = "*", default-features = false, features = ["bevy_gltf"] }
37 changes: 24 additions & 13 deletions examples/docking_zone_splits.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
//! An example using the widget library to test docking zones and zone splits.
use bevy::prelude::*;

#[cfg(feature = "dev_panels")]
use sickle_ui::dev_panels::hierarchy::{HierarchyTreeViewPlugin, UiHierarchyExt};

use sickle_ui::{
dev_panels::hierarchy::{HierarchyTreeViewPlugin, UiHierarchyExt},
ui_builder::{UiBuilder, UiBuilderExt, UiContextRoot, UiRoot},
ui_style::prelude::*,
widgets::prelude::*,
SickleUiPlugin,
};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Sickle UI - Docking Zone Splits".into(),
resolution: (1280., 720.).into(),
..default()
}),
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Sickle UI - Docking Zone Splits".into(),
resolution: (1280., 720.).into(),
..default()
}))
.add_plugins(SickleUiPlugin)
.add_plugins(HierarchyTreeViewPlugin)
.add_systems(Startup, setup.in_set(UiStartupSet))
.run();
}),
..default()
}))
.add_plugins(SickleUiPlugin)
.add_systems(Startup, setup.in_set(UiStartupSet));

#[cfg(feature = "dev_panels")]
app.add_plugins(HierarchyTreeViewPlugin);

app.run();
}

#[derive(Component)]
Expand Down Expand Up @@ -79,6 +84,11 @@ fn setup(mut commands: Commands) {
},
|column| {
hierarchy_container = column.id();

#[cfg(not(feature = "dev_panels"))]
column.label(
"Run with '--features=dev_panels'\nto get a hierarchy view here!",
);
},
)
.style()
Expand All @@ -99,6 +109,7 @@ fn setup(mut commands: Commands) {
},
);

#[cfg(feature = "dev_panels")]
commands
.ui_builder(hierarchy_container)
.hierarchy_for(root_entity);
Expand Down
96 changes: 58 additions & 38 deletions examples/simple_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,62 @@
use bevy::prelude::*;

use ease::Ease;
#[cfg(feature = "dev_panels")]
use sickle_ui::dev_panels::{
hierarchy::{HierarchyTreeViewPlugin, UiHierarchyExt},
scene_view::{SceneView, SceneViewPlugin, SpawnSceneViewPreUpdate, UiSceneViewExt},
};

use sickle_ui::{
dev_panels::{
hierarchy::{HierarchyTreeViewPlugin, UiHierarchyExt},
scene_view::{SceneView, SceneViewPlugin, SpawnSceneViewPreUpdate, UiSceneViewExt},
},
prelude::*,
ui_commands::{SetCursorExt, UpdateStatesExt},
SickleUiPlugin,
};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Sickle UI - Simple Editor".into(),
resolution: (1280., 720.).into(),
..default()
}),
let mut app = App::new();

app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Sickle UI - Simple Editor".into(),
resolution: (1280., 720.).into(),
..default()
}))
.add_plugins(SickleUiPlugin)
.add_plugins(UiFooterRootNodePlugin)
.add_plugins(OutlinedBlockPlugin)
.add_plugins(TextureAtlasInteractionPlugin)
.init_resource::<CurrentPage>()
.init_state::<Page>()
.add_plugins(HierarchyTreeViewPlugin)
}),
..default()
}))
.add_plugins(SickleUiPlugin)
.add_plugins(UiFooterRootNodePlugin)
.add_plugins(OutlinedBlockPlugin)
.add_plugins(TextureAtlasInteractionPlugin)
.init_resource::<CurrentPage>()
.init_state::<Page>()
.add_systems(Startup, setup.in_set(UiStartupSet))
.add_systems(OnEnter(Page::Layout), layout_showcase)
.add_systems(OnExit(Page::Layout), clear_content_on_menu_change)
.add_systems(OnEnter(Page::Playground), interaction_showcase)
.add_systems(OnExit(Page::Playground), clear_content_on_menu_change)
.add_systems(PreUpdate, exit_app_on_menu_item)
.add_systems(
Update,
(
update_current_page,
handle_theme_data_update,
handle_theme_switch,
handle_theme_contrast_select,
)
.chain()
.after(WidgetLibraryUpdate),
);

#[cfg(feature = "dev_panels")]
app.add_plugins(HierarchyTreeViewPlugin)
.add_plugins(SceneViewPlugin)
.add_systems(Startup, setup.in_set(UiStartupSet))
.add_systems(OnEnter(Page::Layout), layout_showcase)
.add_systems(OnExit(Page::Layout), clear_content_on_menu_change)
.add_systems(OnEnter(Page::Playground), interaction_showcase)
.add_systems(OnExit(Page::Playground), clear_content_on_menu_change)
.add_systems(PreUpdate, exit_app_on_menu_item)
.add_systems(
PreUpdate,
(spawn_hierarchy_view, despawn_hierarchy_view).after(SpawnSceneViewPreUpdate),
)
.add_systems(
Update,
(
update_current_page,
handle_theme_data_update,
handle_theme_switch,
handle_theme_contrast_select,
)
.chain()
.after(WidgetLibraryUpdate),
)
.run();
);

app.run();
}

#[derive(Component)]
Expand Down Expand Up @@ -739,6 +745,7 @@ fn clear_content_on_menu_change(
commands.set_cursor(CursorIcon::Default);
}

#[cfg(feature = "dev_panels")]
fn spawn_hierarchy_view(
q_added_scene_view: Query<&SceneView, Added<SceneView>>,
q_hierarchy_panel: Query<Entity, With<HierarchyPanel>>,
Expand All @@ -758,6 +765,7 @@ fn spawn_hierarchy_view(
}
}

#[cfg(feature = "dev_panels")]
fn despawn_hierarchy_view(
q_hierarchy_panel: Query<Entity, With<HierarchyPanel>>,
q_removed_scene_view: RemovedComponents<SceneView>,
Expand Down Expand Up @@ -799,6 +807,11 @@ fn layout_showcase(root_node: Query<Entity, With<ShowcaseContainer>>, mut comman
|tab_container| {
tab_container.add_tab("Hierarchy".into(), |panel| {
panel.insert(HierarchyPanel);

#[cfg(not(feature = "dev_panels"))]
panel.label(
"Run with '--features=dev_panels'\nto get a hierarchy view here!",
);
});
tab_container.add_tab("Tab 3".into(), |panel| {
panel.label(LabelConfig {
Expand All @@ -816,8 +829,15 @@ fn layout_showcase(root_node: Query<Entity, With<ShowcaseContainer>>, mut comman
false,
|tab_container| {
tab_container.add_tab("Scene View".into(), |panel| {
#[cfg(feature = "dev_panels")]
panel.scene_view("examples/Low_poly_scene.gltf#Scene0");

#[cfg(not(feature = "dev_panels"))]
panel.label(
"Run with '--features=dev_panels'\nto get a scene view here!",
);
});

tab_container.add_tab("Tab 2".into(), |panel| {
panel.label(LabelConfig {
label: "Panel 2".into(),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod assets;
#[cfg(feature = "dev_panels")]
pub mod dev_panels;
pub mod input_extension;
pub mod widgets;
Expand Down

0 comments on commit f003cce

Please sign in to comment.