Added button and animatations
This commit is contained in:
@@ -95,7 +95,8 @@ impl App {
|
|||||||
text_align: Alignment::XCenter | Alignment::YCenter,
|
text_align: Alignment::XCenter | Alignment::YCenter,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let protostar = ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?;
|
let protostar =
|
||||||
|
ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?;
|
||||||
let text = Text::create(
|
let text = Text::create(
|
||||||
protostar.content_parent(),
|
protostar.content_parent(),
|
||||||
Transform::from_position_rotation(
|
Transform::from_position_rotation(
|
||||||
|
|||||||
@@ -9,9 +9,12 @@ use protostar::{
|
|||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
client::{Client, FrameInfo, RootHandler},
|
client::{Client, FrameInfo, RootHandler},
|
||||||
core::values::Transform,
|
core::values::Transform,
|
||||||
drawable::{Alignment, Bounds, Text, TextFit, TextStyle},
|
drawable::{Alignment, Bounds, MaterialParameter, Model, ResourceID, Text, TextFit, TextStyle},
|
||||||
|
node::NodeError,
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
};
|
};
|
||||||
|
use stardust_xr_molecules::touch_plane::TouchPlane;
|
||||||
|
use std::f32::consts::PI;
|
||||||
use tween::TweenTime;
|
use tween::TweenTime;
|
||||||
|
|
||||||
const APP_SIZE: f32 = 0.065;
|
const APP_SIZE: f32 = 0.065;
|
||||||
@@ -34,7 +37,7 @@ const HEX_DIRECTION_VECTORS: [Hex; 6] = [
|
|||||||
|
|
||||||
impl Hex {
|
impl Hex {
|
||||||
fn new(q: isize, r: isize, s: isize) -> Self {
|
fn new(q: isize, r: isize, s: isize) -> Self {
|
||||||
Hex { q: q, r: r, s: s }
|
Hex { q, r, s }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_coords(&self) -> [f32; 3] {
|
fn get_coords(&self) -> [f32; 3] {
|
||||||
@@ -78,9 +81,11 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
struct AppHexGrid {
|
struct AppHexGrid {
|
||||||
apps: Vec<App>,
|
apps: Vec<App>,
|
||||||
|
button: Button,
|
||||||
}
|
}
|
||||||
impl AppHexGrid {
|
impl AppHexGrid {
|
||||||
fn new(client: &Client) -> Self {
|
fn new(client: &Client) -> Self {
|
||||||
|
let button = Button::new(client).unwrap();
|
||||||
let mut desktop_files: Vec<DesktopFile> = get_desktop_files()
|
let mut desktop_files: Vec<DesktopFile> = get_desktop_files()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|d| parse_desktop_file(d).ok())
|
.filter_map(|d| parse_desktop_file(d).ok())
|
||||||
@@ -114,11 +119,29 @@ impl AppHexGrid {
|
|||||||
}
|
}
|
||||||
radius += 1;
|
radius += 1;
|
||||||
}
|
}
|
||||||
AppHexGrid { apps }
|
AppHexGrid { apps, button }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl RootHandler for AppHexGrid {
|
impl RootHandler for AppHexGrid {
|
||||||
fn frame(&mut self, info: FrameInfo) {
|
fn frame(&mut self, info: FrameInfo) {
|
||||||
|
self.button.touch_plane.update();
|
||||||
|
if self.button.touch_plane.touch_started() {
|
||||||
|
dbg!("Touch started");
|
||||||
|
let color = [0.0, 1.0, 0.0, 1.0];
|
||||||
|
self.button
|
||||||
|
.model
|
||||||
|
.set_material_parameter(1, "color", MaterialParameter::Color(color))
|
||||||
|
.unwrap();
|
||||||
|
for app in &mut self.apps {
|
||||||
|
app.protostar.toggle();
|
||||||
|
}
|
||||||
|
} else if self.button.touch_plane.touch_stopped() {
|
||||||
|
let color = [0.0, 0.0, 1.0, 1.0];
|
||||||
|
self.button
|
||||||
|
.model
|
||||||
|
.set_material_parameter(1, "color", MaterialParameter::Color(color))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
for app in &mut self.apps {
|
for app in &mut self.apps {
|
||||||
app.frame(info);
|
app.frame(info);
|
||||||
}
|
}
|
||||||
@@ -147,7 +170,8 @@ impl App {
|
|||||||
text_align: Alignment::XCenter | Alignment::YCenter,
|
text_align: Alignment::XCenter | Alignment::YCenter,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let protostar = ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?;
|
let protostar =
|
||||||
|
ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?;
|
||||||
let text = Text::create(
|
let text = Text::create(
|
||||||
protostar.content_parent(),
|
protostar.content_parent(),
|
||||||
Transform::from_position_rotation([0.0, 0.0, 0.004], Quat::from_rotation_y(3.14)),
|
Transform::from_position_rotation([0.0, 0.0, 0.004], Quat::from_rotation_y(3.14)),
|
||||||
@@ -167,3 +191,33 @@ impl RootHandler for App {
|
|||||||
self.protostar.frame(info);
|
self.protostar.frame(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Button {
|
||||||
|
touch_plane: TouchPlane,
|
||||||
|
model: Model,
|
||||||
|
}
|
||||||
|
impl Button {
|
||||||
|
fn new(client: &Client) -> Result<Self, NodeError> {
|
||||||
|
let touch_plane = TouchPlane::new(
|
||||||
|
client.get_root(),
|
||||||
|
Transform::default(),
|
||||||
|
[APP_SIZE / 2.0, APP_SIZE / 2.0],
|
||||||
|
APP_SIZE / 2.0,
|
||||||
|
)?;
|
||||||
|
let model = Model::create(
|
||||||
|
client.get_root(),
|
||||||
|
Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
[0.03, 0.03, 0.03],
|
||||||
|
),
|
||||||
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
|
)?;
|
||||||
|
model
|
||||||
|
.set_material_parameter(1, "color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))
|
||||||
|
.unwrap();
|
||||||
|
Ok(Button { touch_plane, model })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl RootHandler for Button {
|
||||||
|
fn frame(&mut self, _info: FrameInfo) {}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ async fn main() -> Result<()> {
|
|||||||
let protostar = if let Some(desktop_file) = args.desktop_file {
|
let protostar = if let Some(desktop_file) = args.desktop_file {
|
||||||
ProtoStar::create_from_desktop_file(
|
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(desktop_file).map_err(|e| Report::msg(e))?,
|
parse_desktop_file(desktop_file).map_err(|e| Report::msg(e))?,
|
||||||
)?
|
)?
|
||||||
} else if let Some(command) = args.command {
|
} else if let Some(command) = args.command {
|
||||||
ProtoStar::new_raw(client.get_root(), [0.0,0.0,0.0],None, command)?
|
ProtoStar::new_raw(client.get_root(), [0.0, 0.0, 0.0], None, command)?
|
||||||
} else {
|
} else {
|
||||||
bail!("No command or desktop file, nothing to launch.");
|
bail!("No command or desktop file, nothing to launch.");
|
||||||
};
|
};
|
||||||
|
|||||||
114
src/protostar.rs
114
src/protostar.rs
@@ -4,13 +4,13 @@ use glam::Quat;
|
|||||||
use mint::Vector3;
|
use mint::Vector3;
|
||||||
use nix::unistd::setsid;
|
use nix::unistd::setsid;
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
client::{Client, FrameInfo, RootHandler},
|
client::{Client, FrameInfo, RootHandler},
|
||||||
core::values::Transform,
|
core::values::Transform,
|
||||||
drawable::{MaterialParameter, Model, ResourceID},
|
drawable::{MaterialParameter, Model, ResourceID},
|
||||||
fields::BoxField,
|
fields::BoxField,
|
||||||
node::NodeType,
|
node::NodeType,
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
startup_settings::StartupSettings,
|
startup_settings::StartupSettings,
|
||||||
};
|
};
|
||||||
use stardust_xr_molecules::{GrabData, Grabbable};
|
use stardust_xr_molecules::{GrabData, Grabbable};
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
@@ -58,12 +58,17 @@ pub struct ProtoStar {
|
|||||||
grabbable: Grabbable,
|
grabbable: Grabbable,
|
||||||
field: BoxField,
|
field: BoxField,
|
||||||
icon: Model,
|
icon: Model,
|
||||||
icon_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
icon_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
execute_command: String,
|
execute_command: String,
|
||||||
|
currently_shown: bool,
|
||||||
}
|
}
|
||||||
impl ProtoStar {
|
impl ProtoStar {
|
||||||
pub fn create_from_desktop_file(parent: &Spatial, position: impl Into<Vector3<f32>>, desktop_file: DesktopFile) -> Result<Self> {
|
pub fn create_from_desktop_file(
|
||||||
|
parent: &Spatial,
|
||||||
|
position: impl Into<Vector3<f32>>,
|
||||||
|
desktop_file: DesktopFile,
|
||||||
|
) -> Result<Self> {
|
||||||
// dbg!(&desktop_file);
|
// dbg!(&desktop_file);
|
||||||
let raw_icons = desktop_file.get_raw_icons();
|
let raw_icons = desktop_file.get_raw_icons();
|
||||||
let mut icon = raw_icons
|
let mut icon = raw_icons
|
||||||
@@ -92,7 +97,12 @@ impl ProtoStar {
|
|||||||
desktop_file.command.ok_or_else(|| eyre!("No command"))?,
|
desktop_file.command.ok_or_else(|| eyre!("No command"))?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn new_raw(parent: &Spatial, position: impl Into<Vector3<f32>>, icon: Option<Icon>, execute_command: String) -> Result<Self> {
|
pub fn new_raw(
|
||||||
|
parent: &Spatial,
|
||||||
|
position: impl Into<Vector3<f32>>,
|
||||||
|
icon: Option<Icon>,
|
||||||
|
execute_command: String,
|
||||||
|
) -> Result<Self> {
|
||||||
let position = position.into();
|
let position = position.into();
|
||||||
let field = BoxField::create(
|
let field = BoxField::create(
|
||||||
parent,
|
parent,
|
||||||
@@ -130,65 +140,85 @@ impl ProtoStar {
|
|||||||
grabbable,
|
grabbable,
|
||||||
field,
|
field,
|
||||||
icon,
|
icon,
|
||||||
icon_shrink: None,
|
grabbable_shrink: None,
|
||||||
icon_grow: None,
|
grabbable_grow: None,
|
||||||
execute_command,
|
execute_command,
|
||||||
|
currently_shown: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn content_parent(&self) -> &Spatial {
|
pub fn content_parent(&self) -> &Spatial {
|
||||||
self.grabbable.content_parent()
|
self.grabbable.content_parent()
|
||||||
}
|
}
|
||||||
|
pub fn toggle(&mut self) {
|
||||||
|
if self.currently_shown {
|
||||||
|
self.grabbable_shrink = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter
|
||||||
|
} else {
|
||||||
|
self.grabbable_grow = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
}
|
||||||
|
self.currently_shown = !self.currently_shown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl RootHandler for ProtoStar {
|
impl RootHandler for ProtoStar {
|
||||||
fn frame(&mut self, info: FrameInfo) {
|
fn frame(&mut self, info: FrameInfo) {
|
||||||
self.grabbable.update(&info);
|
self.grabbable.update(&info);
|
||||||
if let Some(icon_shrink) = &mut self.icon_shrink {
|
|
||||||
if !icon_shrink.is_finished() {
|
if let Some(grabbable_shrink) = &mut self.grabbable_shrink {
|
||||||
let scale = icon_shrink.move_by(info.delta);
|
if !grabbable_shrink.is_finished() {
|
||||||
self.icon
|
let scale = grabbable_shrink.move_by(info.delta);
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
.set_scale(None, Vector3::from([scale; 3]))
|
.set_scale(None, Vector3::from([scale; 3]))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
self.icon_grow = Some(Tweener::quart_in_out(0.0001, 0.03, 0.25)); //TODO make the scale a parameter
|
if self.currently_shown {
|
||||||
self.icon_shrink = None;
|
self.grabbable_grow = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25)); //TODO make the scale a parameter
|
||||||
self.grabbable.content_parent().set_position(Some(self.client.get_root()) , self.position).unwrap();
|
}
|
||||||
self.grabbable.content_parent().set_rotation(Some(self.client.get_root()), Quat::default()).unwrap();
|
self.grabbable_shrink = None;
|
||||||
self.icon.set_rotation(None, Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI) ).unwrap();
|
self.grabbable
|
||||||
}
|
.content_parent()
|
||||||
} else if let Some(icon_grow) = &mut self.icon_grow {
|
.set_position(Some(self.client.get_root()), self.position)
|
||||||
if !icon_grow.is_finished() {
|
.unwrap();
|
||||||
let scale = icon_grow.move_by(info.delta);
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_rotation(Some(self.client.get_root()), Quat::default())
|
||||||
|
.unwrap();
|
||||||
self.icon
|
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(None, Vector3::from([scale; 3]))
|
.set_scale(None, Vector3::from([scale; 3]))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
self.icon_grow = None;
|
self.grabbable_grow = None;
|
||||||
}
|
}
|
||||||
}else if self.grabbable.grab_action().actor_stopped() {
|
} else if self.grabbable.grab_action().actor_stopped() {
|
||||||
let startup_settings = StartupSettings::create(&self.field.client().unwrap()).unwrap();
|
let startup_settings = StartupSettings::create(&self.field.client().unwrap()).unwrap();
|
||||||
//self.icon
|
|
||||||
// .set_spatial_parent_in_place(self.client.get_root())
|
|
||||||
// .unwrap();
|
|
||||||
//self.grabbable
|
|
||||||
// .content_parent()
|
|
||||||
// .set_rotation(
|
|
||||||
// Some(&self.field.client().unwrap().get_root()),
|
|
||||||
// Quat::IDENTITY,
|
|
||||||
// )
|
|
||||||
// .unwrap();
|
|
||||||
startup_settings
|
startup_settings
|
||||||
.set_root(self.grabbable.content_parent())
|
.set_root(self.grabbable.content_parent())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.icon_shrink = Some(Tweener::quart_in_out(0.03, 0.0001, 0.25)); //TODO make the scale a parameter
|
self.grabbable_shrink = Some(Tweener::quart_in_out(0.03, 0.0001, 0.25)); //TODO make the scale a parameter
|
||||||
let distance_future = self.grabbable.content_parent().get_position_rotation_scale(self.client.get_root()).unwrap();
|
let distance_future = self
|
||||||
|
.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.get_position_rotation_scale(self.client.get_root())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let executable = dbg!(self.execute_command.clone());
|
let executable = dbg!(self.execute_command.clone());
|
||||||
|
|
||||||
//TODO: split the executable string for the args
|
//TODO: split the executable string for the args
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
let distance_vector = distance_future.await.ok().unwrap().0;
|
let distance_vector = distance_future.await.ok().unwrap().0;
|
||||||
let distance = distance_vector.x.abs() + distance_vector.y.abs() + distance_vector.z.abs();
|
let distance =
|
||||||
if dbg!(distance) > 1.0 {
|
distance_vector.x.abs() + distance_vector.y.abs() + distance_vector.z.abs();
|
||||||
|
if dbg!(distance) > 1.0 {
|
||||||
let future = startup_settings.generate_startup_token().unwrap();
|
let future = startup_settings.generate_startup_token().unwrap();
|
||||||
|
|
||||||
std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap());
|
std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap());
|
||||||
|
|||||||
Reference in New Issue
Block a user