Skip to content

Commit f33aaa9

Browse files
committed
WIP
1 parent 73682b4 commit f33aaa9

12 files changed

Lines changed: 121 additions & 178 deletions

File tree

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ impl<'a> ModifyInputsContext<'a> {
206206
Some(NodeInput::value(TaggedValue::F64(typesetting.font_size), false)),
207207
Some(NodeInput::value(TaggedValue::F64(typesetting.line_height_ratio), false)),
208208
Some(NodeInput::value(TaggedValue::F64(typesetting.character_spacing), false)),
209-
Some(NodeInput::value(TaggedValue::OptionalF64(typesetting.max_width), false)),
210-
Some(NodeInput::value(TaggedValue::OptionalF64(typesetting.max_height), false)),
209+
Some(NodeInput::value(TaggedValue::Bool(typesetting.max_width.is_some()), false)),
210+
Some(NodeInput::value(TaggedValue::F64(typesetting.max_width.unwrap_or(100.)), false)),
211+
Some(NodeInput::value(TaggedValue::Bool(typesetting.max_width.is_some()), false)),
212+
Some(NodeInput::value(TaggedValue::F64(typesetting.max_width.unwrap_or(100.)), false)),
211213
Some(NodeInput::value(TaggedValue::F64(typesetting.tilt), false)),
212214
Some(NodeInput::value(TaggedValue::TextAlign(typesetting.align), false)),
213215
]);

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

