Skip to content

Commit

Permalink
Merge pull request #66 from bytestring-net/dev
Browse files Browse the repository at this point in the history
Clippy + Reflection
  • Loading branch information
IDEDARY authored Aug 29, 2024
2 parents d06e6e5 + a524992 commit 00d7706
Show file tree
Hide file tree
Showing 23 changed files with 370 additions and 378 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_lunex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[dependencies]
bevy = { workspace = true }
colored = { workspace = true }
lunex_engine = { workspace = true, features = ["bevy"] }
lunex_engine = { workspace = true }
bevy_kira_audio = { workspace = true, optional = true }
bevy_mod_picking = { workspace = true }

Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_lunex/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![doc = include_str!("../README.md")]
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]

// #==============================#
// #=== IMPORTS FOR THIS CRATE ===#
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_lunex/src/logic/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub struct SetUiLayout {
fn apply_event_set_ui_layout(mut events: EventReader<SetUiLayout>, mut query: Query<&mut UiLayout>) {
for event in events.read() {
if let Ok(mut layout) = query.get_mut(event.target) {
if layout.clone() != event.layout{
if *layout != event.layout{
*layout = event.layout;
}
}
Expand Down
26 changes: 18 additions & 8 deletions crates/bevy_lunex/src/logic/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ pub struct UiAnimator<S: UiState> {
impl <S: UiState> UiAnimator<S> {
/// Creates new struct
pub fn new() -> Self {
UiAnimator {
marker: PhantomData,
animation_direction: -1.0,
animation_transition: 0.0,
receiver: false,
animation_speed_backward: 8.0,
animation_speed_forward: 8.0,
}
Self::default()
}
/// Marks this hover as receiver
pub fn receiver(mut self, receiver: bool) -> Self {
Expand All @@ -80,6 +73,18 @@ impl <S: UiState> UiAnimator<S> {
self.animation_direction == 1.0
}
}
impl <S: UiState> Default for UiAnimator<S> {
fn default() -> Self {
Self {
marker: PhantomData,
animation_direction: -1.0,
animation_transition: 0.0,
receiver: false,
animation_speed_backward: 8.0,
animation_speed_forward: 8.0,
}
}
}
fn ui_animation<S: UiState>(time: Res<Time>, mut query: Query<&mut UiAnimator<S>>) {
for mut control in &mut query {
if control.receiver { continue }
Expand Down Expand Up @@ -229,6 +234,11 @@ impl <T:Component, N:Default + Component, S: UiState> Plugin for StatePlugin<T,N
.add_systems(Update, send_layout_to_node::<T, N, S>.in_set(UiSystems::Send).before(send_content_size_to_node::<T, N>));
}
}
impl <T:Component, N:Default + Component, S: UiState> Default for StatePlugin<T,N,S> {
fn default() -> Self {
Self::new()
}
}

pub struct DefaultStatesPlugin;
impl Plugin for DefaultStatesPlugin {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_lunex/src/logic/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub trait LerpColor {
}
impl LerpColor for Color {
fn lerp(&self, color: Color, value: f32) -> Color {
let c1: Hsla = self.clone().into();
let c1: Hsla = (*self).into();
let c2: Hsla = color.into();
Color::hsla(c1.hue.lerp(c2.hue, value), c1.saturation.lerp(c2.saturation, value), c1.lightness.lerp(c2.lightness, value), c1.alpha.lerp(c2.alpha, value))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_lunex/src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn lunex_picking(
return None;
}

let pos = if !element.is_some() { dimension.size.invert_y() / 2.0 } else { Vec2::ZERO };
let pos = if element.is_none() { dimension.size.invert_y() / 2.0 } else { Vec2::ZERO };

let rect = Rect::from_center_size(pos, dimension.size);

Expand Down
42 changes: 21 additions & 21 deletions crates/bevy_lunex/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl UiState for Outro {

/// This struct marks [`UiTree`] entity to receive piped [`Camera`] size and position to its [`Dimension`] and [`Transform`] component.
#[derive(Component, Debug, Default, Clone, Copy, PartialEq)]
pub struct MovableByCamera;
pub struct SourceFromCamera;

/// This struct is used to mark linked UI entities as elements for easier rendering.
/// They are picked up by different systems, that ensure their piped [`Transform`] is centered,
Expand All @@ -73,7 +73,7 @@ pub struct Element;

/// This struct holds rectangular data. If the component covers some kind of 2D area, it should be stored in this component.
/// Lunex uses this component to mirror node size in & out from parent [`UiTree`].
#[derive(Component, Debug, Default, Clone, Copy, PartialEq)]
#[derive(Component, Debug, Default, Clone, Copy, PartialEq, Reflect)]
pub struct Dimension {
pub size: Vec2,
}
Expand All @@ -86,7 +86,7 @@ impl Dimension {
}

/// # WIP - used for Div layout
#[derive(Component, Debug, Default, Clone, Copy, PartialEq)]
#[derive(Component, Debug, Default, Clone, Copy, PartialEq, Reflect)]
pub struct UiContent {
pub size: Vec2,
}
Expand All @@ -98,7 +98,7 @@ impl UiContent {


/// This struct is used to specify size of the font in UI.
#[derive(Component, Debug, Clone, Copy, PartialEq)]
#[derive(Component, Debug, Clone, Copy, PartialEq, Reflect)]
pub struct UiTextSize {
/// The unit type and scale value of the text height
pub size: UiValueType<f32>,
Expand All @@ -123,7 +123,7 @@ impl UiTextSize {
// #=======================#
// #=== MAIN COMPONENTS ===#

#[derive(Component, Debug, Copy, Clone, PartialEq)]
#[derive(Component, Debug, Copy, Clone, PartialEq, Reflect)]
pub struct UiLayout<S = Base> {
pub layout: Layout,
state: PhantomData<S>,
Expand Down Expand Up @@ -205,39 +205,39 @@ pub trait PackageLayout {
}

// Implement packaging
impl <S> Into<UiLayout<S>> for ui::Boundary {
fn into(self) -> UiLayout<S> {
self.pack::<S>()
impl <S> From<ui::Boundary> for UiLayout<S> {
fn from(val: ui::Boundary) -> Self {
val.pack::<S>()
}
}
impl PackageLayout for ui::Boundary {
fn pack<S>(self) -> UiLayout<S> {
UiLayout::<S>::from(self)
}
}
impl <S> Into<UiLayout<S>> for ui::Window {
fn into(self) -> UiLayout<S> {
self.pack::<S>()
impl <S> From<ui::Window> for UiLayout<S> {
fn from(val: ui::Window) -> Self {
val.pack::<S>()
}
}
impl PackageLayout for ui::Window {
fn pack<S>(self) -> UiLayout<S> {
UiLayout::<S>::from(self)
}
}
impl <S> Into<UiLayout<S>> for ui::Solid {
fn into(self) -> UiLayout<S> {
self.pack::<S>()
impl <S> From<ui::Solid> for UiLayout<S> {
fn from(val: ui::Solid) -> Self {
val.pack::<S>()
}
}
impl PackageLayout for ui::Solid {
fn pack<S>(self) -> UiLayout<S> {
UiLayout::<S>::from(self)
}
}
impl <S> Into<UiLayout<S>> for ui::Div {
fn into(self) -> UiLayout<S> {
self.pack::<S>()
impl <S> From<ui::Div> for UiLayout<S> {
fn from(val: ui::Div) -> Self {
val.pack::<S>()
}
}
impl PackageLayout for ui::Div {
Expand Down Expand Up @@ -269,7 +269,7 @@ impl Default for UiLayoutController {

/// This struct is a string reference to a specific node in a parent [`UiTree`].
/// Lunex uses this component to locate what data this entity should be working with.
#[derive(Component, Debug, Clone, PartialEq)]
#[derive(Component, Debug, Clone, PartialEq, Reflect)]
pub struct UiLink<T = MainUi> {
pub path: String,
marker: PhantomData<T>,
Expand All @@ -289,15 +289,15 @@ impl <T> UiLink<T> {
}
pub fn new() -> Self {
UiLink {
path: format!("/"),
path: "/".to_string(),
marker: PhantomData,
}
}
}
impl <T> Default for UiLink<T> {
fn default() -> Self {
UiLink {
path: String::new(),
path: "/".to_string(),
marker: PhantomData,
}
}
Expand All @@ -307,7 +307,7 @@ impl <T> Default for UiLink<T> {
/// This struct holds depth bias that will be relatively added to `depth` in the layout calculation.
/// Nodes with higher depth bias will be placed on top of nodes with lower depth bias.
/// It is recursive.
#[derive(Component, Debug, Default, Clone, Copy, PartialEq)]
#[derive(Component, Debug, Default, Clone, Copy, PartialEq, Reflect)]
pub struct UiDepthBias (pub f32);


Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_lunex/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lunex_engine::*;
/// * Generic `(N)` - Node data schema struct defining what can be stored in [`UiNode`]
/// * Generic `(T)` - Marker component grouping entities into one widget type
pub fn compute_ui<T:Component, N:Default + Component>(
mut query: Query<(&Dimension, &mut UiTree<T, N>, Option<&MovableByCamera>), (With<UiLink<T>>, Or<(Changed<UiTree<T, N>>, Changed<Dimension>)>)>,
mut query: Query<(&Dimension, &mut UiTree<T, N>, Option<&SourceFromCamera>), (With<UiLink<T>>, Or<(Changed<UiTree<T, N>>, Changed<Dimension>)>)>,
window: Query<&bevy::window::Window, With<PrimaryWindow>>,
) {
let scale = if let Ok(window) = window.get_single() { window.resolution.scale_factor() } else { 1.0 };
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn debug_print_tree<T:Component, N:Default + Component>(
/// is marked with `(T)` component at the same time.
pub fn fetch_dimension_from_camera<T:Component, N:Default + Component>(
source: Query<(&Camera, Option<&OrthographicProjection>), (With<T>, Changed<Camera>)>,
mut destination: Query<&mut Dimension, (With<UiTree<T, N>>, With<MovableByCamera>)>
mut destination: Query<&mut Dimension, (With<UiTree<T, N>>, With<SourceFromCamera>)>
) {
// Undesired behaviour if source.len() > 1
for (cam, o_projection) in &source {
Expand All @@ -104,7 +104,7 @@ pub fn fetch_dimension_from_camera<T:Component, N:Default + Component>(
}
}

/// This system takes [`Camera`] data and overwrites querried [`Transform`] + [`MovableByCamera`].
/// This system takes [`Camera`] data and overwrites querried [`Transform`] + [`SourceFromCamera`].
/// It is mainly used to pipe [`Camera`] data into [`UiTree`] for positioning.
/// ## 📦 Types
/// * Generic `(N)` - Node data schema struct defining what can be stored in [`UiNode`]
Expand All @@ -115,7 +115,7 @@ pub fn fetch_dimension_from_camera<T:Component, N:Default + Component>(
/// is marked with `(T)` component at the same time.
pub fn fetch_transform_from_camera<T:Component, N:Default + Component>(
source: Query<(&Camera, Option<&OrthographicProjection>), (With<T>, Changed<Camera>)>,
mut destination: Query<&mut Transform, (With<UiTree<T, N>>, With<MovableByCamera>)>,
mut destination: Query<&mut Transform, (With<UiTree<T, N>>, With<SourceFromCamera>)>,
window: Query<&bevy::window::Window, With<PrimaryWindow>>,
) {
// Undesired behaviour if source.len() > 1
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn fetch_transform_from_camera<T:Component, N:Default + Component>(
/// Otherwise, it will lead to value overwriting. Just make sure only one camera
/// is marked with `(T)` component at the same time.
pub fn touch_camera_if_uitree_added<T:Component, N:Default + Component>(
query: Query<Entity, (Added<UiTree<T, N>>, With<MovableByCamera>)>,
query: Query<Entity, (Added<UiTree<T, N>>, With<SourceFromCamera>)>,
mut camera: Query<&mut Camera, With<T>>,
){
if !query.is_empty() {
Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn send_stack_to_node<T:Component, N:Default + Component>(
if let Some(container) = node.obtain_data_mut() {
#[cfg(feature = "verbose")]
info!("{} {} - Received Stack data", "->".blue(), link.path.yellow().bold());
container.stack = *stack;
container.stack = stack.clone();
}
}
}
Expand Down Expand Up @@ -386,7 +386,7 @@ pub fn element_sprite_size_from_dimension<T: Component>(
/// ## 📦 Types
/// * Generic `(T)` - Marker component grouping entities into one widget type
pub fn element_image_size_from_dimension<T: Component>(
query: Query<(&Handle<Image>, &Dimension), (With<UiLink<T>>, With<Element>, With<MovableByCamera>, Changed<Dimension>)>,
query: Query<(&Handle<Image>, &Dimension), (With<UiLink<T>>, With<Element>, With<SourceFromCamera>, Changed<Dimension>)>,
mut images: ResMut<Assets<Image>>,
) {
for (handle, dimension) in &query {
Expand Down
1 change: 0 additions & 1 deletion crates/lunex_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
thiserror.workspace = true

[features]
bevy = []
2 changes: 1 addition & 1 deletion crates/lunex_engine/src/core/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl <N:Default + Component> UiNodeComputeTrait for UiNode<N> {

} else { return; };

if skip == false {
if !skip {
if is_parametric {
//compute divs with inherited scale
//self.compute_content(parent.size, Vec4::ZERO, absolute_scale, font_size);
Expand Down
18 changes: 9 additions & 9 deletions crates/lunex_engine/src/core/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ impl Rectangle2D {
self
}
}
impl Into<Rectangle3D> for Rectangle2D {
fn into(self) -> Rectangle3D {
impl From<Rectangle2D> for Rectangle3D {
fn from(val: Rectangle2D) -> Self {
Rectangle3D {
pos: self.pos.extend(0.0),
size: self.size,
pos: val.pos.extend(0.0),
size: val.size,
..Default::default()
}
}
Expand All @@ -112,17 +112,17 @@ impl Rectangle3D {
}
}
}
impl Into<Rectangle2D> for Rectangle3D {
fn into(self) -> Rectangle2D {
impl From<Rectangle3D> for Rectangle2D {
fn from(val: Rectangle3D) -> Self {
Rectangle2D {
pos: self.pos.truncate(),
size: self.size,
pos: val.pos.truncate(),
size: val.size,
}
}
}
impl NiceDisplay for Rectangle3D {
fn to_nicestr(&self) -> String {
let text = format!("[pos: {} size: {}]", self.pos.to_string(), self.size.to_string());
let text = format!("[pos: {} size: {}]", self.pos, self.size);
format!("{} {}", "Computed".bright_magenta(), text.black())
}
}
Expand Down
Loading

0 comments on commit 00d7706

Please sign in to comment.