Skip to content

Commit

Permalink
Add ProtoColor
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Apr 30, 2023
1 parent 1258832 commit c84dd83
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 41 deletions.
7 changes: 1 addition & 6 deletions assets/examples/bevy/ui/Left.prototype.ron
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@
style: (
font: AssetPath("fonts/JetBrainsMono-Regular.ttf"),
font_size: 30.0,
color: Rgba(
red: 1.0,
green: 1.0,
blue: 1.0,
alpha: 1.0
),
color: White,
)
)]
),
Expand Down
7 changes: 1 addition & 6 deletions assets/examples/bevy/ui/Red.prototype.ron
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
height: Px(100.0),
),
),
background_color: (Rgba(
red: 1.0,
green: 0.0,
blue: 0.0,
alpha: 1.0
)),
background_color: (Red),
)
},
children: [
Expand Down
7 changes: 1 addition & 6 deletions assets/examples/bevy/ui/Right.prototype.ron
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@
style: (
font: AssetPath("fonts/JetBrainsMono-Regular.ttf"),
font_size: 25.0,
color: Rgba(
red: 1.0,
green: 1.0,
blue: 1.0,
alpha: 1.0
),
color: White,
)
)]
),
Expand Down
22 changes: 11 additions & 11 deletions bevy_proto_backend/src/impls/bevy_impls/pbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use bevy::pbr::{
DirectionalLight, EnvironmentMapLight, FogFalloff, FogSettings, NotShadowCaster,
NotShadowReceiver, PointLight, SpotLight,
};
use bevy::prelude::Color;
use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect};

use crate::impls::macros::{from_to, from_to_default, register_schematic};
use crate::proto::ProtoColor;
use bevy_proto_derive::impl_external_schematic;

