Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to vello pr updates #38

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
422 changes: 231 additions & 191 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bevy = { version = "0.14", features = ["jpeg"] }
[patch.crates-io]
bevy_mod_picking = { git = "https://github.com/StarArawn/bevy_mod_picking", branch = "main" }
bevy_eventlistener = { git = "https://github.com/StarArawn/bevy_eventlistener", branch = "main" }
bevy_vello = { git = "https://github.com/ChristopherBiscardi/bevy_vello", branch = "renderlayer-canvas-fix" }
bevy_vello = { git = "https://github.com/linebender/bevy_vello", rev = "f21cdc2" }

[[example]]
name = "todo"
Expand Down
2 changes: 1 addition & 1 deletion examples/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn get_buttons() -> [&'static str; 16] {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.insert_resource(CalcOutput("".into()))
Expand Down
2 changes: 1 addition & 1 deletion examples/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn baz_render(entity: Res<CurrentWidget>, query: Query<&BazWidget>) {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(WorldInspectorPlugin::new())
.add_plugins(DefaultPickingPlugins)
.register_widget::<FooWidget>()
Expand Down
2 changes: 1 addition & 1 deletion examples/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod classes {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/clipping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn render(
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.register_widget::<CounterWidget>()
Expand Down
2 changes: 1 addition & 1 deletion examples/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn focus_render(
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.insert_resource(DebugPickingMode::Normal)
.register_widget::<FocusWidget>()
Expand Down
2 changes: 1 addition & 1 deletion examples/icon_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.insert_resource(DebugPickingMode::Normal)
.add_systems(Startup, startup)
Expand Down
2 changes: 1 addition & 1 deletion examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/image_contained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn render(
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.register_widget::<MyWidget>()
.add_systems(Startup, startup)
Expand Down
2 changes: 1 addition & 1 deletion examples/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn render(
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.register_widget::<MyWidget>()
.add_systems(Startup, startup)
Expand Down
75 changes: 75 additions & 0 deletions examples/render_layers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use bevy::{prelude::*, render::view::RenderLayers};
use bevy_mod_picking::DefaultPickingPlugins;
use bevy_vello::render::VelloRenderSettings;
use woodpecker_ui::prelude::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin)
.insert_resource(VelloRenderSettings {
canvas_render_layers: RenderLayers::layer(1),
})
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.add_systems(Update, flip_render_layers)
.run();
}

fn flip_render_layers(
mut query: Query<&mut RenderLayers, With<Camera2d>>,
input: Res<ButtonInput<KeyCode>>,
mut local: Local<u8>,
) {
if input.just_pressed(KeyCode::Space) {
for mut layer in &mut query {
*layer = match *local {
0 => {
info!("camera showing layer 0");
*local = 1;
RenderLayers::layer(0)
}
1 => {
info!("camera showing layer 1");
*local = 0;
RenderLayers::layer(1)
}
_ => unreachable!(),
};
}
}
}
fn startup(
mut commands: Commands,
mut ui_context: ResMut<WoodpeckerContext>,
mut font_manager: ResMut<FontManager>,
asset_server: Res<AssetServer>,
) {
commands.spawn((Camera2dBundle::default(), RenderLayers::layer(1)));

let font = asset_server.load("Outfit/static/Outfit-Regular.ttf");
font_manager.add(&font);

let root = commands
.spawn(WoodpeckerAppBundle {
children: WidgetChildren::default().with_child::<Element>((
ElementBundle {
styles: WoodpeckerStyle {
font_size: 50.0,
color: Srgba::RED.into(),
margin: Edge::all(10.0),
font: Some(font.id()),
..Default::default()
},
..Default::default()
},
WidgetRender::Text {
content: "Space to change Camera RenderLayer. WoodPecker is on layer 1".into(),
word_wrap: true,
},
)),
..Default::default()
})
.id();
ui_context.set_root_widget(root);
}
2 changes: 1 addition & 1 deletion examples/scrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/text_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/todo/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct TodoListData(Vec<String>);
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.register_widget::<TodoList>()
.register_widget::<TodoInput>()
Expand Down
2 changes: 1 addition & 1 deletion examples/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use woodpecker_ui::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WoodpeckerUIPlugin::default())
.add_plugins(WoodpeckerUIPlugin)
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, startup)
.run();
Expand Down
32 changes: 13 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! - [Taffy](https://github.com/DioxusLabs/taffy) layouting
//! - [Cosmic Text](https://github.com/pop-os/cosmic-text) for text layouting
//! - A few helper widgets to get you started
//!
//!
//! ## Example:
//! ```rust
//! fn startup(
Expand Down Expand Up @@ -59,10 +59,10 @@
//! .id();
//! ui_context.set_root_widget(root);
//! }
//!
//!
//! ```
use bevy::{
asset::embedded_asset, prelude::*, reflect::GetTypeRegistration, render::view::RenderLayers,
asset::embedded_asset, prelude::*, reflect::GetTypeRegistration,
};
use bevy_mod_picking::{events::Pointer, prelude::EventListenerPlugin};
use bevy_trait_query::RegisterExt;
Expand Down Expand Up @@ -136,7 +136,7 @@ pub struct ParentWidget(pub Entity);

impl ParentWidget {
/// Converts a ParentWidget into a CurrentWidget
///
///
/// Note: Really just a convince function.
pub fn as_current(&self) -> CurrentWidget {
CurrentWidget(self.0)
Expand All @@ -151,7 +151,7 @@ pub struct CurrentWidget(pub Entity);

impl CurrentWidget {
/// Converts a CurrentWidget into a ParentWidget.
///
///
/// Note: Really just a convince function.
pub fn as_parent(&self) -> ParentWidget {
ParentWidget(self.0)
Expand All @@ -161,17 +161,13 @@ impl CurrentWidget {
/// The Woodpecker UI bevy Plugin
/// Add this to bevy to use.
#[derive(Default)]
pub struct WoodpeckerUIPlugin {
pub render_layers: Option<RenderLayers>,
}
pub struct WoodpeckerUIPlugin;

impl Plugin for WoodpeckerUIPlugin {
fn build(&self, app: &mut App) {
embedded_asset!(app, "embedded_assets/Poppins-Regular.ttf");
app.add_plugins(WoodpeckerLayoutPlugin)
.add_plugins(VelloPlugin {
canvas_render_layers: self.render_layers.clone(),
})
.add_plugins(VelloPlugin::default())
.add_plugins(WoodpeckerUIWidgetPlugin)
.add_plugins(EventListenerPlugin::<focus::WidgetFocus>::default())
.add_plugins(EventListenerPlugin::<focus::WidgetBlur>::default())
Expand Down Expand Up @@ -238,17 +234,15 @@ fn has_root() -> impl Condition<(), ()> {

fn startup(
mut commands: Commands,
vello_render_config: Res<bevy_vello::render::VelloRenderPlugin>,
vello_render_config: Res<bevy_vello::render::VelloRenderSettings>,
) {
let entity = commands
.spawn(VelloSceneBundle {
commands.spawn((
VelloSceneBundle {
coordinate_space: CoordinateSpace::ScreenSpace,
..Default::default()
})
.id();
if let Some(layers) = &vello_render_config.canvas_render_layers {
commands.entity(entity).insert(layers.clone());
}
},
vello_render_config.canvas_render_layers.clone(),
));
}

/// A trait that gives us some extra functionality for register widgets
Expand Down