mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 06:38:52 +00:00
fix: use traits for enums to/from number and string
This commit is contained in:
parent
c8f219402b
commit
de4aebd40f
2 changed files with 52 additions and 40 deletions
|
@ -21,33 +21,10 @@ pub enum XRServiceType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRServiceType {
|
impl XRServiceType {
|
||||||
pub fn from_string(s: String) -> Self {
|
|
||||||
match s.trim().to_lowercase().as_str() {
|
|
||||||
"monado" => Self::Monado,
|
|
||||||
"wivrn" => Self::Wivrn,
|
|
||||||
_ => Self::Monado,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn iter() -> Iter<'static, Self> {
|
pub fn iter() -> Iter<'static, Self> {
|
||||||
[Self::Monado, Self::Wivrn].iter()
|
[Self::Monado, Self::Wivrn].iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_number(&self) -> u32 {
|
|
||||||
match self {
|
|
||||||
Self::Monado => 0,
|
|
||||||
Self::Wivrn => 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_number(i: u32) -> Self {
|
|
||||||
match i {
|
|
||||||
0 => Self::Monado,
|
|
||||||
1 => Self::Wivrn,
|
|
||||||
_ => panic!("XRServiceType index out of bounds"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// relative path from the prefix lib dir of the libopenxr shared object
|
/// relative path from the prefix lib dir of the libopenxr shared object
|
||||||
pub fn libopenxr_path(&self) -> &'static str {
|
pub fn libopenxr_path(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
@ -65,6 +42,35 @@ impl XRServiceType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&str> for XRServiceType {
|
||||||
|
fn from(s: &str) -> Self {
|
||||||
|
match s.trim().to_lowercase().as_str() {
|
||||||
|
"monado" => Self::Monado,
|
||||||
|
"wivrn" => Self::Wivrn,
|
||||||
|
_ => Self::Monado,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u32> for XRServiceType {
|
||||||
|
fn from(i: u32) -> Self {
|
||||||
|
match i {
|
||||||
|
0 => Self::Monado,
|
||||||
|
1 => Self::Wivrn,
|
||||||
|
_ => panic!("XRServiceType index out of bounds"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<u32> for XRServiceType {
|
||||||
|
fn into(self) -> u32 {
|
||||||
|
match self {
|
||||||
|
Self::Monado => 0,
|
||||||
|
Self::Wivrn => 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for XRServiceType {
|
impl Display for XRServiceType {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_str(match self {
|
f.write_str(match self {
|
||||||
|
@ -182,8 +188,8 @@ impl Default for LighthouseDriver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LighthouseDriver {
|
impl From<&str> for LighthouseDriver {
|
||||||
pub fn from_string(s: String) -> Self {
|
fn from(s: &str) -> Self {
|
||||||
match s.trim().to_lowercase().as_str() {
|
match s.trim().to_lowercase().as_str() {
|
||||||
"vive" => Self::Vive,
|
"vive" => Self::Vive,
|
||||||
"survive" => Self::Survive,
|
"survive" => Self::Survive,
|
||||||
|
@ -193,20 +199,10 @@ impl LighthouseDriver {
|
||||||
_ => Self::Vive,
|
_ => Self::Vive,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn iter() -> Iter<'static, Self> {
|
impl From<u32> for LighthouseDriver {
|
||||||
[Self::Vive, Self::Survive, Self::SteamVR].iter()
|
fn from(i: u32) -> Self {
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_number(&self) -> u32 {
|
|
||||||
match self {
|
|
||||||
Self::Vive => 0,
|
|
||||||
Self::Survive => 1,
|
|
||||||
Self::SteamVR => 2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_number(i: u32) -> Self {
|
|
||||||
match i {
|
match i {
|
||||||
0 => Self::Vive,
|
0 => Self::Vive,
|
||||||
1 => Self::Survive,
|
1 => Self::Survive,
|
||||||
|
@ -216,6 +212,22 @@ impl LighthouseDriver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<u32> for LighthouseDriver {
|
||||||
|
fn into(self) -> u32 {
|
||||||
|
match self {
|
||||||
|
Self::Vive => 0,
|
||||||
|
Self::Survive => 1,
|
||||||
|
Self::SteamVR => 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LighthouseDriver {
|
||||||
|
pub fn iter() -> Iter<'static, Self> {
|
||||||
|
[Self::Vive, Self::Survive, Self::SteamVR].iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for LighthouseDriver {
|
impl Display for LighthouseDriver {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_str(match self {
|
f.write_str(match self {
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl SimpleComponent for ProfileEditor {
|
||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
clone!(#[strong] prof, move |row| {
|
clone!(#[strong] prof, move |row| {
|
||||||
prof.borrow_mut().xrservice_type =
|
prof.borrow_mut().xrservice_type =
|
||||||
XRServiceType::from_number(row.selected());
|
XRServiceType::from(row.selected());
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
add: &entry_row(
|
add: &entry_row(
|
||||||
|
@ -171,7 +171,7 @@ impl SimpleComponent for ProfileEditor {
|
||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
clone!(#[strong] prof, move |row| {
|
clone!(#[strong] prof, move |row| {
|
||||||
prof.borrow_mut().lighthouse_driver =
|
prof.borrow_mut().lighthouse_driver =
|
||||||
LighthouseDriver::from_number(row.selected());
|
LighthouseDriver::from(row.selected());
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
add: &path_row(
|
add: &path_row(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue