Cleaned up dependecies
This commit is contained in:
@@ -8,7 +8,9 @@ use protostar::{
|
||||
};
|
||||
use stardust_xr_fusion::{
|
||||
client::{Client, FrameInfo, RootHandler},
|
||||
spatial::Spatial, drawable::{Text, TextStyle, Bounds, TextFit, Alignment}, core::values::Transform,
|
||||
core::values::Transform,
|
||||
drawable::{Alignment, Bounds, Text, TextFit, TextStyle},
|
||||
spatial::Spatial,
|
||||
};
|
||||
|
||||
const APP_LIMIT: usize = 300;
|
||||
@@ -39,7 +41,6 @@ struct AppGrid {
|
||||
//style: TextStyle,
|
||||
}
|
||||
impl AppGrid {
|
||||
|
||||
fn new(client: &Client) -> Self {
|
||||
let apps = get_desktop_files()
|
||||
.into_iter()
|
||||
@@ -96,15 +97,15 @@ impl App {
|
||||
};
|
||||
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(),
|
||||
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)
|
||||
|
||||
@@ -8,7 +8,9 @@ use protostar::{
|
||||
};
|
||||
use stardust_xr_molecules::fusion::{
|
||||
client::{Client, FrameInfo, RootHandler},
|
||||
spatial::Spatial, drawable::{Text, TextStyle, Bounds, TextFit, Alignment}, core::values::Transform,
|
||||
core::values::Transform,
|
||||
drawable::{Alignment, Bounds, Text, TextFit, TextStyle},
|
||||
spatial::Spatial,
|
||||
};
|
||||
use tween::TweenTime;
|
||||
|
||||
@@ -20,32 +22,37 @@ struct Hex {
|
||||
s: isize,
|
||||
}
|
||||
|
||||
const HEX_CENTER: Hex = Hex{q:0,r:0,s:0};
|
||||
const HEX_CENTER: Hex = Hex { q: 0, r: 0, s: 0 };
|
||||
const HEX_DIRECTION_VECTORS: [Hex; 6] = [
|
||||
Hex{q:1, r:0, s:-1}, Hex{q:1, r:-1, s:0}, Hex{q:0, r:-1, s:1},
|
||||
Hex{q:-1, r:0, s:1}, Hex{q:-1, r:1, s:0}, Hex{q:0, r:1, s:-1},
|
||||
Hex { q: 1, r: 0, s: -1 },
|
||||
Hex { q: 1, r: -1, s: 0 },
|
||||
Hex { q: 0, r: -1, s: 1 },
|
||||
Hex { q: -1, r: 0, s: 1 },
|
||||
Hex { q: -1, r: 1, s: 0 },
|
||||
Hex { q: 0, r: 1, s: -1 },
|
||||
];
|
||||
|
||||
impl Hex {
|
||||
fn new(q:isize, r:isize, s:isize) -> Self{
|
||||
Hex{q:q, r:r, s:s}
|
||||
fn new(q: isize, r: isize, s: isize) -> Self {
|
||||
Hex { q: q, r: r, s: s }
|
||||
}
|
||||
|
||||
fn get_coords(&self) -> [f32; 3]{
|
||||
let x = 3.0/2.0 * APP_SIZE/2.0 * (-self.q-self.s).to_f32();
|
||||
let y = 3.0_f32.sqrt() * APP_SIZE/2.0 * ( (-self.q-self.s).to_f32()/2.0 + self.s.to_f32());
|
||||
[x,y,0.0]
|
||||
fn get_coords(&self) -> [f32; 3] {
|
||||
let x = 3.0 / 2.0 * APP_SIZE / 2.0 * (-self.q - self.s).to_f32();
|
||||
let y =
|
||||
3.0_f32.sqrt() * APP_SIZE / 2.0 * ((-self.q - self.s).to_f32() / 2.0 + self.s.to_f32());
|
||||
[x, y, 0.0]
|
||||
}
|
||||
|
||||
fn add(self, vec:&Hex) -> Self{
|
||||
fn add(self, vec: &Hex) -> Self {
|
||||
Hex::new(self.q + vec.q, self.r + vec.r, self.s + vec.s)
|
||||
}
|
||||
|
||||
fn neighbor(self, direction:usize) -> Self{
|
||||
fn neighbor(self, direction: usize) -> Self {
|
||||
self.add(&HEX_DIRECTION_VECTORS[direction])
|
||||
}
|
||||
|
||||
fn scale(self, factor:isize) -> Self {
|
||||
fn scale(self, factor: isize) -> Self {
|
||||
Hex::new(self.q * factor, self.r * factor, self.s * factor)
|
||||
}
|
||||
}
|
||||
@@ -73,7 +80,6 @@ struct AppHexGrid {
|
||||
apps: Vec<App>,
|
||||
}
|
||||
impl AppHexGrid {
|
||||
|
||||
fn new(client: &Client) -> Self {
|
||||
let mut desktop_files: Vec<DesktopFile> = get_desktop_files()
|
||||
.into_iter()
|
||||
@@ -84,19 +90,30 @@ impl AppHexGrid {
|
||||
desktop_files.sort_by_key(|d| d.clone().name.unwrap());
|
||||
|
||||
let mut apps = Vec::new();
|
||||
let mut radius = 1;
|
||||
let mut radius = 1;
|
||||
while !desktop_files.is_empty() {
|
||||
let mut hex = HEX_CENTER.add(&HEX_DIRECTION_VECTORS[4].clone().scale(radius));
|
||||
for i in 0..6{
|
||||
if desktop_files.is_empty() {break};
|
||||
for _ in 0..radius{
|
||||
if desktop_files.is_empty() {break};
|
||||
apps.push(App::new(client.get_root(),hex.get_coords(),desktop_files.pop().unwrap()).unwrap());
|
||||
hex = hex.neighbor(i);
|
||||
}
|
||||
for i in 0..6 {
|
||||
if desktop_files.is_empty() {
|
||||
break;
|
||||
};
|
||||
for _ in 0..radius {
|
||||
if desktop_files.is_empty() {
|
||||
break;
|
||||
};
|
||||
apps.push(
|
||||
App::new(
|
||||
client.get_root(),
|
||||
hex.get_coords(),
|
||||
desktop_files.pop().unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
hex = hex.neighbor(i);
|
||||
}
|
||||
}
|
||||
radius += 1;
|
||||
}
|
||||
}
|
||||
AppHexGrid { apps }
|
||||
}
|
||||
}
|
||||
@@ -120,7 +137,7 @@ impl App {
|
||||
desktop_file: DesktopFile,
|
||||
) -> Option<Self> {
|
||||
let position = position.into();
|
||||
let style= TextStyle {
|
||||
let style = TextStyle {
|
||||
character_height: APP_SIZE * 0.1,
|
||||
bounds: Some(Bounds {
|
||||
bounds: [APP_SIZE; 2].into(),
|
||||
@@ -132,15 +149,12 @@ impl App {
|
||||
};
|
||||
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, 0.004],
|
||||
Quat::from_rotation_y(3.14),
|
||||
),
|
||||
desktop_file.name.as_deref().unwrap_or("Unknown"),
|
||||
style,
|
||||
)
|
||||
.unwrap();
|
||||
protostar.content_parent(),
|
||||
Transform::from_position_rotation([0.0, 0.0, 0.004], Quat::from_rotation_y(3.14)),
|
||||
desktop_file.name.as_deref().unwrap_or("Unknown"),
|
||||
style,
|
||||
)
|
||||
.unwrap();
|
||||
protostar
|
||||
.content_parent()
|
||||
.set_position(None, position)
|
||||
|
||||
Reference in New Issue
Block a user