From 545c7017e7eccd763db99cdcd181178f415742f0 Mon Sep 17 00:00:00 2001 From: musjj <72612857+musjj@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:10:15 +0700 Subject: [PATCH 1/3] Implement Clone, Copy and Debug on possible structs and enums --- particles/src/lib.rs | 8 +++++++- physics-platformer/src/lib.rs | 2 ++ profiler/src/lib.rs | 2 ++ src/audio.rs | 4 ++++ src/camera.rs | 4 ++-- src/exec.rs | 3 ++- src/experimental/animation.rs | 3 ++- src/experimental/coroutines.rs | 2 ++ src/experimental/scene.rs | 3 +++ src/input.rs | 2 +- src/material.rs | 1 + src/models.rs | 3 ++- src/quad_gl.rs | 9 +++++++-- src/shapes.rs | 2 +- src/telemetry.rs | 5 ++++- src/text.rs | 2 +- src/text/atlas.rs | 1 + src/texture.rs | 27 ++++++++++++++++----------- src/ui.rs | 1 + src/ui/cursor.rs | 6 +++--- src/ui/input.rs | 6 +++--- src/ui/render/mesh_rasterizer.rs | 2 +- src/ui/render/painter.rs | 4 ++-- src/ui/style.rs | 1 + src/ui/widgets/button.rs | 1 + src/ui/widgets/checkbox.rs | 1 + src/ui/widgets/combobox.rs | 1 + src/ui/widgets/drag.rs | 1 + src/ui/widgets/editbox.rs | 1 + src/ui/widgets/editbox/text_editor.rs | 2 +- src/ui/widgets/group.rs | 3 ++- src/ui/widgets/input.rs | 1 + src/ui/widgets/label.rs | 1 + src/ui/widgets/popup.rs | 1 + src/ui/widgets/slider.rs | 1 + src/ui/widgets/tabbar.rs | 1 + src/ui/widgets/texture.rs | 1 + src/ui/widgets/tree_node.rs | 2 ++ src/ui/widgets/window.rs | 1 + tiled/src/lib.rs | 9 +++++---- tiled/src/tiled.rs | 8 ++++---- 41 files changed, 97 insertions(+), 42 deletions(-) diff --git a/particles/src/lib.rs b/particles/src/lib.rs index 963b9d8e..1b331969 100644 --- a/particles/src/lib.rs +++ b/particles/src/lib.rs @@ -115,6 +115,7 @@ impl From<&ColorSerializable> for Color { } #[cfg_attr(feature = "nanoserde", derive(DeJson, SerJson))] +#[derive(Clone, Copy, Debug)] pub struct Vec2Serializable { x: f32, y: f32, @@ -415,7 +416,7 @@ impl BlendMode { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] #[cfg_attr(feature = "nanoserde", derive(DeJson, SerJson))] pub struct AtlasConfig { n: u16, @@ -484,6 +485,7 @@ impl Default for EmitterConfig { } #[repr(C)] +#[derive(Clone, Debug)] struct GpuParticle { pos: Vec4, uv: Vec4, @@ -491,6 +493,7 @@ struct GpuParticle { color: Vec4, } +#[derive(Clone, Debug)] struct CpuParticle { velocity: Vec2, angular_velocity: f32, @@ -500,6 +503,7 @@ struct CpuParticle { initial_size: f32, } +#[derive(Clone, Debug)] pub struct Emitter { pipeline: Pipeline, bindings: Bindings, @@ -995,6 +999,7 @@ impl Emitter { /// Multiple emitters drawn simultaneously. /// Will reuse as much GPU resources as possible, so should be more efficient than /// just Vec +#[derive(Clone, Debug)] pub struct EmittersCache { emitter: Emitter, emitters_cache: Vec, @@ -1112,6 +1117,7 @@ mod shader { } #[repr(C)] + #[derive(Clone, Copy, Debug)] pub struct Uniforms { pub mvp: Mat4, pub local_coords: f32, diff --git a/physics-platformer/src/lib.rs b/physics-platformer/src/lib.rs index 2b3850f2..34c743d5 100644 --- a/physics-platformer/src/lib.rs +++ b/physics-platformer/src/lib.rs @@ -21,6 +21,7 @@ impl Tile { } } } +#[derive(Clone, Debug)] pub struct StaticTiledLayer { static_colliders: Vec, tile_width: f32, @@ -29,6 +30,7 @@ pub struct StaticTiledLayer { tag: u8, } +#[derive(Clone, Debug)] pub struct World { static_tiled_layers: Vec, solids: Vec<(Solid, Collider)>, diff --git a/profiler/src/lib.rs b/profiler/src/lib.rs index bf13e59b..5091657d 100644 --- a/profiler/src/lib.rs +++ b/profiler/src/lib.rs @@ -4,6 +4,7 @@ use macroquad::prelude::*; use macroquad::ui::{hash, root_ui, widgets::Window, Ui}; +#[derive(Clone, Debug)] pub struct ProfilerState { fps_buffer: Vec, frames_buffer: Vec, @@ -12,6 +13,7 @@ pub struct ProfilerState { paused: bool, } +#[derive(Clone, Copy, Debug)] pub struct ProfilerParams { pub fps_counter_pos: Vec2, } diff --git a/src/audio.rs b/src/audio.rs index c76b6ccd..05b9c3bd 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -13,6 +13,7 @@ pub use quad_snd::PlaySoundParams; mod dummy_audio { use crate::audio::PlaySoundParams; + #[derive(Clone, Copy, Debug)] pub struct AudioContext {} impl AudioContext { @@ -27,6 +28,7 @@ mod dummy_audio { pub fn resume(&mut self) {} } + #[derive(Clone, Copy, Debug)] pub struct Sound {} impl Sound { @@ -54,11 +56,13 @@ mod dummy_audio { use dummy_audio::{AudioContext as QuadSndContext, Sound as QuadSndSound}; #[cfg(not(feature = "audio"))] +#[derive(Clone, Copy, Debug)] pub struct PlaySoundParams { pub looped: bool, pub volume: f32, } +#[derive(Clone, Copy, Debug)] pub struct AudioContext { native_ctx: QuadSndContext, } diff --git a/src/camera.rs b/src/camera.rs index 0f0f3e12..3da2eee0 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -15,7 +15,7 @@ pub trait Camera { fn viewport(&self) -> Option<(i32, i32, i32, i32)>; } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Camera2D { /// Rotation in degrees. pub rotation: f32, @@ -151,7 +151,7 @@ pub enum Projection { Orthographics, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Camera3D { /// Camera position. pub position: Vec3, diff --git a/src/exec.rs b/src/exec.rs index aed90fc9..17b86135 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -6,7 +6,7 @@ use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; use crate::Error; // Returns Pending as long as its inner bool is false. -#[derive(Default)] +#[derive(Default, Clone, Copy, Debug)] pub struct FrameFuture { done: bool, } @@ -27,6 +27,7 @@ impl Future for FrameFuture { } } +#[derive(Clone, Debug)] pub struct FileLoadingFuture { pub contents: Arc, Error>>>>, } diff --git a/src/experimental/animation.rs b/src/experimental/animation.rs index 815280eb..65e35ce8 100644 --- a/src/experimental/animation.rs +++ b/src/experimental/animation.rs @@ -71,6 +71,7 @@ pub struct Animation { } /// Specific animation frame +#[derive(Clone, Copy, Debug)] pub struct AnimationFrame { /// Area of current frame in source image pub source_rect: Rect, @@ -79,7 +80,7 @@ pub struct AnimationFrame { } /// Main definition of all animations for specific image -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct AnimatedSprite { tile_width: f32, tile_height: f32, diff --git a/src/experimental/coroutines.rs b/src/experimental/coroutines.rs index c638f3a2..b2a1aa84 100644 --- a/src/experimental/coroutines.rs +++ b/src/experimental/coroutines.rs @@ -233,6 +233,7 @@ pub fn stop_coroutine(coroutine: Coroutine) { context.coroutines.free(coroutine.id); } +#[derive(Clone, Copy, Debug)] pub struct TimerDelayFuture { pub(crate) remaining_time: f32, } @@ -272,6 +273,7 @@ pub mod tweens { task::{Context, Poll}, }; + #[derive(Clone, Copy, Debug)] pub struct LinearTweenFuture where T: Copy + Add + Sub + Mul, diff --git a/src/experimental/scene.rs b/src/experimental/scene.rs index 82eb7bcd..c6c5a7aa 100644 --- a/src/experimental/scene.rs +++ b/src/experimental/scene.rs @@ -80,6 +80,7 @@ impl Handle { pub fn as_trait(&self) {} } +#[derive(Clone, Copy, Debug)] pub(crate) struct Lens { handle: HandleUntyped, offset: isize, @@ -181,6 +182,7 @@ impl Drop for RefMut { } } +#[derive(Clone, Debug)] pub struct RefMutAny<'a> { data: *mut (), used: *mut bool, @@ -568,6 +570,7 @@ impl Scene { } } +#[derive(Clone, Copy, Debug)] pub struct MagicVecIterator { n: usize, len: usize, diff --git a/src/input.rs b/src/input.rs index 0fb3e8b6..a8ba7bc3 100644 --- a/src/input.rs +++ b/src/input.rs @@ -28,7 +28,7 @@ impl From for TouchPhase { } } -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct Touch { pub id: u64, pub phase: TouchPhase, diff --git a/src/material.rs b/src/material.rs index abc0082d..3f8d8853 100644 --- a/src/material.rs +++ b/src/material.rs @@ -41,6 +41,7 @@ impl Material { /// Params used for material loading. /// It is not possible to change material params at runtime, so this /// struct is used only once - at "load_material". +#[derive(Clone, Debug)] pub struct MaterialParams { /// miniquad pipeline configuration for this material. /// Things like blending, culling, depth dest diff --git a/src/models.rs b/src/models.rs index 3a0edce3..e190b8fa 100644 --- a/src/models.rs +++ b/src/models.rs @@ -22,6 +22,7 @@ impl From for crate::quad_gl::VertexInterop { } } +#[derive(Clone, Debug)] pub struct Mesh { pub vertices: Vec, pub indices: Vec, @@ -453,7 +454,7 @@ pub fn draw_cube_wires(position: Vec3, size: Vec3, color: Color) { ); } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct DrawSphereParams { pub rings: usize, pub slices: usize, diff --git a/src/quad_gl.rs b/src/quad_gl.rs index 5e4298a2..76f75ec4 100644 --- a/src/quad_gl.rs +++ b/src/quad_gl.rs @@ -17,6 +17,7 @@ pub enum DrawMode { #[derive(Debug, Clone, Copy, PartialEq)] pub struct GlPipeline(usize); +#[derive(Clone, Debug)] struct DrawCall { vertices: Vec, indices: Vec, @@ -131,6 +132,7 @@ impl DrawCall { } } +#[derive(Clone, Debug)] struct MagicSnapshotter { pipeline: Pipeline, bindings: Bindings, @@ -200,7 +202,7 @@ mod snapshotter_shader { } #[repr(C)] - #[derive(Debug)] + #[derive(Clone, Copy, Debug)] pub struct Uniforms {} } @@ -323,6 +325,7 @@ impl MagicSnapshotter { } } +#[derive(Clone, Debug)] struct GlState { texture: Option, draw_mode: DrawMode, @@ -352,7 +355,7 @@ struct Uniform { byte_offset: usize, } -#[derive(Clone)] +#[derive(Clone, Debug)] struct PipelineExt { pipeline: miniquad::Pipeline, wants_screen_texture: bool, @@ -406,6 +409,7 @@ impl PipelineExt { } } +#[derive(Clone, Debug)] struct PipelinesStorage { pipelines: [Option; Self::MAX_PIPELINES], pipelines_amount: usize, @@ -586,6 +590,7 @@ impl PipelinesStorage { } } +#[derive(Clone, Debug)] pub struct QuadGl { pipelines: PipelinesStorage, diff --git a/src/shapes.rs b/src/shapes.rs index 0b902b92..085dc23d 100644 --- a/src/shapes.rs +++ b/src/shapes.rs @@ -75,7 +75,7 @@ pub fn draw_rectangle_lines(x: f32, y: f32, w: f32, h: f32, thickness: f32, colo context.gl.geometry(&vertices, &indices); } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct DrawRectangleParams { /// Adds an offset to the position /// E.g. offset (0,0) positions the rectangle at the top left corner of the screen, while offset diff --git a/src/telemetry.rs b/src/telemetry.rs index 6f2b3a3d..2e99f873 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -47,6 +47,7 @@ impl Zone { } } +#[derive(Clone, Debug)] pub struct ZoneGuard { _marker: (), } @@ -272,6 +273,7 @@ impl Profiler { } } +#[derive(Clone, Copy)] pub struct GpuQuery { pub query: miniquad::graphics::ElapsedQuery, pub in_progress: bool, @@ -293,6 +295,7 @@ pub fn scene_allocated_memory() -> usize { /// ``` /// Will add "Time query: Atlas build time, 0.5s" string to /// `telemetry::strings()` +#[derive(Clone, Debug)] pub struct LogTimeGuard<'a> { name: &'a str, start_time: f64, @@ -342,7 +345,7 @@ pub fn capture_frame() { get_profiler().capture_request = true; } -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct DrawCallTelemetry { pub indices_count: usize, pub texture: miniquad::TextureId, diff --git a/src/text.rs b/src/text.rs index 73d26130..d26a38ed 100644 --- a/src/text.rs +++ b/src/text.rs @@ -222,7 +222,7 @@ impl Font { } /// Arguments for "draw_text_ex" function such as font, font_size etc -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct TextParams<'a> { pub font: Option<&'a Font>, /// Base size for character height. The size in pixel used during font rasterizing. diff --git a/src/text/atlas.rs b/src/text/atlas.rs index 4106adf7..e2b7f46a 100644 --- a/src/text/atlas.rs +++ b/src/text/atlas.rs @@ -17,6 +17,7 @@ pub enum SpriteKey { Texture(miniquad::TextureId), Id(u64), } +#[derive(Clone, Debug)] pub struct Atlas { texture: miniquad::TextureId, image: Image, diff --git a/src/texture.rs b/src/texture.rs index 993a62d6..2d75947a 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -230,24 +230,27 @@ impl Image { bytes, } } - + /// Blends this image with another image (of identical dimensions) /// Inspired by OpenCV saturated blending pub fn blend(&mut self, other: &Image) { - assert!(self.width as usize * self.height as usize == other.width as usize * other.height as usize); + assert!( + self.width as usize * self.height as usize + == other.width as usize * other.height as usize + ); for i in 0..self.bytes.len() / 4 { let c1: Color = Color { r: self.bytes[i * 4] as f32 / 255., g: self.bytes[i * 4 + 1] as f32 / 255., b: self.bytes[i * 4 + 2] as f32 / 255., - a: self.bytes[i * 4 + 3] as f32 / 255. + a: self.bytes[i * 4 + 3] as f32 / 255., }; let c2: Color = Color { r: other.bytes[i * 4] as f32 / 255., g: other.bytes[i * 4 + 1] as f32 / 255., b: other.bytes[i * 4 + 2] as f32 / 255., - a: other.bytes[i * 4 + 3] as f32 / 255. + a: other.bytes[i * 4 + 3] as f32 / 255., }; let new_color: Color = Color { r: f32::min(c1.r * c1.a + c2.r * c2.a, 1.), @@ -267,28 +270,31 @@ impl Image { /// overlaying a completely transparent image has no effect /// on the original image, though blending them would. pub fn overlay(&mut self, other: &Image) { - assert!(self.width as usize * self.height as usize == other.width as usize * other.height as usize); + assert!( + self.width as usize * self.height as usize + == other.width as usize * other.height as usize + ); for i in 0..self.bytes.len() / 4 { let c1: Color = Color { r: self.bytes[i * 4] as f32 / 255., g: self.bytes[i * 4 + 1] as f32 / 255., b: self.bytes[i * 4 + 2] as f32 / 255., - a: self.bytes[i * 4 + 3] as f32 / 255. + a: self.bytes[i * 4 + 3] as f32 / 255., }; let c2: Color = Color { r: other.bytes[i * 4] as f32 / 255., g: other.bytes[i * 4 + 1] as f32 / 255., b: other.bytes[i * 4 + 2] as f32 / 255., - a: other.bytes[i * 4 + 3] as f32 / 255. + a: other.bytes[i * 4 + 3] as f32 / 255., }; let new_color: Color = Color { r: f32::min(c1.r * (1. - c2.a) + c2.r * c2.a, 1.), g: f32::min(c1.g * (1. - c2.a) + c2.g * c2.a, 1.), b: f32::min(c1.b * (1. - c2.a) + c2.b * c2.a, 1.), - a: f32::min(c1.a + c2.a, 1.) + a: f32::min(c1.a + c2.a, 1.), }; - + self.bytes[i * 4] = (new_color.r * 255.) as u8; self.bytes[i * 4 + 1] = (new_color.g * 255.) as u8; self.bytes[i * 4 + 2] = (new_color.b * 255.) as u8; @@ -367,7 +373,7 @@ pub fn render_target(width: u32, height: u32) -> RenderTarget { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct DrawTextureParams { pub dest_size: Option, @@ -671,7 +677,6 @@ impl Texture2D { ctx.texture_update(self.raw_miniquad_id(), bytes); } - /// Uploads [Image] data to part of this texture. pub fn update_part( &self, diff --git a/src/ui.rs b/src/ui.rs index 6f27d011..b7af278b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -89,6 +89,7 @@ use input::{InputCharacter, Key}; /// These should be unique per window and ideally not change in between frames. pub type Id = u64; +#[derive(Clone, Debug)] pub enum UiContent<'a> { Label(Cow<'a, str>), Texture(crate::texture::Texture2D), diff --git a/src/ui/cursor.rs b/src/ui/cursor.rs index 8e01e2b0..b587e2b7 100644 --- a/src/ui/cursor.rs +++ b/src/ui/cursor.rs @@ -5,7 +5,7 @@ use crate::math::{Rect, Vec2}; -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct Scroll { pub scroll: Vec2, pub dragging_x: bool, @@ -31,14 +31,14 @@ impl Scroll { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub enum Layout { Vertical, Horizontal, Free(Vec2), } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub struct Cursor { pub x: f32, pub y: f32, diff --git a/src/ui/input.rs b/src/ui/input.rs index 6919165e..bb7e70b8 100644 --- a/src/ui/input.rs +++ b/src/ui/input.rs @@ -2,20 +2,20 @@ use crate::math::Vec2; pub use crate::ui::input_handler::KeyCode; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum Key { Char(char), KeyCode(KeyCode), } -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct InputCharacter { pub key: Key, pub modifier_shift: bool, pub modifier_ctrl: bool, } -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub struct Input { pub(crate) mouse_position: Vec2, pub(crate) is_mouse_down: bool, diff --git a/src/ui/render/mesh_rasterizer.rs b/src/ui/render/mesh_rasterizer.rs index b44310c9..3cabd6f3 100644 --- a/src/ui/render/mesh_rasterizer.rs +++ b/src/ui/render/mesh_rasterizer.rs @@ -40,7 +40,7 @@ impl Vertex { } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct DrawList { pub vertices: Vec, pub indices: Vec, diff --git a/src/ui/render/painter.rs b/src/ui/render/painter.rs index 542fd739..4f3d3b01 100644 --- a/src/ui/render/painter.rs +++ b/src/ui/render/painter.rs @@ -540,7 +540,7 @@ impl Painter { } } -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] #[allow(dead_code)] pub enum Alignment { Left, @@ -553,7 +553,7 @@ impl Default for Alignment { } } -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct LabelParams { pub color: Color, pub alignment: Alignment, diff --git a/src/ui/style.rs b/src/ui/style.rs index 9d0cf2ca..6541abde 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -12,6 +12,7 @@ use crate::{ use std::sync::{Arc, Mutex}; +#[derive(Clone, Debug)] pub struct StyleBuilder { atlas: Arc>, font: Arc>, diff --git a/src/ui/widgets/button.rs b/src/ui/widgets/button.rs index 445b9d0b..0e81922a 100644 --- a/src/ui/widgets/button.rs +++ b/src/ui/widgets/button.rs @@ -3,6 +3,7 @@ use crate::{ ui::{ElementState, Layout, Ui, UiContent}, }; +#[derive(Clone, Debug)] pub struct Button<'a> { position: Option, size: Option, diff --git a/src/ui/widgets/checkbox.rs b/src/ui/widgets/checkbox.rs index 5d3d5638..6fa95290 100644 --- a/src/ui/widgets/checkbox.rs +++ b/src/ui/widgets/checkbox.rs @@ -3,6 +3,7 @@ use crate::{ ui::{ElementState, Id, Layout, Ui, UiContent}, }; +#[derive(Clone, Copy, Debug)] pub struct Checkbox<'a> { id: Id, label: &'a str, diff --git a/src/ui/widgets/combobox.rs b/src/ui/widgets/combobox.rs index 52adac00..145f0595 100644 --- a/src/ui/widgets/combobox.rs +++ b/src/ui/widgets/combobox.rs @@ -3,6 +3,7 @@ use crate::{ ui::{ElementState, Id, Layout, Ui, UiContent}, }; +#[derive(Clone, Copy, Debug)] pub struct ComboBox<'a, 'b, 'c> { id: Id, label: &'a str, diff --git a/src/ui/widgets/drag.rs b/src/ui/widgets/drag.rs index 74d78f24..e0377f51 100644 --- a/src/ui/widgets/drag.rs +++ b/src/ui/widgets/drag.rs @@ -36,6 +36,7 @@ impl Default for State { } } +#[derive(Clone, Copy, Debug)] pub struct Drag<'a> { id: Id, label: &'a str, diff --git a/src/ui/widgets/editbox.rs b/src/ui/widgets/editbox.rs index 36b4bc61..212f19ba 100644 --- a/src/ui/widgets/editbox.rs +++ b/src/ui/widgets/editbox.rs @@ -5,6 +5,7 @@ use crate::{ ui::{ElementState, Id, InputCharacter, Key, KeyCode, Layout, Ui}, }; +#[derive(Clone, Copy)] pub struct Editbox<'a> { id: Id, size: Vec2, diff --git a/src/ui/widgets/editbox/text_editor.rs b/src/ui/widgets/editbox/text_editor.rs index 3fb09834..d06ff410 100644 --- a/src/ui/widgets/editbox/text_editor.rs +++ b/src/ui/widgets/editbox/text_editor.rs @@ -134,7 +134,7 @@ impl Command for DeleteRange { } } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub enum ClickState { None, SelectingChars { selection_begin: u32 }, diff --git a/src/ui/widgets/group.rs b/src/ui/widgets/group.rs index 2cc2f1df..64293d43 100644 --- a/src/ui/widgets/group.rs +++ b/src/ui/widgets/group.rs @@ -3,7 +3,7 @@ use crate::{ ui::{Drag, DragState, ElementState, Id, Layout, Ui}, }; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct Group { id: Id, position: Option, @@ -143,6 +143,7 @@ impl Group { } #[must_use = "Must call `.end()` to finish Group"] +#[derive(Clone, Copy, Debug)] pub struct GroupToken { draggable: bool, drag: Drag, diff --git a/src/ui/widgets/input.rs b/src/ui/widgets/input.rs index de31bb1a..40769739 100644 --- a/src/ui/widgets/input.rs +++ b/src/ui/widgets/input.rs @@ -3,6 +3,7 @@ use crate::{ ui::{widgets::Editbox, ElementState, Id, Layout, Ui, UiContent}, }; +#[derive(Clone, Copy, Debug)] pub struct InputText<'a> { id: Id, label: &'a str, diff --git a/src/ui/widgets/label.rs b/src/ui/widgets/label.rs index 172a46b1..8ea3ec63 100644 --- a/src/ui/widgets/label.rs +++ b/src/ui/widgets/label.rs @@ -5,6 +5,7 @@ use crate::{ use std::borrow::Cow; +#[derive(Clone, Debug)] pub struct Label<'a> { position: Option, _multiline: Option, diff --git a/src/ui/widgets/popup.rs b/src/ui/widgets/popup.rs index 410ff7ee..93bc21f1 100644 --- a/src/ui/widgets/popup.rs +++ b/src/ui/widgets/popup.rs @@ -4,6 +4,7 @@ use crate::{ }; /// Borderless subwindow drawn on top of everything +#[derive(Clone, Copy, Debug)] pub struct Popup { id: Id, size: Vec2, diff --git a/src/ui/widgets/slider.rs b/src/ui/widgets/slider.rs index 5ac69dc3..c2b268cc 100644 --- a/src/ui/widgets/slider.rs +++ b/src/ui/widgets/slider.rs @@ -5,6 +5,7 @@ use crate::{ use std::ops::Range; +#[derive(Clone, Debug)] pub struct Slider<'a> { id: Id, label: &'a str, diff --git a/src/ui/widgets/tabbar.rs b/src/ui/widgets/tabbar.rs index 61cae266..cbf4c78d 100644 --- a/src/ui/widgets/tabbar.rs +++ b/src/ui/widgets/tabbar.rs @@ -3,6 +3,7 @@ use crate::{ ui::{ElementState, Id, Layout, Ui, UiContent}, }; +#[derive(Debug)] pub struct Tabbar<'a, 'b> { id: Id, size: Vec2, diff --git a/src/ui/widgets/texture.rs b/src/ui/widgets/texture.rs index 72ac7692..53567717 100644 --- a/src/ui/widgets/texture.rs +++ b/src/ui/widgets/texture.rs @@ -4,6 +4,7 @@ use crate::{ ui::{Layout, Ui}, }; +#[derive(Clone, Debug)] pub struct Texture { position: Option, w: f32, diff --git a/src/ui/widgets/tree_node.rs b/src/ui/widgets/tree_node.rs index a0a8f0e6..22a9217b 100644 --- a/src/ui/widgets/tree_node.rs +++ b/src/ui/widgets/tree_node.rs @@ -5,6 +5,7 @@ use crate::{ use std::borrow::Cow; +#[derive(Clone, Debug)] pub struct TreeNode<'a> { id: Id, label: Cow<'a, str>, @@ -88,6 +89,7 @@ impl<'a> TreeNode<'a> { } #[must_use = "Must call `.end()` to finish TreeNode"] +#[derive(Clone, Copy, Debug)] pub struct TreeNodeToken { clicked: bool, } diff --git a/src/ui/widgets/window.rs b/src/ui/widgets/window.rs index 244d0e2d..4c758065 100644 --- a/src/ui/widgets/window.rs +++ b/src/ui/widgets/window.rs @@ -169,6 +169,7 @@ impl Window { } #[must_use = "Must call `.end()` to finish Window"] +#[derive(Clone, Copy, Debug)] pub struct WindowToken; impl WindowToken { diff --git a/tiled/src/lib.rs b/tiled/src/lib.rs index 76e8fd74..b0329f6c 100644 --- a/tiled/src/lib.rs +++ b/tiled/src/lib.rs @@ -30,7 +30,7 @@ pub struct Object { pub properties: HashMap, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Tile { /// id in the tileset pub id: u32, @@ -40,7 +40,7 @@ pub struct Tile { pub attrs: String, } -#[derive(Debug, Default)] +#[derive(Clone, Debug, Default)] pub struct Layer { pub objects: Vec, pub width: u32, @@ -53,7 +53,7 @@ pub struct Layer { pub offsety: Option, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct TileSet { pub texture: Texture2D, @@ -76,7 +76,7 @@ impl TileSet { } } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Map { pub layers: HashMap, pub tilesets: HashMap, @@ -235,6 +235,7 @@ impl Map { } } +#[derive(Clone, Copy, Debug)] pub struct TilesIterator<'a> { rect: Rect, current: (u32, u32), diff --git a/tiled/src/tiled.rs b/tiled/src/tiled.rs index 00f7b6c5..7d2f20e4 100644 --- a/tiled/src/tiled.rs +++ b/tiled/src/tiled.rs @@ -3,7 +3,7 @@ use nanoserde::DeJson; pub mod layer; /// https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tmx-grid -#[derive(Clone, Debug, Default, DeJson)] +#[derive(Clone, Copy, Debug, Default, DeJson)] pub struct Grid { pub width: i32, pub height: i32, @@ -18,11 +18,11 @@ pub struct Property { } /// https://doc.mapeditor.org/en/stable/reference/json-map-format/#json-layer -#[derive(Clone, Debug, Default, DeJson)] +#[derive(Clone, Copy, Debug, Default, DeJson)] pub struct Layer {} /// https://doc.mapeditor.org/en/stable/reference/json-map-format/#json-frame -#[derive(Clone, Debug, Default, DeJson)] +#[derive(Clone, Copy, Debug, Default, DeJson)] pub struct Frame { pub duration: i32, pub tileid: i32, @@ -54,7 +54,7 @@ pub struct Tile { } /// https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tmx-tileoffset -#[derive(Clone, Debug, Default, DeJson)] +#[derive(Clone, Copy, Debug, Default, DeJson)] pub struct Tileoffset { pub x: i32, pub y: i32, From 5aa8a4f24029b1e9927083d96903533c0d90971b Mon Sep 17 00:00:00 2001 From: musjj <72612857+musjj@users.noreply.github.com> Date: Sat, 13 Apr 2024 18:20:38 +0700 Subject: [PATCH 2/3] Restore non-compliant formatting There's a block of code that is not compliant with rustfmt, so let's restore it for now and maybe deal with it in another PR --- src/texture.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/texture.rs b/src/texture.rs index 2d75947a..0fb81841 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -230,27 +230,24 @@ impl Image { bytes, } } - + /// Blends this image with another image (of identical dimensions) /// Inspired by OpenCV saturated blending pub fn blend(&mut self, other: &Image) { - assert!( - self.width as usize * self.height as usize - == other.width as usize * other.height as usize - ); + assert!(self.width as usize * self.height as usize == other.width as usize * other.height as usize); for i in 0..self.bytes.len() / 4 { let c1: Color = Color { r: self.bytes[i * 4] as f32 / 255., g: self.bytes[i * 4 + 1] as f32 / 255., b: self.bytes[i * 4 + 2] as f32 / 255., - a: self.bytes[i * 4 + 3] as f32 / 255., + a: self.bytes[i * 4 + 3] as f32 / 255. }; let c2: Color = Color { r: other.bytes[i * 4] as f32 / 255., g: other.bytes[i * 4 + 1] as f32 / 255., b: other.bytes[i * 4 + 2] as f32 / 255., - a: other.bytes[i * 4 + 3] as f32 / 255., + a: other.bytes[i * 4 + 3] as f32 / 255. }; let new_color: Color = Color { r: f32::min(c1.r * c1.a + c2.r * c2.a, 1.), @@ -270,31 +267,28 @@ impl Image { /// overlaying a completely transparent image has no effect /// on the original image, though blending them would. pub fn overlay(&mut self, other: &Image) { - assert!( - self.width as usize * self.height as usize - == other.width as usize * other.height as usize - ); + assert!(self.width as usize * self.height as usize == other.width as usize * other.height as usize); for i in 0..self.bytes.len() / 4 { let c1: Color = Color { r: self.bytes[i * 4] as f32 / 255., g: self.bytes[i * 4 + 1] as f32 / 255., b: self.bytes[i * 4 + 2] as f32 / 255., - a: self.bytes[i * 4 + 3] as f32 / 255., + a: self.bytes[i * 4 + 3] as f32 / 255. }; let c2: Color = Color { r: other.bytes[i * 4] as f32 / 255., g: other.bytes[i * 4 + 1] as f32 / 255., b: other.bytes[i * 4 + 2] as f32 / 255., - a: other.bytes[i * 4 + 3] as f32 / 255., + a: other.bytes[i * 4 + 3] as f32 / 255. }; let new_color: Color = Color { r: f32::min(c1.r * (1. - c2.a) + c2.r * c2.a, 1.), g: f32::min(c1.g * (1. - c2.a) + c2.g * c2.a, 1.), b: f32::min(c1.b * (1. - c2.a) + c2.b * c2.a, 1.), - a: f32::min(c1.a + c2.a, 1.), + a: f32::min(c1.a + c2.a, 1.) }; - + self.bytes[i * 4] = (new_color.r * 255.) as u8; self.bytes[i * 4 + 1] = (new_color.g * 255.) as u8; self.bytes[i * 4 + 2] = (new_color.b * 255.) as u8; From 768e77d7ece7902b132d7acae45759a8919bcd17 Mon Sep 17 00:00:00 2001 From: musjj <72612857+musjj@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:36:51 +0700 Subject: [PATCH 3/3] Revert some overly aggressive impls --- src/exec.rs | 2 +- src/telemetry.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/exec.rs b/src/exec.rs index 17b86135..ac78c865 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -6,7 +6,7 @@ use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; use crate::Error; // Returns Pending as long as its inner bool is false. -#[derive(Default, Clone, Copy, Debug)] +#[derive(Default)] pub struct FrameFuture { done: bool, } diff --git a/src/telemetry.rs b/src/telemetry.rs index 2e99f873..8212ee40 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -47,7 +47,6 @@ impl Zone { } } -#[derive(Clone, Debug)] pub struct ZoneGuard { _marker: (), }