pub(super) fn register(app: &mut App) {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl_external_schematic! {
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct DirectionalLightInput {
pub color: Color,
pub color: ProtoColor,
pub illuminance: f32,
pub shadows_enabled: bool,
pub shadow_depth_bias: f32,
Expand All @@ -133,7 +133,7 @@ impl_external_schematic! {
DirectionalLight,
DirectionalLightInput,
|value: Input| Self {
color: value.color,
color: value.color.into(),
illuminance: value.illuminance,
shadows_enabled: value.shadows_enabled,
shadow_depth_bias: value.shadow_depth_bias,
Expand All @@ -158,17 +158,17 @@ impl_external_schematic! {
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct FogSettingsInput {
pub color: Color,
pub directional_light_color: Color,
pub color: ProtoColor,
pub directional_light_color: ProtoColor,
pub directional_light_exponent: f32,
pub falloff: FogFalloffInput,
}
from_to_default! {
FogSettings,
FogSettingsInput,
|value: Input| Self {
color: value.color,
directional_light_color: value.directional_light_color,
color: value.color.into(),
directional_light_color: value.directional_light_color.into(),
directional_light_exponent: value.directional_light_exponent,
falloff: value.falloff.into(),
}
Expand Down Expand Up @@ -236,7 +236,7 @@ impl_external_schematic! {
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct PointLightInput {
pub color: Color,
pub color: ProtoColor,
pub intensity: f32,
pub range: f32,
pub radius: f32,
Expand All @@ -248,7 +248,7 @@ impl_external_schematic! {
PointLight,
PointLightInput,
|value: Input| Self {
color: value.color,
color: value.color.into(),
intensity: value.intensity,
range: value.range,
radius: value.radius,
Expand All @@ -266,7 +266,7 @@ impl_external_schematic! {
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct SpotLightInput {
pub color: Color,
pub color: ProtoColor,
pub intensity: f32,
pub range: f32,
pub radius: f32,
Expand All @@ -280,7 +280,7 @@ impl_external_schematic! {
SpotLight,
SpotLightInput,
|value: Input| Self {
color: value.color,
color: value.color.into(),
intensity: value.intensity,
range: value.range,
radius: value.radius,
Expand Down
7 changes: 3 additions & 4 deletions bevy_proto_backend/src/impls/bevy_impls/sprite.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bevy::app::App;
use bevy::math::Vec2;
use bevy::prelude::Color;
use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect};
use bevy::sprite::{Anchor, Mesh2dHandle, Sprite, TextureAtlasSprite};

use crate::impls::macros::{from_to_default, register_schematic};
use crate::proto::ProtoAsset;
use crate::proto::{ProtoAsset, ProtoColor};
use bevy_proto_derive::impl_external_schematic;

pub(super) fn register(app: &mut App) {
Expand Down Expand Up @@ -39,7 +38,7 @@ impl_external_schematic! {
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct TextureAtlasSpriteInput {
pub color: Color,
pub color: ProtoColor,
pub index: usize,
pub flip_x: bool,
pub flip_y: bool,
Expand All @@ -50,7 +49,7 @@ impl_external_schematic! {
TextureAtlasSprite,
TextureAtlasSpriteInput,
|value: Input| Self {
color: value.color,
color: value.color.into(),
index: value.index,
flip_x: value.flip_x,
flip_y: value.flip_y,
Expand Down
7 changes: 3 additions & 4 deletions bevy_proto_backend/src/impls/bevy_impls/text.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use bevy::app::App;
use bevy::ecs::world::EntityMut;
use bevy::math::Vec2;
use bevy::prelude::Color;
use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect};
use bevy::text::{BreakLineOn, Text, Text2dBounds, TextAlignment, TextSection, TextStyle};

use crate::impls::macros::{from_to, from_to_default, from_to_input, register_schematic};
use crate::proto::ProtoAsset;
use crate::proto::{ProtoAsset, ProtoColor};
use crate::schematics::FromSchematicInput;
use bevy_proto_derive::impl_external_schematic;

Expand Down Expand Up @@ -77,15 +76,15 @@ impl_external_schematic! {
pub struct TextStyleInput {
pub font: ProtoAsset,
pub font_size: f32,
pub color: Color,
pub color: ProtoColor,
}
from_to_input! {
TextStyle,
TextStyleInput,
|input: Input, entity, tree| Self {
font: FromSchematicInput::from_input(input.font, entity, tree),
font_size: input.font_size,
color: input.color,
color: input.color.into(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions bevy_proto_backend/src/impls/bevy_impls/ui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::app::App;
use bevy::math::{Rect, Vec2};
use bevy::prelude::{BackgroundColor, Button, Color, Label};
use bevy::prelude::{BackgroundColor, Button, Label};
use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect};
use bevy::ui::{
AlignContent, AlignItems, AlignSelf, CalculatedClip, CalculatedSize, Direction, Display,
Expand All @@ -9,7 +9,7 @@ use bevy::ui::{
};

use crate::impls::macros::{from_to, from_to_default, register_schematic};
use crate::proto::ProtoAsset;
use crate::proto::{ProtoAsset, ProtoColor};
use bevy_proto_derive::impl_external_schematic;

pub(super) fn register(app: &mut App) {
Expand Down Expand Up @@ -51,11 +51,11 @@ impl_external_schematic! {
// ---
#[derive(Reflect, FromReflect)]
#[reflect(Default)]
pub struct BackgroundColorInput(pub Color);
pub struct BackgroundColorInput(pub ProtoColor);
from_to_default! {
BackgroundColor,
BackgroundColorInput,
|value: Input| Self(value.0)
|value: Input| Self(value.0.into())
}
}

Expand Down
3 changes: 3 additions & 0 deletions bevy_proto_backend/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ impl<T: Prototypical> Plugin for ProtoBackendPlugin<T> {
app.init_resource::<T::Config>();
}

#[cfg(feature = "bevy_render")]
app.register_type::<crate::proto::ProtoColor>();

app.register_type::<ProtoAsset>()
.register_type::<ProtoEntity>()
.register_type::<EntityAccess>()
Expand Down
Loading

0 comments on commit c84dd83

Please sign in to comment.