@@ -10,33 +10,46 @@ use graph_craft::document::{DocumentNode, NodeId, NodeInput};
10
10
use super :: FrontendGraphDataType ;
11
11
12
12
pub fn hue_shift_image_properties ( document_node : & DocumentNode , node_id : NodeId ) -> Vec < LayoutGroup > {
13
- vec ! [ LayoutGroup :: Row {
14
- widgets: vec![
15
- WidgetHolder :: new( Widget :: ParameterExposeButton ( ParameterExposeButton {
16
- exposed: true ,
17
- data_type: FrontendGraphDataType :: Number ,
18
- tooltip: "Expose input parameter in node graph" . into( ) ,
19
- ..Default :: default ( )
20
- } ) ) ,
21
- WidgetHolder :: new( Widget :: Separator ( Separator {
22
- separator_type: SeparatorType :: Unrelated ,
23
- direction: SeparatorDirection :: Horizontal ,
24
- } ) ) ,
25
- WidgetHolder :: new( Widget :: TextLabel ( TextLabel {
26
- value: "Shift Degrees" . into( ) ,
27
- ..Default :: default ( )
28
- } ) ) ,
13
+ let index = 1 ;
14
+ let input: & NodeInput = document_node. inputs . get ( index) . unwrap ( ) ;
15
+ let exposed = input. is_exposed ( ) ;
16
+
17
+ let mut widgets = vec ! [
18
+ WidgetHolder :: new( Widget :: ParameterExposeButton ( ParameterExposeButton {
19
+ exposed,
20
+ data_type: FrontendGraphDataType :: Number ,
21
+ tooltip: "Expose input parameter in node graph" . into( ) ,
22
+ on_update: WidgetCallback :: new( move |_parameter| {
23
+ NodeGraphMessage :: ExposeInput {
24
+ node_id,
25
+ input_index: index,
26
+ new_exposed: !exposed,
27
+ }
28
+ . into( )
29
+ } ) ,
30
+ ..Default :: default ( )
31
+ } ) ) ,
32
+ WidgetHolder :: new( Widget :: Separator ( Separator {
33
+ separator_type: SeparatorType :: Unrelated ,
34
+ direction: SeparatorDirection :: Horizontal ,
35
+ } ) ) ,
36
+ WidgetHolder :: new( Widget :: TextLabel ( TextLabel {
37
+ value: "Shift Degrees" . into( ) ,
38
+ ..Default :: default ( )
39
+ } ) ) ,
40
+ ] ;
41
+ if let NodeInput :: Value {
42
+ tagged_value : TaggedValue :: F32 ( x) ,
43
+ exposed : false ,
44
+ } = document_node. inputs [ index]
45
+ {
46
+ widgets. extend_from_slice ( & [
29
47
WidgetHolder :: new ( Widget :: Separator ( Separator {
30
48
separator_type : SeparatorType :: Unrelated ,
31
49
direction : SeparatorDirection :: Horizontal ,
32
50
} ) ) ,
33
51
WidgetHolder :: new ( Widget :: NumberInput ( NumberInput {
34
- value: Some ( {
35
- let NodeInput :: Value { tagged_value: TaggedValue :: F32 ( x) , ..} = document_node. inputs[ 1 ] else {
36
- panic!( "Hue rotate should be f32" )
37
- } ;
38
- x as f64
39
- } ) ,
52
+ value : Some ( x as f64 ) ,
40
53
unit : "°" . into ( ) ,
41
54
mode : NumberInputMode :: Range ,
42
55
range_min : Some ( -180. ) ,
@@ -51,38 +64,54 @@ pub fn hue_shift_image_properties(document_node: &DocumentNode, node_id: NodeId)
51
64
} ) ,
52
65
..NumberInput :: default ( )
53
66
} ) ) ,
54
- ] ,
55
- } ]
67
+ ] )
68
+ }
69
+
70
+ vec ! [ LayoutGroup :: Row { widgets } ]
56
71
}
57
72
58
73
pub fn brighten_image_properties ( document_node : & DocumentNode , node_id : NodeId ) -> Vec < LayoutGroup > {
59
- vec ! [ LayoutGroup :: Row {
60
- widgets: vec![
61
- WidgetHolder :: new( Widget :: ParameterExposeButton ( ParameterExposeButton {
62
- exposed: true ,
63
- data_type: FrontendGraphDataType :: Number ,
64
- tooltip: "Expose input parameter in node graph" . into( ) ,
65
- ..Default :: default ( )
66
- } ) ) ,
67
- WidgetHolder :: new( Widget :: Separator ( Separator {
68
- separator_type: SeparatorType :: Unrelated ,
69
- direction: SeparatorDirection :: Horizontal ,
70
- } ) ) ,
71
- WidgetHolder :: new( Widget :: TextLabel ( TextLabel {
72
- value: "Brighten Amount" . into( ) ,
73
- ..Default :: default ( )
74
- } ) ) ,
74
+ let index = 1 ;
75
+ let input: & NodeInput = document_node. inputs . get ( index) . unwrap ( ) ;
76
+ let exposed = input. is_exposed ( ) ;
77
+
78
+ let mut widgets = vec ! [
79
+ WidgetHolder :: new( Widget :: ParameterExposeButton ( ParameterExposeButton {
80
+ exposed,
81
+ data_type: FrontendGraphDataType :: Number ,
82
+ tooltip: "Expose input parameter in node graph" . into( ) ,
83
+ on_update: WidgetCallback :: new( move |_parameter| {
84
+ NodeGraphMessage :: ExposeInput {
85
+ node_id,
86
+ input_index: index,
87
+ new_exposed: !exposed,
88
+ }
89
+ . into( )
90
+ } ) ,
91
+ ..Default :: default ( )
92
+ } ) ) ,
93
+ WidgetHolder :: new( Widget :: Separator ( Separator {
94
+ separator_type: SeparatorType :: Unrelated ,
95
+ direction: SeparatorDirection :: Horizontal ,
96
+ } ) ) ,
97
+ WidgetHolder :: new( Widget :: TextLabel ( TextLabel {
98
+ value: "Brighten Amount" . into( ) ,
99
+ ..Default :: default ( )
100
+ } ) ) ,
101
+ ] ;
102
+
103
+ if let NodeInput :: Value {
104
+ tagged_value : TaggedValue :: F32 ( x) ,
105
+ exposed : false ,
106
+ } = document_node. inputs [ index]
107
+ {
108
+ widgets. extend_from_slice ( & [
75
109
WidgetHolder :: new ( Widget :: Separator ( Separator {
76
110
separator_type : SeparatorType :: Unrelated ,
77
111
direction : SeparatorDirection :: Horizontal ,
78
112
} ) ) ,
79
113
WidgetHolder :: new ( Widget :: NumberInput ( NumberInput {
80
- value: Some ( {
81
- let NodeInput :: Value { tagged_value: TaggedValue :: F32 ( x) , ..} = document_node. inputs[ 1 ] else {
82
- panic!( "Brighten amount should be f32" )
83
- } ;
84
- x as f64
85
- } ) ,
114
+ value : Some ( x as f64 ) ,
86
115
mode : NumberInputMode :: Range ,
87
116
range_min : Some ( -255. ) ,
88
117
range_max : Some ( 255. ) ,
@@ -96,17 +125,29 @@ pub fn brighten_image_properties(document_node: &DocumentNode, node_id: NodeId)
96
125
} ) ,
97
126
..NumberInput :: default ( )
98
127
} ) ) ,
99
- ] ,
100
- } ]
128
+ ] )
129
+ }
130
+
131
+ vec ! [ LayoutGroup :: Row { widgets } ]
101
132
}
102
133
103
134
pub fn add_properties ( document_node : & DocumentNode , node_id : NodeId ) -> Vec < LayoutGroup > {
104
- let operand = |name : & str , index| LayoutGroup :: Row {
105
- widgets : vec ! [
135
+ let operand = |name : & str , index| {
136
+ let input: & NodeInput = document_node. inputs . get ( index) . unwrap ( ) ;
137
+ let exposed = input. is_exposed ( ) ;
138
+ let mut widgets = vec ! [
106
139
WidgetHolder :: new( Widget :: ParameterExposeButton ( ParameterExposeButton {
107
- exposed: true ,
140
+ exposed,
108
141
data_type: FrontendGraphDataType :: Number ,
109
142
tooltip: "Expose input parameter in node graph" . into( ) ,
143
+ on_update: WidgetCallback :: new( move |_parameter| {
144
+ NodeGraphMessage :: ExposeInput {
145
+ node_id,
146
+ input_index: index,
147
+ new_exposed: !exposed,
148
+ }
149
+ . into( )
150
+ } ) ,
110
151
..Default :: default ( )
111
152
} ) ) ,
112
153
WidgetHolder :: new( Widget :: Separator ( Separator {
@@ -117,32 +158,37 @@ pub fn add_properties(document_node: &DocumentNode, node_id: NodeId) -> Vec<Layo
117
158
value: name. into( ) ,
118
159
..Default :: default ( )
119
160
} ) ) ,
120
- WidgetHolder :: new( Widget :: Separator ( Separator {
121
- separator_type: SeparatorType :: Unrelated ,
122
- direction: SeparatorDirection :: Horizontal ,
123
- } ) ) ,
124
- WidgetHolder :: new( Widget :: NumberInput ( NumberInput {
125
- value: Some ( {
126
- let NodeInput :: Value { tagged_value: TaggedValue :: F32 ( x) , ..} = document_node. inputs[ index] else {
127
- panic!( "Add input should be f32" )
128
- } ;
161
+ ] ;
129
162
130
- x as f64
131
- } ) ,
132
- mode: NumberInputMode :: Increment ,
133
- on_update: WidgetCallback :: new( move |number_input: & NumberInput | {
134
- NodeGraphMessage :: SetInputValue {
135
- node: node_id,
136
- input_index: index,
137
- value: TaggedValue :: F32 ( number_input. value. unwrap( ) as f32 ) ,
138
- }
139
- . into( )
140
- } ) ,
141
- ..NumberInput :: default ( )
142
- } ) ) ,
143
- ] ,
163
+ if let NodeInput :: Value {
164
+ tagged_value : TaggedValue :: F32 ( x) ,
165
+ exposed : false ,
166
+ } = document_node. inputs [ index]
167
+ {
168
+ widgets. extend_from_slice ( & [
169
+ WidgetHolder :: new ( Widget :: Separator ( Separator {
170
+ separator_type : SeparatorType :: Unrelated ,
171
+ direction : SeparatorDirection :: Horizontal ,
172
+ } ) ) ,
173
+ WidgetHolder :: new ( Widget :: NumberInput ( NumberInput {
174
+ value : Some ( x as f64 ) ,
175
+ mode : NumberInputMode :: Increment ,
176
+ on_update : WidgetCallback :: new ( move |number_input : & NumberInput | {
177
+ NodeGraphMessage :: SetInputValue {
178
+ node : node_id,
179
+ input_index : index,
180
+ value : TaggedValue :: F32 ( number_input. value . unwrap ( ) as f32 ) ,
181
+ }
182
+ . into ( )
183
+ } ) ,
184
+ ..NumberInput :: default ( )
185
+ } ) ) ,
186
+ ] ) ;
187
+ }
188
+
189
+ LayoutGroup :: Row { widgets }
144
190
} ;
145
- vec ! [ operand( "Left " , 0 ) , operand( "Right " , 1 ) ]
191
+ vec ! [ operand( "Input " , 0 ) , operand( "Addend " , 1 ) ]
146
192
}
147
193
148
194
fn unknown_node_properties ( document_node : & DocumentNode ) -> Vec < LayoutGroup > {
0 commit comments