Lines changed: 24 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use graphene_std::extract_xy::XY;
2121
use graphene_std::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
2222
use graphene_std::raster_types::{CPU, Raster};
2323
use graphene_std::table::Table;
24-
use graphene_std::text::{Font, TypesettingConfig};
2524
#[allow(unused_imports)]
2625
use graphene_std::transform::Footprint;
2726
use graphene_std::vector::Vector;
@@ -1653,103 +1652,6 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
16531652
properties: None,
16541653
},
16551654
// TODO: Auto-generate this from its proto node macro
1656-
DocumentNodeDefinition {
1657-
identifier: "Text",
1658-
category: "Text",
1659-
node_template: NodeTemplate {
1660-
document_node: DocumentNode {
1661-
implementation: DocumentNodeImplementation::ProtoNode(text::text::IDENTIFIER),
1662-
inputs: vec![
1663-
NodeInput::scope("editor-api"),
1664-
NodeInput::value(TaggedValue::String("Lorem ipsum".to_string()), false),
1665-
NodeInput::value(
1666-
TaggedValue::Font(Font::new(graphene_std::consts::DEFAULT_FONT_FAMILY.into(), graphene_std::consts::DEFAULT_FONT_STYLE.into())),
1667-
false,
1668-
),
1669-
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().font_size), false),
1670-
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().line_height_ratio), false),
1671-
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().character_spacing), false),
1672-
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_width), false),
1673-
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_height), false),
1674-
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().tilt), false),
1675-
NodeInput::value(TaggedValue::TextAlign(text::TextAlign::default()), false),
1676-
NodeInput::value(TaggedValue::Bool(false), false),
1677-
],
1678-
..Default::default()
1679-
},
1680-
persistent_node_metadata: DocumentNodePersistentMetadata {
1681-
input_metadata: vec![
1682-
("Editor API", "TODO").into(),
1683-
InputMetadata::with_name_description_override("Text", "TODO", WidgetOverride::Custom("text_area".to_string())),
1684-
InputMetadata::with_name_description_override("Font", "TODO", WidgetOverride::Custom("text_font".to_string())),
1685-
InputMetadata::with_name_description_override(
1686-
"Size",
1687-
"TODO",
1688-
WidgetOverride::Number(NumberInputSettings {
1689-
unit: Some(" px".to_string()),
1690-
min: Some(1.),
1691-
..Default::default()
1692-
}),
1693-
),
1694-
InputMetadata::with_name_description_override(
1695-
"Line Height",
1696-
"TODO",
1697-
WidgetOverride::Number(NumberInputSettings {
1698-
unit: Some("x".to_string()),
1699-
min: Some(0.),
1700-
step: Some(0.1),
1701-
..Default::default()
1702-
}),
1703-
),
1704-
InputMetadata::with_name_description_override(
1705-
"Character Spacing",
1706-
"TODO",
1707-
WidgetOverride::Number(NumberInputSettings {
1708-
unit: Some(" px".to_string()),
1709-
step: Some(0.1),
1710-
..Default::default()
1711-
}),
1712-
),
1713-
InputMetadata::with_name_description_override(
1714-
"Max Width",
1715-
"TODO",
1716-
WidgetOverride::Number(NumberInputSettings {
1717-
unit: Some(" px".to_string()),
1718-
min: Some(1.),
1719-
blank_assist: false,
1720-
..Default::default()
1721-
}),
1722-
),
1723-
InputMetadata::with_name_description_override(
1724-
"Max Height",
1725-
"TODO",
1726-
WidgetOverride::Number(NumberInputSettings {
1727-
unit: Some(" px".to_string()),
1728-
min: Some(1.),
1729-
blank_assist: false,
1730-
..Default::default()
1731-
}),
1732-
),
1733-
InputMetadata::with_name_description_override(
1734-
"Tilt",
1735-
"Faux italic.",
1736-
WidgetOverride::Number(NumberInputSettings {
1737-
min: Some(-85.),
1738-
max: Some(85.),
1739-
unit: Some("°".to_string()),
1740-
..Default::default()
1741-
}),
1742-
),
1743-
InputMetadata::with_name_description_override("Align", "TODO", WidgetOverride::Custom("text_align".to_string())),
1744-
("Per-Glyph Instances", "Splits each text glyph into its own row in the table of vector geometry.").into(),
1745-
],
1746-
output_names: vec!["Vector".to_string()],
1747-
..Default::default()
1748-
},
1749-
},
1750-
description: Cow::Borrowed("TODO"),
1751-
properties: None,
1752-
},
17531655
DocumentNodeDefinition {
17541656
identifier: "Transform",
17551657
category: "Math: Transform",
@@ -2297,6 +2199,30 @@ fn static_input_properties() -> InputProperties {
22972199
}])
22982200
}),
22992201
);
2202+
map.insert(
2203+
"optional_number".to_string(),
2204+
Box::new(|node_id, index, context| {
2205+
// TODO: Don't wipe out the previously set value (setting it back to the default of 100) when reenabling this checkbox back to Some from None
2206+
let toggle_enabled = move |checkbox_input: &CheckboxInput| TaggedValue::OptionalF64(if checkbox_input.checked { Some(100.) } else { None });
2207+
Ok(vec![
2208+
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
2209+
Separator::new(SeparatorStyle::Related).widget_instance(),
2210+
// The checkbox toggles if the value is Some or None
2211+
CheckboxInput::new(x.is_some())
2212+
.on_update(update_value(toggle_enabled, node_id, index))
2213+
.on_commit(commit_value)
2214+
.widget_instance(),
2215+
Separator::new(SeparatorStyle::Related).widget_instance(),
2216+
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
2217+
number_props
2218+
.value(x)
2219+
.on_update(update_value(move |x: &NumberInput| TaggedValue::OptionalF64(x.value), node_id, index))
2220+
.disabled(x.is_none())
2221+
.on_commit(commit_value)
2222+
.widget_instance(),
2223+
])
2224+
}),
2225+
);
23002226
map.insert(
23012227
"vec2".to_string(),
23022228
Box::new(|node_id, index, context| {

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -982,27 +982,6 @@ pub fn number_widget(parameter_widgets_info: ParameterWidgetsInfo, number_props:
982982
.on_commit(commit_value)
983983
.widget_instance(),
984984
]),
985-
Some(&TaggedValue::OptionalF64(x)) => {
986-
// TODO: Don't wipe out the previously set value (setting it back to the default of 100) when reenabling this checkbox back to Some from None
987-
let toggle_enabled = move |checkbox_input: &CheckboxInput| TaggedValue::OptionalF64(if checkbox_input.checked { Some(100.) } else { None });
988-
widgets.extend_from_slice(&[
989-
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
990-
Separator::new(SeparatorStyle::Related).widget_instance(),
991-
// The checkbox toggles if the value is Some or None
992-
CheckboxInput::new(x.is_some())
993-
.on_update(update_value(toggle_enabled, node_id, index))
994-
.on_commit(commit_value)
995-
.widget_instance(),
996-
Separator::new(SeparatorStyle::Related).widget_instance(),
997-
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
998-
number_props
999-
.value(x)
1000-
.on_update(update_value(move |x: &NumberInput| TaggedValue::OptionalF64(x.value), node_id, index))
1001-
.disabled(x.is_none())
1002-
.on_commit(commit_value)
1003-
.widget_instance(),
1004-
]);
1005-
}
1006985
Some(&TaggedValue::DVec2(dvec2)) => widgets.extend_from_slice(&[
1007986
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
1008987
number_props
@@ -1087,14 +1066,6 @@ pub fn color_widget(parameter_widgets_info: ParameterWidgetsInfo, color_button:
10871066
.on_commit(commit_value)
10881067
.widget_instance(),
10891068
),
1090-
TaggedValue::OptionalColorNotInTable(color) => widgets.push(
1091-
color_button
1092-
.value(color.map_or(FillChoice::None, FillChoice::Solid))
1093-
.allow_none(true)
1094-
.on_update(update_value(|input: &ColorInput| TaggedValue::OptionalColorNotInTable(input.value.as_solid()), node_id, index))
1095-
.on_commit(commit_value)
1096-
.widget_instance(),
1097-
),
10981069
TaggedValue::Color(color_table) => widgets.push(
10991070
color_button
11001071
.value(match color_table.iter().next() {

editor/src/messages/portfolio/document_migration.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
11661166
if inputs_count >= 7 {
11671167
old_inputs[6].clone()
11681168
} else {
1169-
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_width), false)
1169+
NodeInput::value(TaggedValue::Bool(TypesettingConfig::default().max_width.is_some()), false)
11701170
},
11711171
network_path,
11721172
);
@@ -1175,7 +1175,7 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
11751175
if inputs_count >= 8 {
11761176
old_inputs[7].clone()
11771177
} else {
1178-
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_height), false)
1178+
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().max_width.unwrap_or(100.)), false)
11791179
},
11801180
network_path,
11811181
);
@@ -1184,23 +1184,41 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
11841184
if inputs_count >= 9 {
11851185
old_inputs[8].clone()
11861186
} else {
1187-
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().tilt), false)
1187+
NodeInput::value(TaggedValue::Bool(TypesettingConfig::default().max_height.is_some()), false)
11881188
},
11891189
network_path,
11901190
);
11911191
document.network_interface.set_input(
11921192
&InputConnector::node(*node_id, 9),
1193-
if inputs_count >= 11 {
1193+
if inputs_count >= 10 {
11941194
old_inputs[9].clone()
11951195
} else {
1196-
NodeInput::value(TaggedValue::TextAlign(TextAlign::default()), false)
1196+
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().max_height.unwrap_or(100.)), false)
11971197
},
11981198
network_path,
11991199
);
12001200
document.network_interface.set_input(
12011201
&InputConnector::node(*node_id, 10),
12021202
if inputs_count >= 11 {
12031203
old_inputs[10].clone()
1204+
} else {
1205+
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().tilt), false)
1206+
},
1207+
network_path,
1208+
);
1209+
document.network_interface.set_input(
1210+
&InputConnector::node(*node_id, 11),
1211+
if inputs_count >= 12 {
1212+
old_inputs[11].clone()
1213+
} else {
1214+
NodeInput::value(TaggedValue::TextAlign(TextAlign::default()), false)
1215+
},
1216+
network_path,
1217+
);
1218+
document.network_interface.set_input(
1219+
&InputConnector::node(*node_id, 12),
1220+
if inputs_count >= 13 {
1221+
old_inputs[12].clone()
12041222
} else {
12051223
NodeInput::value(TaggedValue::Bool(false), false)
12061224
},

editor/src/messages/tool/common_functionality/graph_modification_utils.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,20 @@ pub fn get_text(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInter
393393
let Some(&TaggedValue::F64(font_size)) = inputs[3].as_value() else { return None };
394394
let Some(&TaggedValue::F64(line_height_ratio)) = inputs[4].as_value() else { return None };
395395
let Some(&TaggedValue::F64(character_spacing)) = inputs[5].as_value() else { return None };
396-
let Some(&TaggedValue::OptionalF64(max_width)) = inputs[6].as_value() else { return None };
397-
let Some(&TaggedValue::OptionalF64(max_height)) = inputs[7].as_value() else { return None };
398-
let Some(&TaggedValue::F64(tilt)) = inputs[8].as_value() else { return None };
399-
let Some(&TaggedValue::TextAlign(align)) = inputs[9].as_value() else { return None };
400-
let Some(&TaggedValue::Bool(per_glyph_instances)) = inputs[10].as_value() else { return None };
396+
let Some(&TaggedValue::Bool(has_max_width)) = inputs[6].as_value() else { return None };
397+
let Some(&TaggedValue::F64(max_width)) = inputs[7].as_value() else { return None };
398+
let Some(&TaggedValue::Bool(has_max_height)) = inputs[8].as_value() else { return None };
399+
let Some(&TaggedValue::F64(max_height)) = inputs[9].as_value() else { return None };
400+
let Some(&TaggedValue::F64(tilt)) = inputs[10].as_value() else { return None };
401+
let Some(&TaggedValue::TextAlign(align)) = inputs[11].as_value() else { return None };
402+
let Some(&TaggedValue::Bool(per_glyph_instances)) = inputs[12].as_value() else { return None };
401403

402404
let typesetting = TypesettingConfig {
403405
font_size,
404406
line_height_ratio,
405-
max_width,
407+
max_width: has_max_width.then_some(max_width),
408+
max_height: has_max_height.then_some(max_height),
406409
character_spacing,
407-
max_height,
408410
tilt,
409411
align,
410412
};

editor/src/messages/tool/tool_messages/text_tool.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,22 @@ impl Fsm for TextToolFsmState {
800800
// Find the translation necessary from the original position in viewport space
801801
let translation_viewport = bounds.original_bound_transform.transform_vector2(translation_bounds_space);
802802

803+
// TODO: Don't set both max_width and max_height to true at the same time, only do one based on which edge is being dragged (or both if a corner is being dragged)
803804
responses.add(NodeGraphMessage::SetInput {
804805
input_connector: InputConnector::node(node_id, 6),
805-
input: NodeInput::value(TaggedValue::OptionalF64(Some(size_layer.x)), false),
806+
input: NodeInput::value(TaggedValue::Bool(true), false),
806807
});
807808
responses.add(NodeGraphMessage::SetInput {
808809
input_connector: InputConnector::node(node_id, 7),
809-
input: NodeInput::value(TaggedValue::OptionalF64(Some(size_layer.y)), false),
810+
input: NodeInput::value(TaggedValue::F64(size_layer.x), false),
811+
});
812+
responses.add(NodeGraphMessage::SetInput {
813+
input_connector: InputConnector::node(node_id, 8),
814+
input: NodeInput::value(TaggedValue::Bool(true), false),
815+
});
816+
responses.add(NodeGraphMessage::SetInput {
817+
input_connector: InputConnector::node(node_id, 9),
818+
input: NodeInput::value(TaggedValue::F64(size_layer.y), false),
810819
});
811820
responses.add(GraphOperationMessage::TransformSet {
812821
layer: dragging_layer.id,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ tagged_value! {
173173
U64(u64),
174174
Bool(bool),
175175
String(String),
176-
OptionalF64(Option<f64>),
177176
ColorNotInTable(Color),
178-
OptionalColorNotInTable(Option<Color>),
179177
// ========================
180178
// LISTS OF PRIMITIVE TYPES
181179
// ========================
@@ -366,9 +364,9 @@ impl TaggedValue {
366364
x if x == TypeId::of::<u32>() => FromStr::from_str(string).map(TaggedValue::U32).ok()?,
367365
x if x == TypeId::of::<DVec2>() => to_dvec2(string).map(TaggedValue::DVec2)?,
368366
x if x == TypeId::of::<bool>() => FromStr::from_str(string).map(TaggedValue::Bool).ok()?,
369-
x if x == TypeId::of::<Table<Color>>() => to_color(string).map(|color| TaggedValue::Color(Table::new_from_element(color)))?,
370367
x if x == TypeId::of::<Color>() => to_color(string).map(TaggedValue::ColorNotInTable)?,
371368
x if x == TypeId::of::<Option<Color>>() => TaggedValue::ColorNotInTable(to_color(string)?),
369+
x if x == TypeId::of::<Table<Color>>() => to_color(string).map(|color| TaggedValue::Color(Table::new_from_element(color)))?,
372370
x if x == TypeId::of::<Fill>() => to_color(string).map(|color| TaggedValue::Fill(Fill::solid(color)))?,
373371
x if x == TypeId::of::<ReferencePoint>() => to_reference_point(string).map(TaggedValue::ReferencePoint)?,
374372
_ => return None,

node-graph/libraries/graphic-types/src/graphic.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ impl From<Table<Color>> for Graphic {
9090
}
9191
}
9292
// Note: Table conversions handled by blanket impl in gcore
93-
94-
// Option<Color>
95-
impl From<Option<Color>> for Graphic {
96-
fn from(color: Option<Color>) -> Self {
97-
if let Some(color) = color {
98-
Graphic::Color(Table::new_from_element(color))
99-
} else {
100-
Graphic::default()
101-
}
102-
}
103-
}
104-
// Note: Table conversions handled by blanket impl in gcore
10593
// Note: Table<Color> -> Option<Color> is in gcore (Color is defined there)
10694

10795
// GradientStops

node-graph/nodes/blending/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ fn blending<T: SetBlendMode + MultiplyAlpha + MultiplyFill + SetClip>(
244244
#[default(100.)]
245245
fill: Percentage,
246246
/// Whether the content inherits the alpha of the content beneath it.
247-
#[default(false)]
248247
clip: bool,
249248
) -> T {
250249
// TODO: Find a way to make this apply once to the table's parent (i.e. its row in its parent table or TableRow<T>) rather than applying to each row in its own table, which produces the undesired result

0 commit comments

Comments
 (0)