diff --git a/examples/hexagon_launcher.rs b/examples/hexagon_launcher.rs new file mode 100644 index 0000000..a1db21b --- /dev/null +++ b/examples/hexagon_launcher.rs @@ -0,0 +1,138 @@ +use std::path::PathBuf; + +use color_eyre::eyre::Result; +use glam::Quat; +use manifest_dir_macros::directory_relative_path; +use mint::Vector3; +use protostar::{ + protostar::ProtoStar, + xdg::{get_desktop_files, parse_desktop_file, DesktopFile}, +}; +use stardust_xr_molecules::fusion::{ + client::{Client, FrameInfo, RootHandler}, + spatial::Spatial, drawable::{Text, TextStyle, Bounds, TextFit, Alignment}, core::values::Transform, +}; +use tween::TweenTime; + +const APP_LIMIT: usize = 18; +const APP_SIZE: f32 = 0.055; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> Result<()> { + color_eyre::install().unwrap(); + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .pretty() + .init(); + let (client, event_loop) = Client::connect_with_async_loop().await?; + client.set_base_prefixes(&[directory_relative_path!("res")]); + + let _root = client.wrap_root(AppHexGrid::new(&client))?; + + tokio::select! { + _ = tokio::signal::ctrl_c() => (), + e = event_loop => e??, + }; + Ok(()) +} + +struct AppHexGrid { + apps: Vec, +} +impl AppHexGrid { + + fn new(client: &Client) -> Self { + let mut desktop_files: Vec = get_desktop_files() + .into_iter() + .filter_map(|d| parse_desktop_file(d).ok()) + .filter(|d| !d.no_display) + .collect(); + + + let mut circles = 1; + let mut current_num = 6; + let mut target = 6; + desktop_files.sort_by_key(|d| d.clone().name.unwrap()); + dbg!(&desktop_files); + let apps :Vec= desktop_files + .into_iter() + .enumerate() + .filter(|(i,_)| *i < APP_LIMIT) + .filter_map(|(i,d)|{ + let angle = ((3.14*2.0)/current_num.to_f32())*(i%current_num).to_f32(); + + let x = (target-i)%circles; // this gives 0,3,2,1 but I need 0,1,2,3 + dbg!(x); + let m = circles.to_f32()*APP_SIZE - (x.to_f32()*0.5*(circles-1).to_f32()*(APP_SIZE/2.0)); + + let position = [angle.sin()*m,angle.cos()*m,0.0]; + + if (i+1) == target { + circles += 1; + current_num += 6; + target = target + current_num; + } + + return App::new(client.get_root(),position,d); + }) + .collect(); + AppHexGrid { apps } + } +} +impl RootHandler for AppHexGrid { + fn frame(&mut self, info: FrameInfo) { + for app in &mut self.apps { + app.frame(info); + } + } +} +struct App { + _text: Text, + _desktop_file: DesktopFile, + protostar: ProtoStar, +} + +impl App { + fn new( + parent: &Spatial, + position: impl Into>, + desktop_file: DesktopFile, + ) -> Option { + let position = position.into(); + let style = TextStyle { + character_height: APP_SIZE * 0.1, + bounds: Some(Bounds { + bounds: [APP_SIZE; 2].into(), + fit: TextFit::Wrap, + bounds_align: Alignment::XCenter | Alignment::YCenter, + }), + text_align: Alignment::XCenter | Alignment::YCenter, + ..Default::default() + }; + let protostar = ProtoStar::create_from_desktop_file(parent, desktop_file.clone()).ok()?; + let text = Text::create( + protostar.content_parent(), + Transform::from_position_rotation( + [0.0, 0.0, APP_SIZE / 2.0], + Quat::from_rotation_y(3.14), + ), + desktop_file.name.as_deref().unwrap_or("Unknown"), + style, + ) + .unwrap(); + protostar + .content_parent() + .set_position(None, position) + .unwrap(); + Some(App { + _text: text, + _desktop_file: desktop_file, + protostar, + }) + } +} +impl RootHandler for App { + fn frame(&mut self, info: FrameInfo) { + self.protostar.frame(info); + } +} diff --git a/src/protostar.rs b/src/protostar.rs index 5c4d8a4..beed0a5 100644 --- a/src/protostar.rs +++ b/src/protostar.rs @@ -21,7 +21,7 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { return match &icon.icon_type { IconType::Png => { - let t = Transform::from_rotation_scale(Quat::from_rotation_x(PI/2.0),[0.03,0.03,0.03]); + let t = Transform::from_rotation_scale(Quat::from_rotation_x(PI/2.0)*Quat::from_rotation_y(PI),[0.03,0.03,0.03]); let model = Model::create( parent, @@ -113,7 +113,7 @@ impl ProtoStar { .unwrap_or_else(|| { Ok(Model::create( grabbable.content_parent(), - Transform::from_rotation_scale(Quat::from_rotation_x(PI/2.0),[0.03,0.03,0.03]), + Transform::from_rotation_scale(Quat::from_xyzw(0.0,0.707,0.707,0.0),[0.03,0.03,0.03]), &ResourceID::new_namespaced("protostar", "hexagon/hexagon"), )?) })?; @@ -158,7 +158,7 @@ impl RootHandler for ProtoStar { startup_settings .set_root(self.grabbable.content_parent()) .unwrap(); - self.icon_shrink = Some(Tweener::quart_in_out(1.0, 0.0, 0.25)); + self.icon_shrink = Some(Tweener::quart_in_out(0.03, 0.0, 0.25)); //TODO make the scale a parameter let future = startup_settings.generate_startup_token().unwrap(); let executable = dbg!(self.execute_command.clone()); //TODO: split the executable string for the args