diff --git a/examples/app_grid.rs b/examples/app_grid.rs index 969daf7..94f67b6 100644 --- a/examples/app_grid.rs +++ b/examples/app_grid.rs @@ -17,7 +17,6 @@ use stardust_xr_fusion::{ use stardust_xr_molecules::{GrabData, Grabbable}; use std::f32::consts::PI; - const APP_LIMIT: usize = 300; const APP_SIZE: f32 = 0.05; const GRID_PADDING: f32 = 0.01; @@ -80,7 +79,7 @@ impl RootHandler for AppGrid { } fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { - return match &icon.icon_type { + match &icon.icon_type { IconType::Png => { // let t = Transform::from_rotation_scale( // Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), @@ -107,7 +106,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { &ResourceID::new_direct(icon.path.clone())?, )?), _ => panic!("Invalid Icon Type"), - }; + } } pub struct App { diff --git a/examples/hexagon_launcher.rs b/examples/hexagon_launcher.rs index 297a556..843969a 100644 --- a/examples/hexagon_launcher.rs +++ b/examples/hexagon_launcher.rs @@ -218,7 +218,7 @@ impl RootHandler for Button { // Model handling fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { - return match &icon.icon_type { + match &icon.icon_type { IconType::Png => { let t = Transform::from_rotation_scale( Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), @@ -245,7 +245,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { &ResourceID::new_direct(icon.path.clone())?, )?), _ => panic!("Invalid Icon Type"), - }; + } } pub struct App { @@ -341,7 +341,9 @@ impl App { self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter } else { self.icon.set_enabled(true).unwrap(); - self.label.as_ref().map(|l| l.set_enabled(true).unwrap()); + if let Some(label) = self.label.as_ref() { + label.set_enabled(true).unwrap() + } self.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25)); } self.currently_shown = !self.currently_shown; @@ -368,7 +370,9 @@ impl RootHandler for App { } else { if grabbable_move.final_value() == 0.0001 { self.icon.set_enabled(false).unwrap(); - self.label.as_ref().map(|l| l.set_enabled(false).unwrap()); + if let Some(label) = self.label.as_ref() { + label.set_enabled(false).unwrap() + } } self.grabbable_move = None; } diff --git a/examples/sirius.rs b/examples/sirius.rs index d21d273..9db1b81 100644 --- a/examples/sirius.rs +++ b/examples/sirius.rs @@ -146,7 +146,7 @@ impl RootHandler for Sirius { println!("{}", starpos); star.content_parent() .set_position( - Some(&self.grabbable.content_parent()), + Some(self.grabbable.content_parent()), [starpos, 0.1, 0.0], ) .ok(); @@ -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, 0.0, 0.0]) .ok(); } } @@ -197,7 +197,7 @@ impl RootHandler for Sirius { } fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { - return match &icon.icon_type { + match &icon.icon_type { IconType::Png => { let t = Transform::from_rotation_scale( Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), @@ -224,7 +224,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { &ResourceID::new_direct(icon.path.clone())?, )?), _ => panic!("Invalid Icon Type"), - }; + } } pub struct App { @@ -320,7 +320,9 @@ impl App { self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter } else { self.icon.set_enabled(true).unwrap(); - self.label.as_ref().map(|l| l.set_enabled(true).unwrap()); + if let Some(label) = self.label.as_ref() { + label.set_enabled(true).unwrap() + } self.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25)); } self.currently_shown = !self.currently_shown; @@ -347,7 +349,9 @@ impl RootHandler for App { } else { if grabbable_move.final_value() == 0.0001 { self.icon.set_enabled(false).unwrap(); - self.label.as_ref().map(|l| l.set_enabled(false).unwrap()); + if let Some(label) = self.label.as_ref() { + label.set_enabled(false).unwrap() + } } self.grabbable_move = None; } diff --git a/src/application.rs b/src/application.rs index e12cf55..9eeae0b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -44,10 +44,7 @@ impl Application { if prefer_3d { icon = raw_icons .into_iter() - .find(|i| match i.icon_type { - IconType::Gltf => true, - _ => false, - }) + .find(|i| i.icon_type == IconType::Gltf) .or(icon); } diff --git a/src/main.rs b/src/main.rs index dd84573..1c2e4ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ async fn main() -> Result<()> { let protostar = ProtoStar::create_from_desktop_file( client.get_root(), [0.0, 0.0, 0.0], - parse_desktop_file(args.desktop_file).map_err(|e| Report::msg(e))?, + parse_desktop_file(args.desktop_file).map_err(Report::msg)?, )?; let _root = client.wrap_root(protostar); diff --git a/src/protostar.rs b/src/protostar.rs index 1fa8406..90b9348 100644 --- a/src/protostar.rs +++ b/src/protostar.rs @@ -21,7 +21,7 @@ const MODEL_SCALE: f32 = 0.03; const ACTIVATION_DISTANCE: f32 = 0.5; fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { - return match &icon.icon_type { + match &icon.icon_type { IconType::Png => { let t = Transform::from_rotation_scale( Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), @@ -48,7 +48,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { &ResourceID::new_direct(icon.path.clone())?, )?), _ => panic!("Invalid Icon Type"), - }; + } } pub struct ProtoStar { @@ -64,6 +64,7 @@ pub struct ProtoStar { grabbable_move: Option>, currently_shown: bool, } + impl ProtoStar { pub fn create_from_desktop_file( parent: &Spatial, @@ -143,7 +144,9 @@ impl ProtoStar { self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter } else { self.icon.set_enabled(true).unwrap(); - self.label.as_ref().map(|l| l.set_enabled(true).unwrap()); + if let Some(label) = self.label.as_ref() { + label.set_enabled(true).unwrap() + } self.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25)); } self.currently_shown = !self.currently_shown; @@ -170,7 +173,9 @@ impl RootHandler for ProtoStar { } else { if grabbable_move.final_value() == 0.0001 { self.icon.set_enabled(false).unwrap(); - self.label.as_ref().map(|l| l.set_enabled(false).unwrap()); + if let Some(label) = self.label.as_ref() { + label.set_enabled(false).unwrap() + } } self.grabbable_move = None; } diff --git a/src/xdg.rs b/src/xdg.rs index 9f70bff..991f8eb 100644 --- a/src/xdg.rs +++ b/src/xdg.rs @@ -64,12 +64,12 @@ lazy_static! { } fn get_data_dirs() -> Vec { - let xdg_data_dirs_str = std::env::var("XDG_DATA_DIRS").unwrap_or_default(); - xdg_data_dirs_str - .split(":") + std::env::var("XDG_DATA_DIRS") // parse XDG_DATA_DIRS + .unwrap_or_default() + .split(':') .filter_map(|dir| PathBuf::from_str(dir).ok()) - .chain(dirs::home_dir().into_iter().map(|d| d.join(".local/share"))) - .chain(PathBuf::from_str("/usr/share").into_iter()) + .chain(dirs::home_dir().into_iter().map(|d| d.join(".local/share"))) // $HOME/.local/share + .chain(PathBuf::from_str("/usr/share").into_iter()) // /usr/share .filter(|dir| dir.exists() && dir.is_dir()) .collect() } @@ -172,12 +172,7 @@ pub fn parse_desktop_file(path: PathBuf) -> Result { .collect() } "Icon" => icon = Some(value.to_string()), - "NoDisplay" => { - no_display = match value { - "true" => true, - _ => false, - } - } + "NoDisplay" => no_display = value == "true", _ => (), // Ignore unknown keys } } @@ -304,11 +299,11 @@ impl Icon { Some("glb") | Some("gltf") => IconType::Gltf, _ => return None, }; - return Some(Icon { + Some(Icon { icon_type, path, size, - }); + }) } pub fn cached_process(self, size: u16) -> Result { @@ -382,7 +377,7 @@ pub fn get_image_cache_dir() -> PathBuf { } let image_cache_dir = cache_dir.join("protostar_icon_cache"); create_dir_all(&image_cache_dir).expect("Could not create image cache directory"); - return image_cache_dir; + image_cache_dir } pub fn get_png_from_svg(svg_path: impl AsRef, size: u16) -> Result {