2023-04-06 01:07:41 +02:00
|
|
|
//! Tests how different transforms behave when clipped with `Overflow::Hidden`
|
Migrate from `LegacyColor` to `bevy_color::Color` (#12163)
# Objective
- As part of the migration process we need to a) see the end effect of
the migration on user ergonomics b) check for serious perf regressions
c) actually migrate the code
- To accomplish this, I'm going to attempt to migrate all of the
remaining user-facing usages of `LegacyColor` in one PR, being careful
to keep a clean commit history.
- Fixes #12056.
## Solution
I've chosen to use the polymorphic `Color` type as our standard
user-facing API.
- [x] Migrate `bevy_gizmos`.
- [x] Take `impl Into<Color>` in all `bevy_gizmos` APIs
- [x] Migrate sprites
- [x] Migrate UI
- [x] Migrate `ColorMaterial`
- [x] Migrate `MaterialMesh2D`
- [x] Migrate fog
- [x] Migrate lights
- [x] Migrate StandardMaterial
- [x] Migrate wireframes
- [x] Migrate clear color
- [x] Migrate text
- [x] Migrate gltf loader
- [x] Register color types for reflection
- [x] Remove `LegacyColor`
- [x] Make sure CI passes
Incidental improvements to ease migration:
- added `Color::srgba_u8`, `Color::srgba_from_array` and friends
- added `set_alpha`, `is_fully_transparent` and `is_fully_opaque` to the
`Alpha` trait
- add and immediately deprecate (lol) `Color::rgb` and friends in favor
of more explicit and consistent `Color::srgb`
- standardized on white and black for most example text colors
- added vector field traits to `LinearRgba`: ~~`Add`, `Sub`,
`AddAssign`, `SubAssign`,~~ `Mul<f32>` and `Div<f32>`. Multiplications
and divisions do not scale alpha. `Add` and `Sub` have been cut from
this PR.
- added `LinearRgba` and `Srgba` `RED/GREEN/BLUE`
- added `LinearRgba_to_f32_array` and `LinearRgba::to_u32`
## Migration Guide
Bevy's color types have changed! Wherever you used a
`bevy::render::Color`, a `bevy::color::Color` is used instead.
These are quite similar! Both are enums storing a color in a specific
color space (or to be more precise, using a specific color model).
However, each of the different color models now has its own type.
TODO...
- `Color::rgba`, `Color::rgb`, `Color::rbga_u8`, `Color::rgb_u8`,
`Color::rgb_from_array` are now `Color::srgba`, `Color::srgb`,
`Color::srgba_u8`, `Color::srgb_u8` and `Color::srgb_from_array`.
- `Color::set_a` and `Color::a` is now `Color::set_alpha` and
`Color::alpha`. These are part of the `Alpha` trait in `bevy_color`.
- `Color::is_fully_transparent` is now part of the `Alpha` trait in
`bevy_color`
- `Color::r`, `Color::set_r`, `Color::with_r` and the equivalents for
`g`, `b` `h`, `s` and `l` have been removed due to causing silent
relatively expensive conversions. Convert your `Color` into the desired
color space, perform your operations there, and then convert it back
into a polymorphic `Color` enum.
- `Color::hex` is now `Srgba::hex`. Call `.into` or construct a
`Color::Srgba` variant manually to convert it.
- `WireframeMaterial`, `ExtractedUiNode`, `ExtractedDirectionalLight`,
`ExtractedPointLight`, `ExtractedSpotLight` and `ExtractedSprite` now
store a `LinearRgba`, rather than a polymorphic `Color`
- `Color::rgb_linear` and `Color::rgba_linear` are now
`Color::linear_rgb` and `Color::linear_rgba`
- The various CSS color constants are no longer stored directly on
`Color`. Instead, they're defined in the `Srgba` color space, and
accessed via `bevy::color::palettes::css`. Call `.into()` on them to
convert them into a `Color` for quick debugging use, and consider using
the much prettier `tailwind` palette for prototyping.
- The `LIME_GREEN` color has been renamed to `LIMEGREEN` to comply with
the standard naming.
- Vector field arithmetic operations on `Color` (add, subtract, multiply
and divide by a f32) have been removed. Instead, convert your colors
into `LinearRgba` space, and perform your operations explicitly there.
This is particularly relevant when working with emissive or HDR colors,
whose color channel values are routinely outside of the ordinary 0 to 1
range.
- `Color::as_linear_rgba_f32` has been removed. Call
`LinearRgba::to_f32_array` instead, converting if needed.
- `Color::as_linear_rgba_u32` has been removed. Call
`LinearRgba::to_u32` instead, converting if needed.
- Several other color conversion methods to transform LCH or HSL colors
into float arrays or `Vec` types have been removed. Please reimplement
these externally or open a PR to re-add them if you found them
particularly useful.
- Various methods on `Color` such as `rgb` or `hsl` to convert the color
into a specific color space have been removed. Convert into
`LinearRgba`, then to the color space of your choice.
- Various implicitly-converting color value methods on `Color` such as
`r`, `g`, `b` or `h` have been removed. Please convert it into the color
space of your choice, then check these properties.
- `Color` no longer implements `AsBindGroup`. Store a `LinearRgba`
internally instead to avoid conversion costs.
---------
Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
Co-authored-by: Afonso Lage <lage.afonso@gmail.com>
Co-authored-by: Rob Parrett <robparrett@gmail.com>
Co-authored-by: Zachary Harrold <zac@harrold.com.au>
2024-02-29 14:35:12 -05:00
|
|
|
use bevy::{
|
|
|
|
color::palettes::css::DARK_GRAY, input::common_conditions::input_just_pressed, prelude::*,
|
|
|
|
};
|
2023-04-06 01:07:41 +02:00
|
|
|
use std::f32::consts::{FRAC_PI_2, PI, TAU};
|
|
|
|
|
|
|
|
const CONTAINER_SIZE: f32 = 150.0;
|
|
|
|
const HALF_CONTAINER_SIZE: f32 = CONTAINER_SIZE / 2.0;
|
|
|
|
const LOOP_LENGTH: f32 = 4.0;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
|
|
|
.add_plugins(DefaultPlugins)
|
2024-02-19 12:15:47 -07:00
|
|
|
.init_resource::<AnimationState>()
|
2023-04-06 01:07:41 +02:00
|
|
|
.add_systems(Startup, setup)
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
(
|
2024-02-19 12:15:47 -07:00
|
|
|
toggle_overflow.run_if(input_just_pressed(KeyCode::KeyO)),
|
|
|
|
next_container_size.run_if(input_just_pressed(KeyCode::KeyS)),
|
2023-04-06 01:07:41 +02:00
|
|
|
update_transform::<Move>,
|
|
|
|
update_transform::<Scale>,
|
|
|
|
update_transform::<Rotate>,
|
|
|
|
update_animation,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-02-19 12:15:47 -07:00
|
|
|
#[derive(Component)]
|
|
|
|
struct Instructions;
|
|
|
|
|
|
|
|
#[derive(Resource, Default)]
|
2023-04-06 01:07:41 +02:00
|
|
|
struct AnimationState {
|
|
|
|
playing: bool,
|
|
|
|
paused_at: f32,
|
|
|
|
paused_total: f32,
|
|
|
|
t: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct Container(u8);
|
|
|
|
|
|
|
|
trait UpdateTransform {
|
|
|
|
fn update(&self, t: f32, transform: &mut Transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct Move;
|
|
|
|
|
|
|
|
impl UpdateTransform for Move {
|
|
|
|
fn update(&self, t: f32, transform: &mut Transform) {
|
|
|
|
transform.translation.x = (t * TAU - FRAC_PI_2).sin() * HALF_CONTAINER_SIZE;
|
|
|
|
transform.translation.y = -(t * TAU - FRAC_PI_2).cos() * HALF_CONTAINER_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct Scale;
|
|
|
|
|
|
|
|
impl UpdateTransform for Scale {
|
|
|
|
fn update(&self, t: f32, transform: &mut Transform) {
|
|
|
|
transform.scale.x = 1.0 + 0.5 * (t * TAU).cos().max(0.0);
|
|
|
|
transform.scale.y = 1.0 + 0.5 * (t * TAU + PI).cos().max(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct Rotate;
|
|
|
|
|
|
|
|
impl UpdateTransform for Rotate {
|
|
|
|
fn update(&self, t: f32, transform: &mut Transform) {
|
|
|
|
transform.rotation = Quat::from_axis_angle(Vec3::Z, ((t * TAU).cos() * 45.0).to_radians());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
|
|
// Camera
|
2024-02-19 12:15:47 -07:00
|
|
|
|
2023-04-06 01:07:41 +02:00
|
|
|
commands.spawn(Camera2dBundle::default());
|
|
|
|
|
2024-02-19 12:15:47 -07:00
|
|
|
// Instructions
|
|
|
|
|
|
|
|
let text_style = TextStyle {
|
|
|
|
font_size: 20.,
|
|
|
|
..default()
|
|
|
|
};
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
TextBundle::from_sections([
|
|
|
|
TextSection::new(
|
|
|
|
"Next Overflow Setting (O)\nNext Container Size (S)\nToggle Animation (space)\n\n",
|
|
|
|
text_style.clone(),
|
|
|
|
),
|
|
|
|
TextSection::new(format!("{:?}", Overflow::clip()), text_style.clone()),
|
|
|
|
])
|
|
|
|
.with_style(Style {
|
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
top: Val::Px(12.0),
|
|
|
|
left: Val::Px(12.0),
|
|
|
|
..default()
|
|
|
|
}),
|
|
|
|
Instructions,
|
|
|
|
));
|
|
|
|
|
|
|
|
// Overflow Debug
|
|
|
|
|
2023-04-06 01:07:41 +02:00
|
|
|
commands
|
|
|
|
.spawn(NodeBundle {
|
|
|
|
style: Style {
|
Flatten UI `Style` properties that use `Size` + remove `Size` (#8548)
# Objective
- Simplify API and make authoring styles easier
See:
https://github.com/bevyengine/bevy/issues/8540#issuecomment-1536177102
## Solution
- The `size`, `min_size`, `max_size`, and `gap` properties have been
replaced by `width`, `height`, `min_width`, `min_height`, `max_width`,
`max_height`, `row_gap`, and `column_gap` properties
---
## Changelog
- Flattened `Style` properties that have a `Size` value directly into
`Style`
## Migration Guide
- The `size`, `min_size`, `max_size`, and `gap` properties have been
replaced by the `width`, `height`, `min_width`, `min_height`,
`max_width`, `max_height`, `row_gap`, and `column_gap` properties. Use
the new properties instead.
---------
Co-authored-by: ickshonpe <david.curthoys@googlemail.com>
2023-05-16 02:36:32 +01:00
|
|
|
width: Val::Percent(100.),
|
2024-02-19 12:15:47 -07:00
|
|
|
height: Val::Percent(100.),
|
|
|
|
justify_content: JustifyContent::Center,
|
|
|
|
align_items: AlignItems::Center,
|
2023-04-06 01:07:41 +02:00
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
})
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent
|
|
|
|
.spawn(NodeBundle {
|
|
|
|
style: Style {
|
2024-02-19 12:15:47 -07:00
|
|
|
display: Display::Grid,
|
|
|
|
grid_template_columns: RepeatedGridTrack::px(3, CONTAINER_SIZE),
|
|
|
|
grid_template_rows: RepeatedGridTrack::px(2, CONTAINER_SIZE),
|
|
|
|
row_gap: Val::Px(80.),
|
|
|
|
column_gap: Val::Px(80.),
|
2023-04-06 01:07:41 +02:00
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
})
|
|
|
|
.with_children(|parent| {
|
2024-02-19 12:15:47 -07:00
|
|
|
spawn_image(parent, &asset_server, Move);
|
|
|
|
spawn_image(parent, &asset_server, Scale);
|
|
|
|
spawn_image(parent, &asset_server, Rotate);
|
2023-04-06 01:07:41 +02:00
|
|
|
|
2024-02-19 12:15:47 -07:00
|
|
|
spawn_text(parent, &asset_server, Move);
|
|
|
|
spawn_text(parent, &asset_server, Scale);
|
|
|
|
spawn_text(parent, &asset_server, Rotate);
|
2023-04-06 01:07:41 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn_image(
|
|
|
|
parent: &mut ChildBuilder,
|
|
|
|
asset_server: &Res<AssetServer>,
|
|
|
|
update_transform: impl UpdateTransform + Component,
|
|
|
|
) {
|
|
|
|
spawn_container(parent, update_transform, |parent| {
|
|
|
|
parent.spawn(ImageBundle {
|
|
|
|
image: UiImage::new(asset_server.load("branding/bevy_logo_dark_big.png")),
|
|
|
|
style: Style {
|
Flatten UI `Style` properties that use `Size` + remove `Size` (#8548)
# Objective
- Simplify API and make authoring styles easier
See:
https://github.com/bevyengine/bevy/issues/8540#issuecomment-1536177102
## Solution
- The `size`, `min_size`, `max_size`, and `gap` properties have been
replaced by `width`, `height`, `min_width`, `min_height`, `max_width`,
`max_height`, `row_gap`, and `column_gap` properties
---
## Changelog
- Flattened `Style` properties that have a `Size` value directly into
`Style`
## Migration Guide
- The `size`, `min_size`, `max_size`, and `gap` properties have been
replaced by the `width`, `height`, `min_width`, `min_height`,
`max_width`, `max_height`, `row_gap`, and `column_gap` properties. Use
the new properties instead.
---------
Co-authored-by: ickshonpe <david.curthoys@googlemail.com>
2023-05-16 02:36:32 +01:00
|
|
|
height: Val::Px(100.),
|
2023-04-06 01:07:41 +02:00
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
top: Val::Px(-50.),
|
|
|
|
left: Val::Px(-200.),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn_text(
|
|
|
|
parent: &mut ChildBuilder,
|
|
|
|
asset_server: &Res<AssetServer>,
|
|
|
|
update_transform: impl UpdateTransform + Component,
|
|
|
|
) {
|
|
|
|
spawn_container(parent, update_transform, |parent| {
|
|
|
|
parent.spawn(TextBundle::from_section(
|
|
|
|
"Bevy",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
|
|
|
font_size: 120.0,
|
2023-11-03 05:57:38 -07:00
|
|
|
..default()
|
2023-04-06 01:07:41 +02:00
|
|
|
},
|
|
|
|
));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn_container(
|
|
|
|
parent: &mut ChildBuilder,
|
|
|
|
update_transform: impl UpdateTransform + Component,
|
|
|
|
spawn_children: impl FnOnce(&mut ChildBuilder),
|
|
|
|
) {
|
|
|
|
let mut transform = Transform::default();
|
|
|
|
|
|
|
|
update_transform.update(0.0, &mut transform);
|
|
|
|
|
|
|
|
parent
|
|
|
|
.spawn((
|
|
|
|
NodeBundle {
|
|
|
|
style: Style {
|
2024-02-19 12:15:47 -07:00
|
|
|
width: Val::Percent(100.),
|
|
|
|
height: Val::Percent(100.),
|
2023-04-06 01:07:41 +02:00
|
|
|
align_items: AlignItems::Center,
|
|
|
|
justify_content: JustifyContent::Center,
|
2023-04-17 23:23:52 +01:00
|
|
|
overflow: Overflow::clip(),
|
2023-04-06 01:07:41 +02:00
|
|
|
..default()
|
|
|
|
},
|
Migrate from `LegacyColor` to `bevy_color::Color` (#12163)
# Objective
- As part of the migration process we need to a) see the end effect of
the migration on user ergonomics b) check for serious perf regressions
c) actually migrate the code
- To accomplish this, I'm going to attempt to migrate all of the
remaining user-facing usages of `LegacyColor` in one PR, being careful
to keep a clean commit history.
- Fixes #12056.
## Solution
I've chosen to use the polymorphic `Color` type as our standard
user-facing API.
- [x] Migrate `bevy_gizmos`.
- [x] Take `impl Into<Color>` in all `bevy_gizmos` APIs
- [x] Migrate sprites
- [x] Migrate UI
- [x] Migrate `ColorMaterial`
- [x] Migrate `MaterialMesh2D`
- [x] Migrate fog
- [x] Migrate lights
- [x] Migrate StandardMaterial
- [x] Migrate wireframes
- [x] Migrate clear color
- [x] Migrate text
- [x] Migrate gltf loader
- [x] Register color types for reflection
- [x] Remove `LegacyColor`
- [x] Make sure CI passes
Incidental improvements to ease migration:
- added `Color::srgba_u8`, `Color::srgba_from_array` and friends
- added `set_alpha`, `is_fully_transparent` and `is_fully_opaque` to the
`Alpha` trait
- add and immediately deprecate (lol) `Color::rgb` and friends in favor
of more explicit and consistent `Color::srgb`
- standardized on white and black for most example text colors
- added vector field traits to `LinearRgba`: ~~`Add`, `Sub`,
`AddAssign`, `SubAssign`,~~ `Mul<f32>` and `Div<f32>`. Multiplications
and divisions do not scale alpha. `Add` and `Sub` have been cut from
this PR.
- added `LinearRgba` and `Srgba` `RED/GREEN/BLUE`
- added `LinearRgba_to_f32_array` and `LinearRgba::to_u32`
## Migration Guide
Bevy's color types have changed! Wherever you used a
`bevy::render::Color`, a `bevy::color::Color` is used instead.
These are quite similar! Both are enums storing a color in a specific
color space (or to be more precise, using a specific color model).
However, each of the different color models now has its own type.
TODO...
- `Color::rgba`, `Color::rgb`, `Color::rbga_u8`, `Color::rgb_u8`,
`Color::rgb_from_array` are now `Color::srgba`, `Color::srgb`,
`Color::srgba_u8`, `Color::srgb_u8` and `Color::srgb_from_array`.
- `Color::set_a` and `Color::a` is now `Color::set_alpha` and
`Color::alpha`. These are part of the `Alpha` trait in `bevy_color`.
- `Color::is_fully_transparent` is now part of the `Alpha` trait in
`bevy_color`
- `Color::r`, `Color::set_r`, `Color::with_r` and the equivalents for
`g`, `b` `h`, `s` and `l` have been removed due to causing silent
relatively expensive conversions. Convert your `Color` into the desired
color space, perform your operations there, and then convert it back
into a polymorphic `Color` enum.
- `Color::hex` is now `Srgba::hex`. Call `.into` or construct a
`Color::Srgba` variant manually to convert it.
- `WireframeMaterial`, `ExtractedUiNode`, `ExtractedDirectionalLight`,
`ExtractedPointLight`, `ExtractedSpotLight` and `ExtractedSprite` now
store a `LinearRgba`, rather than a polymorphic `Color`
- `Color::rgb_linear` and `Color::rgba_linear` are now
`Color::linear_rgb` and `Color::linear_rgba`
- The various CSS color constants are no longer stored directly on
`Color`. Instead, they're defined in the `Srgba` color space, and
accessed via `bevy::color::palettes::css`. Call `.into()` on them to
convert them into a `Color` for quick debugging use, and consider using
the much prettier `tailwind` palette for prototyping.
- The `LIME_GREEN` color has been renamed to `LIMEGREEN` to comply with
the standard naming.
- Vector field arithmetic operations on `Color` (add, subtract, multiply
and divide by a f32) have been removed. Instead, convert your colors
into `LinearRgba` space, and perform your operations explicitly there.
This is particularly relevant when working with emissive or HDR colors,
whose color channel values are routinely outside of the ordinary 0 to 1
range.
- `Color::as_linear_rgba_f32` has been removed. Call
`LinearRgba::to_f32_array` instead, converting if needed.
- `Color::as_linear_rgba_u32` has been removed. Call
`LinearRgba::to_u32` instead, converting if needed.
- Several other color conversion methods to transform LCH or HSL colors
into float arrays or `Vec` types have been removed. Please reimplement
these externally or open a PR to re-add them if you found them
particularly useful.
- Various methods on `Color` such as `rgb` or `hsl` to convert the color
into a specific color space have been removed. Convert into
`LinearRgba`, then to the color space of your choice.
- Various implicitly-converting color value methods on `Color` such as
`r`, `g`, `b` or `h` have been removed. Please convert it into the color
space of your choice, then check these properties.
- `Color` no longer implements `AsBindGroup`. Store a `LinearRgba`
internally instead to avoid conversion costs.
---------
Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
Co-authored-by: Afonso Lage <lage.afonso@gmail.com>
Co-authored-by: Rob Parrett <robparrett@gmail.com>
Co-authored-by: Zachary Harrold <zac@harrold.com.au>
2024-02-29 14:35:12 -05:00
|
|
|
background_color: DARK_GRAY.into(),
|
2023-04-06 01:07:41 +02:00
|
|
|
..default()
|
|
|
|
},
|
|
|
|
Container(0),
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent
|
|
|
|
.spawn((
|
|
|
|
NodeBundle {
|
|
|
|
style: Style {
|
|
|
|
align_items: AlignItems::Center,
|
|
|
|
justify_content: JustifyContent::Center,
|
|
|
|
top: Val::Px(transform.translation.x),
|
|
|
|
left: Val::Px(transform.translation.y),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
transform,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
update_transform,
|
|
|
|
))
|
|
|
|
.with_children(spawn_children);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update_animation(
|
|
|
|
mut animation: ResMut<AnimationState>,
|
|
|
|
time: Res<Time>,
|
2023-12-06 21:32:34 +01:00
|
|
|
keys: Res<ButtonInput<KeyCode>>,
|
2023-04-06 01:07:41 +02:00
|
|
|
) {
|
2024-02-19 12:15:47 -07:00
|
|
|
let delta = time.elapsed_seconds();
|
2023-04-06 01:07:41 +02:00
|
|
|
|
|
|
|
if keys.just_pressed(KeyCode::Space) {
|
|
|
|
animation.playing = !animation.playing;
|
|
|
|
|
|
|
|
if !animation.playing {
|
2024-02-19 12:15:47 -07:00
|
|
|
animation.paused_at = delta;
|
2023-04-06 01:07:41 +02:00
|
|
|
} else {
|
2024-02-19 12:15:47 -07:00
|
|
|
animation.paused_total += delta - animation.paused_at;
|
2023-04-06 01:07:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if animation.playing {
|
2024-02-19 12:15:47 -07:00
|
|
|
animation.t = (delta - animation.paused_total) % LOOP_LENGTH / LOOP_LENGTH;
|
2023-04-06 01:07:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update_transform<T: UpdateTransform + Component>(
|
|
|
|
animation: Res<AnimationState>,
|
|
|
|
mut containers: Query<(&mut Transform, &mut Style, &T)>,
|
|
|
|
) {
|
|
|
|
for (mut transform, mut style, update_transform) in &mut containers {
|
|
|
|
update_transform.update(animation.t, &mut transform);
|
|
|
|
|
|
|
|
style.left = Val::Px(transform.translation.x);
|
|
|
|
style.top = Val::Px(transform.translation.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 21:32:34 +01:00
|
|
|
fn toggle_overflow(
|
|
|
|
mut containers: Query<&mut Style, With<Container>>,
|
2024-02-19 12:15:47 -07:00
|
|
|
mut instructions: Query<&mut Text, With<Instructions>>,
|
2023-12-06 21:32:34 +01:00
|
|
|
) {
|
2024-02-19 12:15:47 -07:00
|
|
|
for mut style in &mut containers {
|
|
|
|
style.overflow = match style.overflow {
|
|
|
|
Overflow {
|
|
|
|
x: OverflowAxis::Visible,
|
|
|
|
y: OverflowAxis::Visible,
|
|
|
|
} => Overflow::clip_y(),
|
|
|
|
Overflow {
|
|
|
|
x: OverflowAxis::Visible,
|
|
|
|
y: OverflowAxis::Clip,
|
|
|
|
} => Overflow::clip_x(),
|
|
|
|
Overflow {
|
|
|
|
x: OverflowAxis::Clip,
|
|
|
|
y: OverflowAxis::Visible,
|
|
|
|
} => Overflow::clip(),
|
|
|
|
_ => Overflow::visible(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut text = instructions.single_mut();
|
|
|
|
text.sections[1].value = format!("{:?}", style.overflow);
|
2023-04-06 01:07:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 12:15:47 -07:00
|
|
|
fn next_container_size(mut containers: Query<(&mut Style, &mut Container)>) {
|
|
|
|
for (mut style, mut container) in &mut containers {
|
|
|
|
container.0 = (container.0 + 1) % 3;
|
|
|
|
|
|
|
|
style.width = match container.0 {
|
|
|
|
2 => Val::Percent(30.),
|
|
|
|
_ => Val::Percent(100.),
|
|
|
|
};
|
|
|
|
style.height = match container.0 {
|
|
|
|
1 => Val::Percent(30.),
|
|
|
|
_ => Val::Percent(100.),
|
|
|
|
};
|
2023-04-06 01:07:41 +02:00
|
|
|
}
|
|
|
|
}
|