cleanup: no more clippy warnings

This commit is contained in:
nik012003
2023-07-24 14:46:21 +02:00
parent f7ea663a3d
commit 6b4511bdd6
7 changed files with 40 additions and 36 deletions

View File

@@ -17,7 +17,6 @@ use stardust_xr_fusion::{
use stardust_xr_molecules::{GrabData, Grabbable}; use stardust_xr_molecules::{GrabData, Grabbable};
use std::f32::consts::PI; use std::f32::consts::PI;
const APP_LIMIT: usize = 300; const APP_LIMIT: usize = 300;
const APP_SIZE: f32 = 0.05; const APP_SIZE: f32 = 0.05;
const GRID_PADDING: f32 = 0.01; const GRID_PADDING: f32 = 0.01;
@@ -80,7 +79,7 @@ impl RootHandler for AppGrid {
} }
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> { fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
return match &icon.icon_type { match &icon.icon_type {
IconType::Png => { IconType::Png => {
// let t = Transform::from_rotation_scale( // let t = Transform::from_rotation_scale(
// Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), // 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<Model> {
&ResourceID::new_direct(icon.path.clone())?, &ResourceID::new_direct(icon.path.clone())?,
)?), )?),
_ => panic!("Invalid Icon Type"), _ => panic!("Invalid Icon Type"),
}; }
} }
pub struct App { pub struct App {

View File

@@ -218,7 +218,7 @@ impl RootHandler for Button {
// Model handling // Model handling
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> { fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
return match &icon.icon_type { match &icon.icon_type {
IconType::Png => { IconType::Png => {
let t = Transform::from_rotation_scale( let t = Transform::from_rotation_scale(
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), 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<Model> {
&ResourceID::new_direct(icon.path.clone())?, &ResourceID::new_direct(icon.path.clone())?,
)?), )?),
_ => panic!("Invalid Icon Type"), _ => panic!("Invalid Icon Type"),
}; }
} }
pub struct App { 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 self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter
} else { } else {
self.icon.set_enabled(true).unwrap(); 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.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
} }
self.currently_shown = !self.currently_shown; self.currently_shown = !self.currently_shown;
@@ -368,7 +370,9 @@ impl RootHandler for App {
} else { } else {
if grabbable_move.final_value() == 0.0001 { if grabbable_move.final_value() == 0.0001 {
self.icon.set_enabled(false).unwrap(); 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; self.grabbable_move = None;
} }

View File

@@ -146,7 +146,7 @@ impl RootHandler for Sirius {
println!("{}", starpos); println!("{}", starpos);
star.content_parent() star.content_parent()
.set_position( .set_position(
Some(&self.grabbable.content_parent()), Some(self.grabbable.content_parent()),
[starpos, 0.1, 0.0], [starpos, 0.1, 0.0],
) )
.ok(); .ok();
@@ -155,7 +155,7 @@ impl RootHandler for Sirius {
false => { false => {
for star in &self.clients { for star in &self.clients {
star.content_parent() 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(); .ok();
} }
} }
@@ -197,7 +197,7 @@ impl RootHandler for Sirius {
} }
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> { fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
return match &icon.icon_type { match &icon.icon_type {
IconType::Png => { IconType::Png => {
let t = Transform::from_rotation_scale( let t = Transform::from_rotation_scale(
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), 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<Model> {
&ResourceID::new_direct(icon.path.clone())?, &ResourceID::new_direct(icon.path.clone())?,
)?), )?),
_ => panic!("Invalid Icon Type"), _ => panic!("Invalid Icon Type"),
}; }
} }
pub struct App { 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 self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter
} else { } else {
self.icon.set_enabled(true).unwrap(); 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.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
} }
self.currently_shown = !self.currently_shown; self.currently_shown = !self.currently_shown;
@@ -347,7 +349,9 @@ impl RootHandler for App {
} else { } else {
if grabbable_move.final_value() == 0.0001 { if grabbable_move.final_value() == 0.0001 {
self.icon.set_enabled(false).unwrap(); 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; self.grabbable_move = None;
} }

View File

@@ -44,10 +44,7 @@ impl Application {
if prefer_3d { if prefer_3d {
icon = raw_icons icon = raw_icons
.into_iter() .into_iter()
.find(|i| match i.icon_type { .find(|i| i.icon_type == IconType::Gltf)
IconType::Gltf => true,
_ => false,
})
.or(icon); .or(icon);
} }

View File

@@ -22,7 +22,7 @@ async fn main() -> Result<()> {
let protostar = ProtoStar::create_from_desktop_file( let protostar = ProtoStar::create_from_desktop_file(
client.get_root(), client.get_root(),
[0.0, 0.0, 0.0], [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); let _root = client.wrap_root(protostar);

View File

@@ -21,7 +21,7 @@ const MODEL_SCALE: f32 = 0.03;
const ACTIVATION_DISTANCE: f32 = 0.5; const ACTIVATION_DISTANCE: f32 = 0.5;
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> { fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
return match &icon.icon_type { match &icon.icon_type {
IconType::Png => { IconType::Png => {
let t = Transform::from_rotation_scale( let t = Transform::from_rotation_scale(
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI), 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<Model> {
&ResourceID::new_direct(icon.path.clone())?, &ResourceID::new_direct(icon.path.clone())?,
)?), )?),
_ => panic!("Invalid Icon Type"), _ => panic!("Invalid Icon Type"),
}; }
} }
pub struct ProtoStar { pub struct ProtoStar {
@@ -64,6 +64,7 @@ pub struct ProtoStar {
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>, grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
currently_shown: bool, currently_shown: bool,
} }
impl ProtoStar { impl ProtoStar {
pub fn create_from_desktop_file( pub fn create_from_desktop_file(
parent: &Spatial, 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 self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter
} else { } else {
self.icon.set_enabled(true).unwrap(); 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.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
} }
self.currently_shown = !self.currently_shown; self.currently_shown = !self.currently_shown;
@@ -170,7 +173,9 @@ impl RootHandler for ProtoStar {
} else { } else {
if grabbable_move.final_value() == 0.0001 { if grabbable_move.final_value() == 0.0001 {
self.icon.set_enabled(false).unwrap(); 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; self.grabbable_move = None;
} }

View File

@@ -64,12 +64,12 @@ lazy_static! {
} }
fn get_data_dirs() -> Vec<PathBuf> { fn get_data_dirs() -> Vec<PathBuf> {
let xdg_data_dirs_str = std::env::var("XDG_DATA_DIRS").unwrap_or_default(); std::env::var("XDG_DATA_DIRS") // parse XDG_DATA_DIRS
xdg_data_dirs_str .unwrap_or_default()
.split(":") .split(':')
.filter_map(|dir| PathBuf::from_str(dir).ok()) .filter_map(|dir| PathBuf::from_str(dir).ok())
.chain(dirs::home_dir().into_iter().map(|d| d.join(".local/share"))) .chain(dirs::home_dir().into_iter().map(|d| d.join(".local/share"))) // $HOME/.local/share
.chain(PathBuf::from_str("/usr/share").into_iter()) .chain(PathBuf::from_str("/usr/share").into_iter()) // /usr/share
.filter(|dir| dir.exists() && dir.is_dir()) .filter(|dir| dir.exists() && dir.is_dir())
.collect() .collect()
} }
@@ -172,12 +172,7 @@ pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
.collect() .collect()
} }
"Icon" => icon = Some(value.to_string()), "Icon" => icon = Some(value.to_string()),
"NoDisplay" => { "NoDisplay" => no_display = value == "true",
no_display = match value {
"true" => true,
_ => false,
}
}
_ => (), // Ignore unknown keys _ => (), // Ignore unknown keys
} }
} }
@@ -304,11 +299,11 @@ impl Icon {
Some("glb") | Some("gltf") => IconType::Gltf, Some("glb") | Some("gltf") => IconType::Gltf,
_ => return None, _ => return None,
}; };
return Some(Icon { Some(Icon {
icon_type, icon_type,
path, path,
size, size,
}); })
} }
pub fn cached_process(self, size: u16) -> Result<Icon, std::io::Error> { pub fn cached_process(self, size: u16) -> Result<Icon, std::io::Error> {
@@ -382,7 +377,7 @@ pub fn get_image_cache_dir() -> PathBuf {
} }
let image_cache_dir = cache_dir.join("protostar_icon_cache"); let image_cache_dir = cache_dir.join("protostar_icon_cache");
create_dir_all(&image_cache_dir).expect("Could not create image cache directory"); 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<Path>, size: u16) -> Result<PathBuf, std::io::Error> { pub fn get_png_from_svg(svg_path: impl AsRef<Path>, size: u16) -> Result<PathBuf, std::io::Error> {