Skip to content

Commit

Permalink
Rename components with Ui prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Davier committed Dec 3, 2021
1 parent faacdd1 commit c8975e5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
15 changes: 7 additions & 8 deletions pipelined/bevy_ui2/src/entity.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::Node;
use crate::{
widget::{Button, ImageMode},
CalculatedSize, FocusPolicy, Interaction, Style, CAMERA_UI,
CalculatedSize, FocusPolicy, Interaction, Node, Style, UiColor, UiImage, CAMERA_UI,
};
use bevy_ecs::bundle::Bundle;
use bevy_render2::{
Expand All @@ -15,8 +14,8 @@ use bevy_transform::prelude::{GlobalTransform, Transform};
pub struct NodeBundle {
pub node: Node,
pub style: Style,
pub color: crate::Color,
pub image: crate::Image,
pub color: UiColor,
pub image: UiImage,
pub transform: Transform,
pub global_transform: GlobalTransform,
}
Expand All @@ -27,8 +26,8 @@ pub struct ImageBundle {
pub style: Style,
pub image_mode: ImageMode,
pub calculated_size: CalculatedSize,
pub color: crate::Color,
pub image: crate::Image,
pub color: UiColor,
pub image: UiImage,
pub transform: Transform,
pub global_transform: GlobalTransform,
}
Expand Down Expand Up @@ -65,8 +64,8 @@ pub struct ButtonBundle {
pub style: Style,
pub interaction: Interaction,
pub focus_policy: FocusPolicy,
pub color: crate::Color,
pub image: crate::Image,
pub color: UiColor,
pub image: UiImage,
pub transform: Transform,
pub global_transform: GlobalTransform,
}
Expand Down
7 changes: 4 additions & 3 deletions pipelined/bevy_ui2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use bevy_asset::Handle;
use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel};
use bevy_input::InputSystem;
use bevy_math::{Rect, Size};
use bevy_render2::texture::Image;
use bevy_transform::TransformSystem;
use update::ui_z_system;

Expand All @@ -46,25 +47,25 @@ impl Plugin for UiPlugin {
.register_type::<AlignItems>()
.register_type::<AlignSelf>()
.register_type::<CalculatedSize>()
.register_type::<Color>()
.register_type::<Direction>()
.register_type::<Display>()
.register_type::<FlexDirection>()
.register_type::<FlexWrap>()
.register_type::<FocusPolicy>()
.register_type::<Interaction>()
.register_type::<Image>()
.register_type::<JustifyContent>()
.register_type::<Node>()
// NOTE: used by Style::aspect_ratio
.register_type::<Option<f32>>()
// NOTE: used by Image
.register_type::<Option<Handle<bevy_render2::texture::Image>>>()
.register_type::<Option<Handle<Image>>>()
.register_type::<PositionType>()
.register_type::<Size<f32>>()
.register_type::<Size<Val>>()
.register_type::<Rect<Val>>()
.register_type::<Style>()
.register_type::<UiColor>()
.register_type::<UiImage>()
.register_type::<Val>()
.register_type::<widget::Button>()
.register_type::<widget::ImageMode>()
Expand Down
6 changes: 2 additions & 4 deletions pipelined/bevy_ui2/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ use bevy_window::Windows;
use bytemuck::{Pod, Zeroable};
use wgpu::{ImageCopyTexture, ImageDataLayout, Origin3d};

use crate::Node;

// bevy_sprite2::lib.rs
use crate::{Node, UiColor, UiImage};

pub mod node {
pub const UI_PASS_DRIVER: &str = "ui_pass_driver";
Expand Down Expand Up @@ -136,7 +134,7 @@ pub struct ExtractedUiNodes {
pub fn extract_uinodes(
mut render_world: ResMut<RenderWorld>,
images: Res<Assets<Image>>,
uinode_query: Query<(&Node, &GlobalTransform, &crate::Color, &crate::Image)>,
uinode_query: Query<(&Node, &GlobalTransform, &UiColor, &UiImage)>,
) {
let mut extracted_uinodes = render_world.get_resource_mut::<ExtractedUiNodes>().unwrap();
extracted_uinodes.uinodes.clear();
Expand Down
13 changes: 7 additions & 6 deletions pipelined/bevy_ui2/src/ui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy_asset::Handle;
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
use bevy_math::{Rect, Size, Vec2};
use bevy_reflect::{Reflect, ReflectDeserialize};
use bevy_render2::{color::Color, texture::Image};
use serde::{Deserialize, Serialize};
use std::ops::{Add, AddAssign};

Expand Down Expand Up @@ -259,21 +260,21 @@ pub struct CalculatedSize {

#[derive(Component, Default, Copy, Clone, Debug, Reflect)]
#[reflect(Component)]
pub struct Color(pub bevy_render2::color::Color);
pub struct UiColor(pub Color);

impl From<bevy_render2::color::Color> for Color {
fn from(color: bevy_render2::color::Color) -> Self {
impl From<Color> for UiColor {
fn from(color: Color) -> Self {
Self(color)
}
}

// NOTE: Option<Handle<Image>> is reflected as a value, so this derive(Reflect) requires Handle<T> to derive Serialize and Deserialize
#[derive(Component, Default, Clone, Debug, Reflect)]
#[reflect(Component)]
pub struct Image(pub Option<Handle<bevy_render2::texture::Image>>);
pub struct UiImage(pub Option<Handle<Image>>);

impl From<Handle<bevy_render2::texture::Image>> for Image {
fn from(handle: Handle<bevy_render2::texture::Image>) -> Self {
impl From<Handle<Image>> for UiImage {
fn from(handle: Handle<Image>) -> Self {
Self(Some(handle))
}
}
7 changes: 4 additions & 3 deletions pipelined/bevy_ui2/src/widget/image.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::CalculatedSize;
use crate::{CalculatedSize, UiImage};
use bevy_asset::Assets;
use bevy_ecs::{
component::Component,
Expand All @@ -8,6 +8,7 @@ use bevy_ecs::{
};
use bevy_math::Size;
use bevy_reflect::{Reflect, ReflectDeserialize};
use bevy_render2::texture::Image;
use serde::{Deserialize, Serialize};

#[derive(Component, Debug, Clone, Reflect, Serialize, Deserialize)]
Expand All @@ -23,8 +24,8 @@ impl Default for ImageMode {
}

pub fn image_node_system(
textures: Res<Assets<bevy_render2::texture::Image>>,
mut query: Query<(&mut CalculatedSize, &crate::Image), With<ImageMode>>,
textures: Res<Assets<Image>>,
mut query: Query<(&mut CalculatedSize, &UiImage), With<ImageMode>>,
) {
for (mut calculated_size, image) in query.iter_mut() {
if let Some(texture) = image.0.as_ref().and_then(|handle| textures.get(handle)) {
Expand Down

0 comments on commit c8975e5

Please sign in to comment.