From 3a396340db405d5c57493c7d5ed8e751b4e1f985 Mon Sep 17 00:00:00 2001 From: nik012003 Date: Mon, 24 Jul 2023 15:28:38 +0200 Subject: [PATCH] cleanup hardcoded values --- examples/hexagon_launcher.rs | 28 ++++++++++++---------------- examples/sirius.rs | 11 ++--------- src/application.rs | 2 +- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/examples/hexagon_launcher.rs b/examples/hexagon_launcher.rs index f7ef12c..b1fc023 100644 --- a/examples/hexagon_launcher.rs +++ b/examples/hexagon_launcher.rs @@ -22,8 +22,13 @@ use tween::{QuartInOut, Tweener}; const APP_SIZE: f32 = 0.06; const PADDING: f32 = 0.005; +const MODEL_SCALE: f32 = 0.03; const ACTIVATION_DISTANCE: f32 = 0.5; +const CYAN: [f32; 4] = [0.0, 1.0, 1.0, 1.0]; +const BTN_SELECTED_COLOR: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; +const BTN_COLOR: [f32; 4] = [1.0, 1.0, 0.0, 1.0]; + #[derive(Clone)] struct Hex { q: isize, @@ -132,23 +137,21 @@ impl RootHandler for AppHexGrid { fn frame(&mut self, info: FrameInfo) { self.button.frame(info); if self.button.touch_plane.touch_started() { - let color = [0.0, 1.0, 0.0, 1.0]; self.button .model .model_part("Hex") .unwrap() - .set_material_parameter("color", MaterialParameter::Color(color)) + .set_material_parameter("color", MaterialParameter::Color(BTN_SELECTED_COLOR)) .unwrap(); for app in &mut self.apps { app.toggle(); } } else if self.button.touch_plane.touch_stopped() { - let color = [0.0, 0.0, 1.0, 1.0]; self.button .model .model_part("Hex") .unwrap() - .set_material_parameter("color", MaterialParameter::Color(color)) + .set_material_parameter("color", MaterialParameter::Color(BTN_COLOR)) .unwrap(); } for app in &mut self.apps { @@ -188,13 +191,13 @@ impl Button { grabbable.content_parent(), Transform::from_rotation_scale( Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), - [0.03, 0.03, 0.03], + [MODEL_SCALE; 3], ), &ResourceID::new_namespaced("protostar", "hexagon/hexagon"), )?; model .model_part("Hex")? - .set_material_parameter("color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))?; + .set_material_parameter("color", MaterialParameter::Color(BTN_COLOR))?; Ok(Button { touch_plane, grabbable, @@ -222,7 +225,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { IconType::Png => { let t = Transform::from_rotation_scale( Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), - [APP_SIZE * 0.5; 3], + [APP_SIZE / 2.0; 3], ); let model = Model::create( @@ -232,7 +235,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { )?; model .model_part("Hex")? - .set_material_parameter("color", MaterialParameter::Color([0.0, 1.0, 1.0, 1.0]))?; + .set_material_parameter("color", MaterialParameter::Color(CYAN))?; model.model_part("Icon")?.set_material_parameter( "diffuse", MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())), @@ -358,14 +361,7 @@ impl RootHandler for App { let scale = grabbable_move.move_by(info.delta); self.grabbable .content_parent() - .set_position( - Some(&self.parent), - [ - self.position.x * scale, - self.position.y * scale, - self.position.z * scale, - ], - ) + .set_position(Some(&self.parent), Vec3::from(self.position) * scale) .unwrap(); } else { if grabbable_move.final_value() == 0.0001 { diff --git a/examples/sirius.rs b/examples/sirius.rs index d8efeab..6c916db 100644 --- a/examples/sirius.rs +++ b/examples/sirius.rs @@ -155,7 +155,7 @@ impl RootHandler for Sirius { false => { for star in &self.clients { star.content_parent() - .set_position(Some(self.grabbable.content_parent()), [0.0, 0.0, 0.0]) + .set_position(Some(self.grabbable.content_parent()), [0.0; 3]) .ok(); } } @@ -337,14 +337,7 @@ impl RootHandler for App { let scale = grabbable_move.move_by(info.delta); self.grabbable .content_parent() - .set_position( - Some(&self.parent), - [ - self.position.x * scale, - self.position.y * scale, - self.position.z * scale, - ], - ) + .set_position(Some(&self.parent), Vec3::from(self.position) * scale) .unwrap(); } else { if grabbable_move.final_value() == 0.0001 { diff --git a/src/application.rs b/src/application.rs index 4430f2e..2f5492d 100644 --- a/src/application.rs +++ b/src/application.rs @@ -77,7 +77,7 @@ impl Application { // Strip/ignore field codes https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html let re = Regex::new(r"%[fFuUdDnNickvm]").unwrap(); - let exec = re.replace_all(&executable, ""); + let exec: std::borrow::Cow<'_, str> = re.replace_all(&executable, ""); unsafe { Command::new("sh")