Skip to content

Commit 74d29bd

Browse files
committed
f32: property support for f32
1 parent 71ad1c8 commit 74d29bd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

editor/src/messages/portfolio/document/node_graph/node_properties.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,14 @@ pub fn number_widget(parameter_widgets_info: ParameterWidgetsInfo, number_props:
805805
.on_commit(commit_value)
806806
.widget_holder(),
807807
]),
808+
Some(&TaggedValue::F32(x)) => widgets.extend_from_slice(&[
809+
Separator::new(SeparatorType::Unrelated).widget_holder(),
810+
number_props
811+
.value(Some(x as f64))
812+
.on_update(update_value(move |x: &NumberInput| TaggedValue::F32(x.value.unwrap() as f32), node_id, index))
813+
.on_commit(commit_value)
814+
.widget_holder(),
815+
]),
808816
Some(&TaggedValue::U32(x)) => widgets.extend_from_slice(&[
809817
Separator::new(SeparatorType::Unrelated).widget_holder(),
810818
number_props
@@ -851,6 +859,15 @@ pub fn number_widget(parameter_widgets_info: ParameterWidgetsInfo, number_props:
851859
.on_commit(commit_value)
852860
.widget_holder(),
853861
]),
862+
Some(&TaggedValue::Vec2(vec2)) => widgets.extend_from_slice(&[
863+
Separator::new(SeparatorType::Unrelated).widget_holder(),
864+
number_props
865+
// We use an arbitrary `y` instead of an arbitrary `x` here because the "Grid" node's "Spacing" value's height should be used from rectangular mode when transferred to "Y Spacing" in isometric mode
866+
.value(Some(vec2.y as f64))
867+
.on_update(update_value(move |x: &NumberInput| TaggedValue::F32(x.value.unwrap() as f32), node_id, index))
868+
.on_commit(commit_value)
869+
.widget_holder(),
870+
]),
854871
_ => {}
855872
}
856873

node-graph/graph-craft/src/document/value.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::proto::{Any as DAny, FutureAny};
33
use crate::wasm_application_io::WasmEditorApi;
44
use dyn_any::DynAny;
55
pub use dyn_any::StaticType;
6+
use glam::{Affine2, Vec2};
67
pub use glam::{DAffine2, DVec2, IVec2, UVec2};
78
use graphene_application_io::{ImageTexture, SurfaceFrame};
89
use graphene_brush::brush_cache::BrushCache;
@@ -163,7 +164,7 @@ tagged_value! {
163164
// ===============
164165
// PRIMITIVE TYPES
165166
// ===============
166-
#[serde(alias = "F32")] // TODO: Eventually remove this alias document upgrade code
167+
F32(f32),
167168
F64(f64),
168169
U32(u32),
169170
U64(u64),
@@ -201,6 +202,8 @@ tagged_value! {
201202
// ============
202203
// STRUCT TYPES
203204
// ============
205+
Vec2(Vec2),
206+
Affine2(Affine2),
204207
#[serde(alias = "IVec2", alias = "UVec2")]
205208
DVec2(DVec2),
206209
DAffine2(DAffine2),
@@ -463,6 +466,21 @@ mod fake_hash {
463466
self.to_cols_array().iter().for_each(|x| x.to_bits().hash(state))
464467
}
465468
}
469+
impl FakeHash for f32 {
470+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
471+
self.to_bits().hash(state)
472+
}
473+
}
474+
impl FakeHash for Vec2 {
475+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
476+
self.to_array().iter().for_each(|x| x.to_bits().hash(state))
477+
}
478+
}
479+
impl FakeHash for Affine2 {
480+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
481+
self.to_cols_array().iter().for_each(|x| x.to_bits().hash(state))
482+
}
483+
}
466484
impl<X: FakeHash> FakeHash for Option<X> {
467485
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
468486
if let Some(x) = self {

0 commit comments

Comments
 (0)