mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 04:28:11 +08:00
Add automatic type conversion from number to Vec2 by splatting (#3394)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use crate::{
|
||||
Node,
|
||||
table::{Table, TableRow},
|
||||
transform::Footprint,
|
||||
};
|
||||
use crate::Node;
|
||||
use crate::table::{Table, TableRow};
|
||||
use crate::transform::Footprint;
|
||||
use glam::DVec2;
|
||||
use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -55,12 +54,10 @@ impl<T: ToString + Send> Convert<String, ()> for T {
|
||||
}
|
||||
}
|
||||
|
||||
// trait mentioning inner type in args
|
||||
pub trait TableConvert<U> {
|
||||
fn convert_row(self) -> U;
|
||||
}
|
||||
|
||||
//
|
||||
impl<U, T: TableConvert<U> + Send> Convert<Table<U>, ()> for Table<T> {
|
||||
async fn convert(self, _: Footprint, _: ()) -> Table<U> {
|
||||
let table: Table<U> = self
|
||||
@@ -76,6 +73,12 @@ impl<U, T: TableConvert<U> + Send> Convert<Table<U>, ()> for Table<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Convert<DVec2, ()> for DVec2 {
|
||||
async fn convert(self, _: Footprint, _: ()) -> DVec2 {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Implements the [`Convert`] trait for conversion between the cartesian product of Rust's primitive numeric types.
|
||||
macro_rules! impl_convert {
|
||||
($from:ty, $to:ty) => {
|
||||
@@ -100,6 +103,12 @@ macro_rules! impl_convert {
|
||||
impl_convert!(u128, $to);
|
||||
impl_convert!(isize, $to);
|
||||
impl_convert!(usize, $to);
|
||||
|
||||
impl Convert<DVec2, ()> for $to {
|
||||
async fn convert(self, _: Footprint, _: ()) -> DVec2 {
|
||||
DVec2::splat(self as f64)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
impl_convert!(f32);
|
||||
|
||||
Reference in New Issue
Block a user