Skip to content

Commit 2284737

Browse files
authored
Merge pull request #249 from StarArawn/v0.4.1
v0.4.1
2 parents 885a3a1 + 58b933c commit 2284737

File tree

12 files changed

+320
-169
lines changed

12 files changed

+320
-169
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "kayak_ui"
33
description = "A UI library built using the bevy game engine!"
4-
version = "0.4.0"
4+
version = "0.4.1"
55
edition = "2021"
66
resolver = "2"
77
authors = ["John Mitchell"]

examples/svg.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ fn startup(
2020
let parent_id = None;
2121
rsx! {
2222
<KayakAppBundle>
23-
<KSvgBundle
24-
svg={KSvg(svg)}
23+
<ElementBundle
2524
styles={KStyle {
2625
position_type: StyleProp::Value(KPositionType::SelfDirected),
27-
left: StyleProp::Value(Units::Pixels(10.0)),
28-
top: StyleProp::Value(Units::Pixels(10.0)),
29-
width: StyleProp::Value(Units::Pixels(800.0)),
30-
height: StyleProp::Value(Units::Pixels(800.0)),
26+
left: StyleProp::Value(Units::Pixels(-34.545261 * 7.6)),
27+
top: StyleProp::Value(Units::Pixels(10.0 - 95.557219 * 7.6)),
3128
..Default::default()
3229
}}
33-
/>
30+
>
31+
<KSvgBundle
32+
svg={KSvg(svg)}
33+
styles={KStyle {
34+
width: StyleProp::Value(Units::Pixels(800.0)),
35+
height: StyleProp::Value(Units::Pixels(800.0)),
36+
..Default::default()
37+
}}
38+
/>
39+
</ElementBundle>
3440
</KayakAppBundle>
3541
};
3642

examples/tabs/tabs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ fn startup(
7575
..Default::default()
7676
}}
7777
>
78-
<TabBundle tab={Tab { index: 0 }}>
78+
<TabBundle key={"tab1"} tab={Tab { index: 0 }}>
7979
<TextWidgetBundle text={TextProps { content: "Tab 1 Content".into(), size: 14.0, line_height: Some(14.0), ..Default::default() }} />
8080
</TabBundle>
81-
<TabBundle tab={Tab { index: 1 }}>
81+
<TabBundle key={"tab2"} tab={Tab { index: 1 }}>
8282
<TextWidgetBundle text={TextProps { content: "Tab 2 Content".into(), size: 14.0, line_height: Some(14.0), ..Default::default() }} />
8383
</TabBundle>
8484
</ElementBundle>

src/children.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl KChildren {
6363
for child in self.inner.iter() {
6464
if let Some(parent_id) = parent_id {
6565
if let Some(mut entity_commands) = commands.get_entity(*child) {
66+
entity_commands.remove::<Parent>();
6667
entity_commands.set_parent(parent_id);
6768
}
6869
}

src/context.rs

Lines changed: 172 additions & 125 deletions
Large diffs are not rendered by default.

src/context_entities.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use dashmap::DashMap;
88

99
#[derive(Debug, Clone)]
1010
pub struct ContextEntities {
11-
ce: Arc<DashMap<Entity, DashMap<TypeId, Entity>>>,
11+
ce: Arc<DashMap<Option<Entity>, DashMap<TypeId, Entity>>>,
1212
}
1313

1414
impl ContextEntities {
@@ -20,7 +20,7 @@ impl ContextEntities {
2020

2121
pub fn add_context_entity<T: Default + 'static>(
2222
&self,
23-
parent_id: Entity,
23+
parent_id: Option<Entity>,
2424
context_entity: Entity,
2525
) {
2626
if !self.ce.contains_key(&parent_id) {
@@ -30,7 +30,10 @@ impl ContextEntities {
3030
inner.insert(T::default().type_id(), context_entity);
3131
}
3232

33-
pub fn get_context_entity<T: Default + 'static>(&self, parent_id: Entity) -> Option<Entity> {
33+
pub fn get_context_entity<T: Default + 'static>(
34+
&self,
35+
parent_id: Option<Entity>,
36+
) -> Option<Entity> {
3437
if !self.ce.contains_key(&parent_id) {
3538
return None;
3639
}

src/event_dispatcher.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ impl EventDispatcher {
425425
let mut stack_children = Vec::new();
426426
for child in children {
427427
let child_z = world
428-
.entity(child.0)
429-
.get::<Node>()
430-
.map(|node| node.z)
428+
.get_entity(child.0)
429+
.map(|e| e.get::<Node>().map(|node| node.z).unwrap_or(0.0))
431430
.unwrap_or(0.0);
432431
stack_children.push((child_z, (*child, depth + 1)));
433432
}
@@ -862,7 +861,7 @@ impl EventDispatcher {
862861
}
863862
}
864863

865-
#[derive(Resource)]
864+
#[derive(Resource, Default)]
866865
pub struct EventDispatcherContext {
867866
cursor_capture: Option<WrappedIndex>,
868867
}

src/on_event.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::widget_state::WidgetState;
1313
/// as a parameter.
1414
#[derive(Component, Clone)]
1515
pub struct OnEvent {
16-
has_initialized: bool,
16+
has_initialized: Arc<RwLock<bool>>,
1717
system: Arc<RwLock<dyn System<In = Entity, Out = ()>>>,
1818
}
1919

@@ -22,7 +22,6 @@ impl Default for OnEvent {
2222
Self::new(|In(_entity)| {})
2323
}
2424
}
25-
2625
impl OnEvent {
2726
/// Create a new event handler
2827
///
@@ -31,7 +30,7 @@ impl OnEvent {
3130
/// 2. The event
3231
pub fn new<Params>(system: impl IntoSystem<Entity, (), Params>) -> OnEvent {
3332
Self {
34-
has_initialized: false,
33+
has_initialized: Arc::new(RwLock::new(false)),
3534
system: Arc::new(RwLock::new(IntoSystem::into_system(system))),
3635
}
3736
}
@@ -48,21 +47,23 @@ impl OnEvent {
4847
world: &mut World,
4948
) -> (EventDispatcherContext, KEvent) {
5049
if let Ok(mut system) = self.system.try_write() {
51-
if !self.has_initialized {
52-
system.initialize(world);
53-
self.has_initialized = true;
50+
if let Ok(mut has_initialized) = self.has_initialized.try_write() {
51+
if !*has_initialized {
52+
system.initialize(world);
53+
*has_initialized = true;
54+
}
5455
}
5556
// Insert resources
5657
world.insert_resource(event_dispatcher_context);
5758
world.insert_resource(widget_state);
5859
world.insert_resource(event);
5960

6061
system.run(entity, world);
62+
system.apply_buffers(world);
6163

6264
event_dispatcher_context = world.remove_resource::<EventDispatcherContext>().unwrap();
6365
event = world.remove_resource::<KEvent>().unwrap();
64-
65-
system.apply_buffers(world);
66+
world.remove_resource::<WidgetState>().unwrap();
6667
}
6768
(event_dispatcher_context, event)
6869
}

src/render/ui_pass.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy::ecs::prelude::*;
44
use bevy::prelude::{Color, Image};
55
use bevy::render::render_asset::RenderAssets;
66
use bevy::render::render_phase::{
7-
BatchedPhaseItem, CachedRenderPipelinePhaseItem, DrawFunctionId, PhaseItem,
7+
BatchedPhaseItem, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem,
88
};
99
use bevy::render::render_resource::{CachedRenderPipelineId, RenderPassColorAttachment};
1010
use bevy::render::{
@@ -209,6 +209,10 @@ impl Node for MainPassUINode {
209209
if let Some(opacity_layer_manager) =
210210
opacity_layer_manager.camera_layers.get(&view_entity)
211211
{
212+
let draw_functions = world.resource::<DrawFunctions<TransparentOpacityUI>>();
213+
let mut draw_functions = draw_functions.write();
214+
draw_functions.prepare(world);
215+
212216
for layer_id in 1..MAX_OPACITY_LAYERS {
213217
// Start new render pass.
214218
let gpu_images = world.get_resource::<RenderAssets<Image>>().unwrap();
@@ -230,7 +234,14 @@ impl Node for MainPassUINode {
230234
let mut tracked_pass =
231235
render_context.begin_tracked_render_pass(pass_descriptor);
232236

233-
transparent_opacity_phase.render(&mut tracked_pass, world, view_entity);
237+
for item in transparent_opacity_phase
238+
.items
239+
.iter()
240+
.filter(|i| i.opacity_layer == layer_id)
241+
{
242+
let draw_function = draw_functions.get_mut(item.draw_function()).unwrap();
243+
draw_function.draw(world, &mut tracked_pass, view_entity, item);
244+
}
234245
}
235246
}
236247
}

src/render/unified/pipeline.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,7 @@ pub fn queue_quads_inner(
950950
position: final_position.into(),
951951
color,
952952
uv: [0.0; 4],
953-
pos_size: [
954-
sprite_rect.min.x,
955-
sprite_rect.min.y,
956-
sprite_rect.size().x,
957-
sprite_rect.size().y,
958-
],
953+
pos_size: [0.0, 0.0, sprite_rect.size().x, sprite_rect.size().y],
959954
});
960955
}
961956
*index += indices.len() as u32;

0 commit comments

Comments
 (0)