feat: workspace!!!
This commit is contained in:
23
hexagon_launcher/Cargo.toml
Normal file
23
hexagon_launcher/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "hexagon_launcher"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.32.0", features = ["rt", "tokio-macros", "sync"] }
|
||||
protostar = { path = "../protostar" }
|
||||
color-eyre = "0.6.2"
|
||||
clap = "4.4.6"
|
||||
manifest-dir-macros = "0.1.18"
|
||||
glam = "0.24.2"
|
||||
mint = "0.5.9"
|
||||
tween = "2.0.1"
|
||||
tracing-subscriber = "0.3.17"
|
||||
|
||||
[dependencies.stardust-xr-fusion]
|
||||
git = "https://github.com/StardustXR/core.git"
|
||||
# path = "../../core/fusion"
|
||||
|
||||
[dependencies.stardust-xr-molecules]
|
||||
git = "https://github.com/StardustXR/molecules.git"
|
||||
# path = "../../molecules"
|
||||
BIN
hexagon_launcher/res/protostar/button.glb
Normal file
BIN
hexagon_launcher/res/protostar/button.glb
Normal file
Binary file not shown.
BIN
hexagon_launcher/res/protostar/cartridge.glb
Normal file
BIN
hexagon_launcher/res/protostar/cartridge.glb
Normal file
Binary file not shown.
BIN
hexagon_launcher/res/protostar/default_icon.glb
Executable file
BIN
hexagon_launcher/res/protostar/default_icon.glb
Executable file
Binary file not shown.
BIN
hexagon_launcher/res/protostar/hexagon/hex_atlas.png
Normal file
BIN
hexagon_launcher/res/protostar/hexagon/hex_atlas.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
BIN
hexagon_launcher/res/protostar/hexagon/hexagon.bin
Normal file
BIN
hexagon_launcher/res/protostar/hexagon/hexagon.bin
Normal file
Binary file not shown.
286
hexagon_launcher/res/protostar/hexagon/hexagon.gltf
Normal file
286
hexagon_launcher/res/protostar/hexagon/hexagon.gltf
Normal file
@@ -0,0 +1,286 @@
|
||||
{
|
||||
"asset":{
|
||||
"generator":"Khronos glTF Blender I/O v3.5.30",
|
||||
"version":"2.0"
|
||||
},
|
||||
"extensionsUsed":[
|
||||
"KHR_materials_unlit"
|
||||
],
|
||||
"scene":0,
|
||||
"scenes":[
|
||||
{
|
||||
"name":"Scene",
|
||||
"nodes":[
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes":[
|
||||
{
|
||||
"mesh":0,
|
||||
"name":"Icon"
|
||||
},
|
||||
{
|
||||
"mesh":1,
|
||||
"name":"Hex"
|
||||
}
|
||||
],
|
||||
"materials":[
|
||||
{
|
||||
"alphaCutoff":0.5,
|
||||
"alphaMode":"MASK",
|
||||
"extensions":{
|
||||
"KHR_materials_unlit":{}
|
||||
},
|
||||
"name":"Icon",
|
||||
"pbrMetallicRoughness":{
|
||||
"baseColorTexture":{
|
||||
"index":0,
|
||||
"texCoord":0
|
||||
},
|
||||
"metallicFactor":0,
|
||||
"roughnessFactor":0.9
|
||||
}
|
||||
},
|
||||
{
|
||||
"alphaMode":"BLEND",
|
||||
"extensions":{
|
||||
"KHR_materials_unlit":{}
|
||||
},
|
||||
"name":"Hex",
|
||||
"pbrMetallicRoughness":{
|
||||
"baseColorFactor":[
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"baseColorTexture":{
|
||||
"index":1,
|
||||
"texCoord":0
|
||||
},
|
||||
"metallicFactor":0,
|
||||
"roughnessFactor":0.9
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes":[
|
||||
{
|
||||
"name":"Circle",
|
||||
"primitives":[
|
||||
{
|
||||
"attributes":{
|
||||
"COLOR_0":0,
|
||||
"POSITION":1,
|
||||
"TEXCOORD_0":2,
|
||||
"NORMAL":3
|
||||
},
|
||||
"indices":4,
|
||||
"material":0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"Circle.001",
|
||||
"primitives":[
|
||||
{
|
||||
"attributes":{
|
||||
"COLOR_0":5,
|
||||
"POSITION":6,
|
||||
"TEXCOORD_0":7,
|
||||
"NORMAL":8
|
||||
},
|
||||
"indices":9,
|
||||
"material":1
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures":[
|
||||
{
|
||||
"sampler":0,
|
||||
"source":0
|
||||
},
|
||||
{
|
||||
"sampler":1,
|
||||
"source":1
|
||||
}
|
||||
],
|
||||
"images":[
|
||||
{
|
||||
"mimeType":"image/png",
|
||||
"name":"icon_test",
|
||||
"uri":"icon_test.png"
|
||||
},
|
||||
{
|
||||
"mimeType":"image/png",
|
||||
"name":"hex_atlas",
|
||||
"uri":"hex_atlas.png"
|
||||
}
|
||||
],
|
||||
"accessors":[
|
||||
{
|
||||
"bufferView":0,
|
||||
"componentType":5123,
|
||||
"count":4,
|
||||
"normalized":true,
|
||||
"type":"VEC4"
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"componentType":5126,
|
||||
"count":4,
|
||||
"max":[
|
||||
0.5853440165519714,
|
||||
0.05000000074505806,
|
||||
0.5853440165519714
|
||||
],
|
||||
"min":[
|
||||
-0.5853440165519714,
|
||||
0.05000000074505806,
|
||||
-0.5853440165519714
|
||||
],
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":2,
|
||||
"componentType":5126,
|
||||
"count":4,
|
||||
"type":"VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView":3,
|
||||
"componentType":5126,
|
||||
"count":4,
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":4,
|
||||
"componentType":5123,
|
||||
"count":6,
|
||||
"type":"SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView":5,
|
||||
"componentType":5123,
|
||||
"count":54,
|
||||
"normalized":true,
|
||||
"type":"VEC4"
|
||||
},
|
||||
{
|
||||
"bufferView":6,
|
||||
"componentType":5126,
|
||||
"count":54,
|
||||
"max":[
|
||||
1.0441828966140747,
|
||||
0.05000000074505806,
|
||||
0.9042890667915344
|
||||
],
|
||||
"min":[
|
||||
-1.0441828966140747,
|
||||
0,
|
||||
-0.9042890667915344
|
||||
],
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":7,
|
||||
"componentType":5126,
|
||||
"count":54,
|
||||
"type":"VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView":8,
|
||||
"componentType":5126,
|
||||
"count":54,
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":9,
|
||||
"componentType":5123,
|
||||
"count":84,
|
||||
"type":"SCALAR"
|
||||
}
|
||||
],
|
||||
"bufferViews":[
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":32,
|
||||
"byteOffset":0,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":48,
|
||||
"byteOffset":32,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":32,
|
||||
"byteOffset":80,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":48,
|
||||
"byteOffset":112,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":12,
|
||||
"byteOffset":160,
|
||||
"target":34963
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":432,
|
||||
"byteOffset":172,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":648,
|
||||
"byteOffset":604,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":432,
|
||||
"byteOffset":1252,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":648,
|
||||
"byteOffset":1684,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":168,
|
||||
"byteOffset":2332,
|
||||
"target":34963
|
||||
}
|
||||
],
|
||||
"samplers":[
|
||||
{
|
||||
"magFilter":9729,
|
||||
"minFilter":9987,
|
||||
"wrapS":33071,
|
||||
"wrapT":33071
|
||||
},
|
||||
{
|
||||
"magFilter":9729,
|
||||
"minFilter":9987
|
||||
}
|
||||
],
|
||||
"buffers":[
|
||||
{
|
||||
"byteLength":2500,
|
||||
"uri":"hexagon.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
hexagon_launcher/res/protostar/hexagon/icon_test.png
Normal file
BIN
hexagon_launcher/res/protostar/hexagon/icon_test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
44
hexagon_launcher/src/hex.rs
Normal file
44
hexagon_launcher/src/hex.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::{APP_SIZE, PADDING};
|
||||
use tween::TweenTime;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Hex {
|
||||
q: isize,
|
||||
r: isize,
|
||||
s: isize,
|
||||
}
|
||||
|
||||
pub const HEX_CENTER: Hex = Hex { q: 0, r: 0, s: 0 };
|
||||
pub 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 },
|
||||
];
|
||||
|
||||
impl Hex {
|
||||
pub fn new(q: isize, r: isize, s: isize) -> Self {
|
||||
Hex { q, r, s }
|
||||
}
|
||||
|
||||
pub fn get_coords(&self) -> [f32; 3] {
|
||||
let x = 3.0 / 2.0 * (APP_SIZE + PADDING) / 2.0 * (-self.q - self.s).to_f32();
|
||||
let y = 3.0_f32.sqrt() * (APP_SIZE + PADDING) / 2.0
|
||||
* ((-self.q - self.s).to_f32() / 2.0 + self.s.to_f32());
|
||||
[x, y, 0.0]
|
||||
}
|
||||
|
||||
pub fn add(self, vec: &Hex) -> Self {
|
||||
Hex::new(self.q + vec.q, self.r + vec.r, self.s + vec.s)
|
||||
}
|
||||
|
||||
pub fn neighbor(self, direction: usize) -> Self {
|
||||
self.add(&HEX_DIRECTION_VECTORS[direction])
|
||||
}
|
||||
|
||||
pub fn scale(self, factor: isize) -> Self {
|
||||
Hex::new(self.q * factor, self.r * factor, self.s * factor)
|
||||
}
|
||||
}
|
||||
404
hexagon_launcher/src/main.rs
Normal file
404
hexagon_launcher/src/main.rs
Normal file
@@ -0,0 +1,404 @@
|
||||
pub mod hex;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use glam::{Quat, Vec3};
|
||||
use hex::{HEX_CENTER, HEX_DIRECTION_VECTORS};
|
||||
use manifest_dir_macros::directory_relative_path;
|
||||
use mint::Vector3;
|
||||
use protostar::{
|
||||
application::Application,
|
||||
xdg::{get_desktop_files, parse_desktop_file, DesktopFile, Icon, IconType},
|
||||
};
|
||||
use stardust_xr_fusion::{
|
||||
client::{Client, ClientState, FrameInfo, RootHandler},
|
||||
core::values::Transform,
|
||||
drawable::{Alignment, Bounds, MaterialParameter, Model, ResourceID, Text, TextFit, TextStyle},
|
||||
fields::BoxField,
|
||||
node::NodeError,
|
||||
node::NodeType,
|
||||
spatial::Spatial,
|
||||
};
|
||||
use stardust_xr_molecules::{touch_plane::TouchPlane, Grabbable, GrabbableSettings};
|
||||
use std::f32::consts::PI;
|
||||
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];
|
||||
|
||||
#[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<App>,
|
||||
button: Button,
|
||||
}
|
||||
impl AppHexGrid {
|
||||
fn new(client: &Client) -> Self {
|
||||
let button = Button::new(client).unwrap();
|
||||
let mut desktop_files: Vec<DesktopFile> = get_desktop_files()
|
||||
.filter_map(|d| parse_desktop_file(d).ok())
|
||||
.filter(|d| !d.no_display)
|
||||
.collect();
|
||||
|
||||
desktop_files.sort_by_key(|d| d.clone().name.unwrap_or_default());
|
||||
|
||||
let mut apps = Vec::new();
|
||||
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::create_from_desktop_file(
|
||||
button.grabbable.content_parent(),
|
||||
hex.get_coords(),
|
||||
desktop_files.pop().unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
hex = hex.neighbor(i);
|
||||
}
|
||||
}
|
||||
radius += 1;
|
||||
}
|
||||
AppHexGrid { apps, button }
|
||||
}
|
||||
}
|
||||
impl RootHandler for AppHexGrid {
|
||||
fn frame(&mut self, info: FrameInfo) {
|
||||
self.button.frame(info);
|
||||
if self.button.touch_plane.touch_started() {
|
||||
self.button
|
||||
.model
|
||||
.model_part("Hex")
|
||||
.unwrap()
|
||||
.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() {
|
||||
self.button
|
||||
.model
|
||||
.model_part("Hex")
|
||||
.unwrap()
|
||||
.set_material_parameter("color", MaterialParameter::Color(BTN_COLOR))
|
||||
.unwrap();
|
||||
}
|
||||
for app in &mut self.apps {
|
||||
app.frame(info);
|
||||
}
|
||||
}
|
||||
|
||||
fn save_state(&mut self) -> ClientState {
|
||||
ClientState::default()
|
||||
}
|
||||
}
|
||||
|
||||
struct Button {
|
||||
touch_plane: TouchPlane,
|
||||
grabbable: Grabbable,
|
||||
model: Model,
|
||||
}
|
||||
impl Button {
|
||||
fn new(client: &Client) -> Result<Self, NodeError> {
|
||||
let field = BoxField::create(client.get_root(), Transform::default(), [APP_SIZE; 3])?;
|
||||
let grabbable = Grabbable::create(
|
||||
client.get_root(),
|
||||
Transform::default(),
|
||||
&field,
|
||||
GrabbableSettings {
|
||||
max_distance: 0.01,
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
field.set_spatial_parent(grabbable.content_parent())?;
|
||||
let touch_plane = TouchPlane::create(
|
||||
grabbable.content_parent(),
|
||||
Transform::default(),
|
||||
[(APP_SIZE + PADDING) / 2.0; 2],
|
||||
(APP_SIZE + PADDING) / 2.0,
|
||||
0.0..1.0,
|
||||
0.0..1.0,
|
||||
)?;
|
||||
|
||||
let model = Model::create(
|
||||
grabbable.content_parent(),
|
||||
Transform::from_rotation_scale(
|
||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||
[MODEL_SCALE; 3],
|
||||
),
|
||||
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||
)?;
|
||||
model
|
||||
.model_part("Hex")?
|
||||
.set_material_parameter("color", MaterialParameter::Color(BTN_COLOR))?;
|
||||
Ok(Button {
|
||||
touch_plane,
|
||||
grabbable,
|
||||
model,
|
||||
})
|
||||
}
|
||||
|
||||
fn frame(&mut self, info: FrameInfo) {
|
||||
let _ = self.grabbable.update(&info);
|
||||
if self.grabbable.grab_action().actor_started() {
|
||||
let _ = self.touch_plane.set_enabled(false);
|
||||
}
|
||||
if self.grabbable.grab_action().actor_stopped() {
|
||||
let _ = self.touch_plane.set_enabled(true);
|
||||
}
|
||||
self.touch_plane.update();
|
||||
}
|
||||
}
|
||||
|
||||
// Model handling
|
||||
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||
match &icon.icon_type {
|
||||
IconType::Png => {
|
||||
let t = Transform::from_rotation_scale(
|
||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||
[APP_SIZE / 2.0; 3],
|
||||
);
|
||||
|
||||
let model = Model::create(
|
||||
parent,
|
||||
t,
|
||||
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||
)?;
|
||||
model
|
||||
.model_part("Hex")?
|
||||
.set_material_parameter("color", MaterialParameter::Color(CYAN))?;
|
||||
model.model_part("Icon")?.set_material_parameter(
|
||||
"diffuse",
|
||||
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
||||
)?;
|
||||
Ok(model)
|
||||
}
|
||||
IconType::Gltf => Ok(Model::create(
|
||||
parent,
|
||||
Transform::from_scale([0.05; 3]),
|
||||
&ResourceID::new_direct(icon.path.clone())?,
|
||||
)?),
|
||||
_ => panic!("Invalid Icon Type"),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
application: Application,
|
||||
parent: Spatial,
|
||||
position: Vector3<f32>,
|
||||
grabbable: Grabbable,
|
||||
_field: BoxField,
|
||||
icon: Model,
|
||||
label: Option<Text>,
|
||||
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
||||
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
||||
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
|
||||
currently_shown: bool,
|
||||
}
|
||||
impl App {
|
||||
pub fn create_from_desktop_file(
|
||||
parent: &Spatial,
|
||||
position: impl Into<Vector3<f32>>,
|
||||
desktop_file: DesktopFile,
|
||||
) -> Result<Self> {
|
||||
let position = position.into();
|
||||
let field = BoxField::create(parent, Transform::default(), [APP_SIZE; 3])?;
|
||||
let application = Application::create(desktop_file)?;
|
||||
let icon = application.icon(128, false);
|
||||
let grabbable = Grabbable::create(
|
||||
parent,
|
||||
Transform::from_position(position),
|
||||
&field,
|
||||
GrabbableSettings {
|
||||
max_distance: 0.01,
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
grabbable.content_parent().set_spatial_parent(parent)?;
|
||||
field.set_spatial_parent(grabbable.content_parent())?;
|
||||
let icon = icon
|
||||
.map(|i| model_from_icon(grabbable.content_parent(), &i))
|
||||
.unwrap_or_else(|| {
|
||||
Ok(Model::create(
|
||||
grabbable.content_parent(),
|
||||
Transform::from_rotation_scale(
|
||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||
[APP_SIZE * 0.5; 3],
|
||||
),
|
||||
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||
)?)
|
||||
})?;
|
||||
|
||||
let label_style = TextStyle {
|
||||
character_height: APP_SIZE * 2.0,
|
||||
bounds: Some(Bounds {
|
||||
bounds: [1.0; 2].into(),
|
||||
fit: TextFit::Wrap,
|
||||
bounds_align: Alignment::XCenter | Alignment::YCenter,
|
||||
}),
|
||||
text_align: Alignment::Center.into(),
|
||||
..Default::default()
|
||||
};
|
||||
let label = application.name().and_then(|name| {
|
||||
Text::create(
|
||||
&icon,
|
||||
Transform::from_position_rotation(
|
||||
[0.0, 0.1, -(APP_SIZE * 4.0)],
|
||||
Quat::from_rotation_x(PI * 0.5),
|
||||
),
|
||||
name,
|
||||
label_style,
|
||||
)
|
||||
.ok()
|
||||
});
|
||||
Ok(App {
|
||||
parent: parent.alias(),
|
||||
position,
|
||||
grabbable,
|
||||
_field: field,
|
||||
label,
|
||||
application,
|
||||
icon,
|
||||
grabbable_shrink: None,
|
||||
grabbable_grow: None,
|
||||
grabbable_move: None,
|
||||
currently_shown: true,
|
||||
})
|
||||
}
|
||||
pub fn content_parent(&self) -> &Spatial {
|
||||
self.grabbable.content_parent()
|
||||
}
|
||||
pub fn toggle(&mut self) {
|
||||
self.grabbable.set_enabled(!self.currently_shown).unwrap();
|
||||
if self.currently_shown {
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
fn frame(&mut self, info: FrameInfo) {
|
||||
let _ = self.grabbable.update(&info);
|
||||
|
||||
if let Some(grabbable_move) = &mut self.grabbable_move {
|
||||
if !grabbable_move.is_finished() {
|
||||
let scale = grabbable_move.move_by(info.delta);
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_position(Some(&self.parent), Vec3::from(self.position) * scale)
|
||||
.unwrap();
|
||||
} else {
|
||||
if grabbable_move.final_value() == 0.0001 {
|
||||
self.icon.set_enabled(false).unwrap();
|
||||
if let Some(label) = self.label.as_ref() {
|
||||
label.set_enabled(false).unwrap()
|
||||
}
|
||||
}
|
||||
self.grabbable_move = None;
|
||||
}
|
||||
}
|
||||
if let Some(grabbable_shrink) = &mut self.grabbable_shrink {
|
||||
if !grabbable_shrink.is_finished() {
|
||||
let scale = grabbable_shrink.move_by(info.delta);
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_scale(Some(&self.parent), Vector3::from([scale; 3]))
|
||||
.unwrap();
|
||||
} else {
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_spatial_parent(&self.parent)
|
||||
.unwrap();
|
||||
if self.currently_shown {
|
||||
self.grabbable_grow = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||
self.grabbable.cancel_angular_velocity();
|
||||
self.grabbable.cancel_linear_velocity();
|
||||
}
|
||||
self.grabbable_shrink = None;
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_position(Some(&self.parent), self.position)
|
||||
.unwrap();
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_rotation(Some(&self.parent), Quat::default())
|
||||
.unwrap();
|
||||
self.icon
|
||||
.set_rotation(
|
||||
None,
|
||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
} else if let Some(grabbable_grow) = &mut self.grabbable_grow {
|
||||
if !grabbable_grow.is_finished() {
|
||||
let scale = grabbable_grow.move_by(info.delta);
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_scale(Some(&self.parent), Vector3::from([scale; 3]))
|
||||
.unwrap();
|
||||
} else {
|
||||
self.grabbable
|
||||
.content_parent()
|
||||
.set_spatial_parent(&self.parent)
|
||||
.unwrap();
|
||||
self.grabbable_grow = None;
|
||||
}
|
||||
} else if self.grabbable.valid() && self.grabbable.grab_action().actor_stopped() {
|
||||
self.grabbable_shrink = Some(Tweener::quart_in_out(APP_SIZE * 0.5, 0.0001, 0.25));
|
||||
let Ok(distance_future) = self.grabbable
|
||||
.content_parent()
|
||||
.get_position_rotation_scale(&self.parent)
|
||||
else {return};
|
||||
|
||||
let application = self.application.clone();
|
||||
let space = self.content_parent().alias();
|
||||
|
||||
//TODO: split the executable string for the args
|
||||
tokio::task::spawn(async move {
|
||||
let distance_vector = distance_future.await.ok().unwrap().0;
|
||||
let distance = Vec3::from(distance_vector).length_squared();
|
||||
|
||||
if distance > ACTIVATION_DISTANCE {
|
||||
let _ = space.set_scale(None, [1.0; 3]);
|
||||
let _ = application.launch(&space);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user