figma_api/models/text_node.rs
1/*
2 * Figma API
3 *
4 * This is the OpenAPI specification for the [Figma REST API](https://www.figma.com/developers/api). Note: we are releasing the OpenAPI specification as a beta given the large surface area and complexity of the REST API. If you notice any inaccuracies with the specification, please [file an issue](https://github.com/figma/rest-api-spec/issues).
5 *
6 * The version of the OpenAPI document: 0.31.0
7 * Contact: support@figma.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct TextNode {
16 /// A string uniquely identifying this node within the document.
17 #[serde(rename = "id")]
18 pub id: String,
19 /// The name given to the node by the user in the tool.
20 #[serde(rename = "name")]
21 pub name: String,
22 /// Whether or not the node is visible on the canvas.
23 #[serde(rename = "visible", skip_serializing_if = "Option::is_none")]
24 pub visible: Option<bool>,
25 /// If true, layer is locked and cannot be edited
26 #[serde(rename = "locked", skip_serializing_if = "Option::is_none")]
27 pub locked: Option<bool>,
28 /// Whether the layer is fixed while the parent is scrolling
29 #[serde(rename = "isFixed", skip_serializing_if = "Option::is_none")]
30 pub is_fixed: Option<bool>,
31 /// How layer should be treated when the frame is resized
32 #[serde(rename = "scrollBehavior")]
33 pub scroll_behavior: ScrollBehavior,
34 /// The rotation of the node, if not 0.
35 #[serde(rename = "rotation", skip_serializing_if = "Option::is_none")]
36 pub rotation: Option<f64>,
37 /// A mapping of a layer's property to component property name of component properties attached to this node. The component property name can be used to look up more information on the corresponding component's or component set's componentPropertyDefinitions.
38 #[serde(rename = "componentPropertyReferences", skip_serializing_if = "Option::is_none")]
39 pub component_property_references: Option<std::collections::HashMap<String, String>>,
40 #[serde(rename = "pluginData", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
41 pub plugin_data: Option<Option<serde_json::Value>>,
42 #[serde(rename = "sharedPluginData", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
43 pub shared_plugin_data: Option<Option<serde_json::Value>>,
44 #[serde(rename = "boundVariables", skip_serializing_if = "Option::is_none")]
45 pub bound_variables: Option<Box<models::IsLayerTraitBoundVariables>>,
46 /// A mapping of variable collection ID to mode ID representing the explicitly set modes for this node.
47 #[serde(rename = "explicitVariableModes", skip_serializing_if = "Option::is_none")]
48 pub explicit_variable_modes: Option<std::collections::HashMap<String, String>>,
49 /// How this node blends with nodes behind it in the scene (see blend mode section for more details)
50 #[serde(rename = "blendMode")]
51 pub blend_mode: models::BlendMode,
52 /// Opacity of the node
53 #[serde(rename = "opacity", skip_serializing_if = "Option::is_none")]
54 pub opacity: Option<f64>,
55 /// Keep height and width constrained to same ratio.
56 #[serde(rename = "preserveRatio", skip_serializing_if = "Option::is_none")]
57 pub preserve_ratio: Option<bool>,
58 /// Horizontal and vertical layout constraints for node.
59 #[serde(rename = "constraints", skip_serializing_if = "Option::is_none")]
60 pub constraints: Option<Box<models::LayoutConstraint>>,
61 /// A transformation matrix is standard way in computer graphics to represent translation and rotation. These are the top two rows of a 3x3 matrix. The bottom row of the matrix is assumed to be [0, 0, 1]. This is known as an affine transform and is enough to represent translation, rotation, and skew. The identity transform is [[1, 0, 0], [0, 1, 0]]. A translation matrix will typically look like: ``` [[1, 0, tx], [0, 1, ty]] ``` and a rotation matrix will typically look like: ``` [[cos(angle), sin(angle), 0], [-sin(angle), cos(angle), 0]] ``` Another way to think about this transform is as three vectors: - The x axis (t[0][0], t[1][0]) - The y axis (t[0][1], t[1][1]) - The translation offset (t[0][2], t[1][2]) The most common usage of the Transform matrix is the `relativeTransform property`. This particular usage of the matrix has a few additional restrictions. The translation offset can take on any value but we do enforce that the axis vectors are unit vectors (i.e. have length 1). The axes are not required to be at 90° angles to each other.
62 #[serde(rename = "relativeTransform", skip_serializing_if = "Option::is_none")]
63 pub relative_transform: Option<Vec<Vec<f64>>>,
64 /// Width and height of element. This is different from the width and height of the bounding box in that the absolute bounding box represents the element after scaling and rotation. Only present if `geometry=paths` is passed.
65 #[serde(rename = "size", skip_serializing_if = "Option::is_none")]
66 pub size: Option<Box<models::Vector>>,
67 /// Determines if the layer should stretch along the parent's counter axis. This property is only provided for direct children of auto-layout frames. - `INHERIT` - `STRETCH` In previous versions of auto layout, determined how the layer is aligned inside an auto-layout frame. This property is only provided for direct children of auto-layout frames. - `MIN` - `CENTER` - `MAX` - `STRETCH` In horizontal auto-layout frames, \"MIN\" and \"MAX\" correspond to \"TOP\" and \"BOTTOM\". In vertical auto-layout frames, \"MIN\" and \"MAX\" correspond to \"LEFT\" and \"RIGHT\".
68 #[serde(rename = "layoutAlign", skip_serializing_if = "Option::is_none")]
69 pub layout_align: Option<LayoutAlign>,
70 /// This property is applicable only for direct children of auto-layout frames, ignored otherwise. Determines whether a layer should stretch along the parent's primary axis. A `0` corresponds to a fixed size and `1` corresponds to stretch.
71 #[serde(rename = "layoutGrow", skip_serializing_if = "Option::is_none")]
72 pub layout_grow: Option<f64>,
73 /// Determines whether a layer's size and position should be determined by auto-layout settings or manually adjustable.
74 #[serde(rename = "layoutPositioning", skip_serializing_if = "Option::is_none")]
75 pub layout_positioning: Option<LayoutPositioning>,
76 /// The minimum width of the frame. This property is only applicable for auto-layout frames or direct children of auto-layout frames.
77 #[serde(rename = "minWidth", skip_serializing_if = "Option::is_none")]
78 pub min_width: Option<f64>,
79 /// The maximum width of the frame. This property is only applicable for auto-layout frames or direct children of auto-layout frames.
80 #[serde(rename = "maxWidth", skip_serializing_if = "Option::is_none")]
81 pub max_width: Option<f64>,
82 /// The minimum height of the frame. This property is only applicable for auto-layout frames or direct children of auto-layout frames.
83 #[serde(rename = "minHeight", skip_serializing_if = "Option::is_none")]
84 pub min_height: Option<f64>,
85 /// The maximum height of the frame. This property is only applicable for auto-layout frames or direct children of auto-layout frames.
86 #[serde(rename = "maxHeight", skip_serializing_if = "Option::is_none")]
87 pub max_height: Option<f64>,
88 /// The horizontal sizing setting on this auto-layout frame or frame child. - `FIXED` - `HUG`: only valid on auto-layout frames and text nodes - `FILL`: only valid on auto-layout frame children
89 #[serde(rename = "layoutSizingHorizontal", skip_serializing_if = "Option::is_none")]
90 pub layout_sizing_horizontal: Option<LayoutSizingHorizontal>,
91 /// The vertical sizing setting on this auto-layout frame or frame child. - `FIXED` - `HUG`: only valid on auto-layout frames and text nodes - `FILL`: only valid on auto-layout frame children
92 #[serde(rename = "layoutSizingVertical", skip_serializing_if = "Option::is_none")]
93 pub layout_sizing_vertical: Option<LayoutSizingVertical>,
94 /// An array of fill paints applied to the node.
95 #[serde(rename = "fills")]
96 pub fills: Vec<models::Paint>,
97 /// A mapping of a StyleType to style ID (see Style) of styles present on this node. The style ID can be used to look up more information about the style in the top-level styles field.
98 #[serde(rename = "styles", skip_serializing_if = "Option::is_none")]
99 pub styles: Option<std::collections::HashMap<String, String>>,
100 /// An array of stroke paints applied to the node.
101 #[serde(rename = "strokes", skip_serializing_if = "Option::is_none")]
102 pub strokes: Option<Vec<models::Paint>>,
103 /// The weight of strokes on the node.
104 #[serde(rename = "strokeWeight", skip_serializing_if = "Option::is_none")]
105 pub stroke_weight: Option<f64>,
106 /// Position of stroke relative to vector outline, as a string enum - `INSIDE`: stroke drawn inside the shape boundary - `OUTSIDE`: stroke drawn outside the shape boundary - `CENTER`: stroke drawn centered along the shape boundary
107 #[serde(rename = "strokeAlign", skip_serializing_if = "Option::is_none")]
108 pub stroke_align: Option<StrokeAlign>,
109 /// A string enum with value of \"MITER\", \"BEVEL\", or \"ROUND\", describing how corners in vector paths are rendered.
110 #[serde(rename = "strokeJoin", skip_serializing_if = "Option::is_none")]
111 pub stroke_join: Option<StrokeJoin>,
112 /// An array of floating point numbers describing the pattern of dash length and gap lengths that the vector stroke will use when drawn. For example a value of [1, 2] indicates that the stroke will be drawn with a dash of length 1 followed by a gap of length 2, repeated.
113 #[serde(rename = "strokeDashes", skip_serializing_if = "Option::is_none")]
114 pub stroke_dashes: Option<Vec<f64>>,
115 /// Only specified if parameter `geometry=paths` is used. An array of paths representing the object fill.
116 #[serde(rename = "fillGeometry", skip_serializing_if = "Option::is_none")]
117 pub fill_geometry: Option<Vec<models::Path>>,
118 /// Only specified if parameter `geometry=paths` is used. An array of paths representing the object stroke.
119 #[serde(rename = "strokeGeometry", skip_serializing_if = "Option::is_none")]
120 pub stroke_geometry: Option<Vec<models::Path>>,
121 /// A string enum describing the end caps of vector paths.
122 #[serde(rename = "strokeCap", skip_serializing_if = "Option::is_none")]
123 pub stroke_cap: Option<StrokeCap>,
124 /// Only valid if `strokeJoin` is \"MITER\". The corner angle, in degrees, below which `strokeJoin` will be set to \"BEVEL\" to avoid super sharp corners. By default this is 28.96 degrees.
125 #[serde(rename = "strokeMiterAngle", skip_serializing_if = "Option::is_none")]
126 pub stroke_miter_angle: Option<f64>,
127 /// An array of export settings representing images to export from the node.
128 #[serde(rename = "exportSettings", skip_serializing_if = "Option::is_none")]
129 pub export_settings: Option<Vec<models::ExportSetting>>,
130 /// An array of effects attached to this node (see effects section for more details)
131 #[serde(rename = "effects")]
132 pub effects: Vec<models::Effect>,
133 /// Does this node mask sibling nodes in front of it?
134 #[serde(rename = "isMask", skip_serializing_if = "Option::is_none")]
135 pub is_mask: Option<bool>,
136 /// If this layer is a mask, this property describes the operation used to mask the layer's siblings. The value may be one of the following: - ALPHA: the mask node's alpha channel will be used to determine the opacity of each pixel in the masked result. - VECTOR: if the mask node has visible fill paints, every pixel inside the node's fill regions will be fully visible in the masked result. If the mask has visible stroke paints, every pixel inside the node's stroke regions will be fully visible in the masked result. - LUMINANCE: the luminance value of each pixel of the mask node will be used to determine the opacity of that pixel in the masked result.
137 #[serde(rename = "maskType", skip_serializing_if = "Option::is_none")]
138 pub mask_type: Option<MaskType>,
139 /// True if maskType is VECTOR. This field is deprecated; use maskType instead.
140 #[serde(rename = "isMaskOutline", skip_serializing_if = "Option::is_none")]
141 pub is_mask_outline: Option<bool>,
142 /// Node ID of node to transition to in prototyping
143 #[serde(rename = "transitionNodeID", skip_serializing_if = "Option::is_none")]
144 pub transition_node_id: Option<String>,
145 /// The duration of the prototyping transition on this node (in milliseconds). This will override the default transition duration on the prototype, for this node.
146 #[serde(rename = "transitionDuration", skip_serializing_if = "Option::is_none")]
147 pub transition_duration: Option<f64>,
148 /// The easing curve used in the prototyping transition on this node.
149 #[serde(rename = "transitionEasing", skip_serializing_if = "Option::is_none")]
150 pub transition_easing: Option<models::EasingType>,
151 /// The raw characters in the text node.
152 #[serde(rename = "characters")]
153 pub characters: String,
154 /// Style of text including font family and weight.
155 #[serde(rename = "style")]
156 pub style: Box<models::TypeStyle>,
157 /// The array corresponds to characters in the text box, where each element references the 'styleOverrideTable' to apply specific styles to each character. The array's length can be less than or equal to the number of characters due to the removal of trailing zeros. Elements with a value of 0 indicate characters that use the default type style. If the array is shorter than the total number of characters, the characters beyond the array's length also use the default style.
158 #[serde(rename = "characterStyleOverrides")]
159 pub character_style_overrides: Vec<f64>,
160 /// Internal property, preserved for backward compatibility. Avoid using this value.
161 #[serde(rename = "layoutVersion", skip_serializing_if = "Option::is_none")]
162 pub layout_version: Option<f64>,
163 /// Map from ID to TypeStyle for looking up style overrides.
164 #[serde(rename = "styleOverrideTable")]
165 pub style_override_table: std::collections::HashMap<String, models::TypeStyle>,
166 /// An array with the same number of elements as lines in the text node, where lines are delimited by newline or paragraph separator characters. Each element in the array corresponds to the list type of a specific line. List types are represented as string enums with one of these possible values: - `NONE`: Not a list item. - `ORDERED`: Text is an ordered list (numbered). - `UNORDERED`: Text is an unordered list (bulleted).
167 #[serde(rename = "lineTypes")]
168 pub line_types: Vec<LineTypes>,
169 /// An array with the same number of elements as lines in the text node, where lines are delimited by newline or paragraph separator characters. Each element in the array corresponds to the indentation level of a specific line.
170 #[serde(rename = "lineIndentations")]
171 pub line_indentations: Vec<f64>,
172}
173
174impl TextNode {
175 pub fn new(id: String, name: String, scroll_behavior: ScrollBehavior, blend_mode: models::BlendMode, fills: Vec<models::Paint>, effects: Vec<models::Effect>, characters: String, style: models::TypeStyle, character_style_overrides: Vec<f64>, style_override_table: std::collections::HashMap<String, models::TypeStyle>, line_types: Vec<LineTypes>, line_indentations: Vec<f64>) -> TextNode {
176 TextNode {
177 id,
178 name,
179 visible: None,
180 locked: None,
181 is_fixed: None,
182 scroll_behavior,
183 rotation: None,
184 component_property_references: None,
185 plugin_data: None,
186 shared_plugin_data: None,
187 bound_variables: None,
188 explicit_variable_modes: None,
189 blend_mode,
190 opacity: None,
191 preserve_ratio: None,
192 constraints: None,
193 relative_transform: None,
194 size: None,
195 layout_align: None,
196 layout_grow: None,
197 layout_positioning: None,
198 min_width: None,
199 max_width: None,
200 min_height: None,
201 max_height: None,
202 layout_sizing_horizontal: None,
203 layout_sizing_vertical: None,
204 fills,
205 styles: None,
206 strokes: None,
207 stroke_weight: None,
208 stroke_align: None,
209 stroke_join: None,
210 stroke_dashes: None,
211 fill_geometry: None,
212 stroke_geometry: None,
213 stroke_cap: None,
214 stroke_miter_angle: None,
215 export_settings: None,
216 effects,
217 is_mask: None,
218 mask_type: None,
219 is_mask_outline: None,
220 transition_node_id: None,
221 transition_duration: None,
222 transition_easing: None,
223 characters,
224 style: Box::new(style),
225 character_style_overrides,
226 layout_version: None,
227 style_override_table,
228 line_types,
229 line_indentations,
230 }
231 }
232}
233/// How layer should be treated when the frame is resized
234#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
235pub enum ScrollBehavior {
236 #[serde(rename = "SCROLLS")]
237 Scrolls,
238 #[serde(rename = "FIXED")]
239 Fixed,
240 #[serde(rename = "STICKY_SCROLLS")]
241 StickyScrolls,
242}
243
244impl Default for ScrollBehavior {
245 fn default() -> ScrollBehavior {
246 Self::Scrolls
247 }
248}
249/// Determines if the layer should stretch along the parent's counter axis. This property is only provided for direct children of auto-layout frames. - `INHERIT` - `STRETCH` In previous versions of auto layout, determined how the layer is aligned inside an auto-layout frame. This property is only provided for direct children of auto-layout frames. - `MIN` - `CENTER` - `MAX` - `STRETCH` In horizontal auto-layout frames, \"MIN\" and \"MAX\" correspond to \"TOP\" and \"BOTTOM\". In vertical auto-layout frames, \"MIN\" and \"MAX\" correspond to \"LEFT\" and \"RIGHT\".
250#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
251pub enum LayoutAlign {
252 #[serde(rename = "INHERIT")]
253 Inherit,
254 #[serde(rename = "STRETCH")]
255 Stretch,
256 #[serde(rename = "MIN")]
257 Min,
258 #[serde(rename = "CENTER")]
259 Center,
260 #[serde(rename = "MAX")]
261 Max,
262}
263
264impl Default for LayoutAlign {
265 fn default() -> LayoutAlign {
266 Self::Inherit
267 }
268}
269/// Determines whether a layer's size and position should be determined by auto-layout settings or manually adjustable.
270#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
271pub enum LayoutPositioning {
272 #[serde(rename = "AUTO")]
273 Auto,
274 #[serde(rename = "ABSOLUTE")]
275 Absolute,
276}
277
278impl Default for LayoutPositioning {
279 fn default() -> LayoutPositioning {
280 Self::Auto
281 }
282}
283/// The horizontal sizing setting on this auto-layout frame or frame child. - `FIXED` - `HUG`: only valid on auto-layout frames and text nodes - `FILL`: only valid on auto-layout frame children
284#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
285pub enum LayoutSizingHorizontal {
286 #[serde(rename = "FIXED")]
287 Fixed,
288 #[serde(rename = "HUG")]
289 Hug,
290 #[serde(rename = "FILL")]
291 Fill,
292}
293
294impl Default for LayoutSizingHorizontal {
295 fn default() -> LayoutSizingHorizontal {
296 Self::Fixed
297 }
298}
299/// The vertical sizing setting on this auto-layout frame or frame child. - `FIXED` - `HUG`: only valid on auto-layout frames and text nodes - `FILL`: only valid on auto-layout frame children
300#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
301pub enum LayoutSizingVertical {
302 #[serde(rename = "FIXED")]
303 Fixed,
304 #[serde(rename = "HUG")]
305 Hug,
306 #[serde(rename = "FILL")]
307 Fill,
308}
309
310impl Default for LayoutSizingVertical {
311 fn default() -> LayoutSizingVertical {
312 Self::Fixed
313 }
314}
315/// Position of stroke relative to vector outline, as a string enum - `INSIDE`: stroke drawn inside the shape boundary - `OUTSIDE`: stroke drawn outside the shape boundary - `CENTER`: stroke drawn centered along the shape boundary
316#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
317pub enum StrokeAlign {
318 #[serde(rename = "INSIDE")]
319 Inside,
320 #[serde(rename = "OUTSIDE")]
321 Outside,
322 #[serde(rename = "CENTER")]
323 Center,
324}
325
326impl Default for StrokeAlign {
327 fn default() -> StrokeAlign {
328 Self::Inside
329 }
330}
331/// A string enum with value of \"MITER\", \"BEVEL\", or \"ROUND\", describing how corners in vector paths are rendered.
332#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
333pub enum StrokeJoin {
334 #[serde(rename = "MITER")]
335 Miter,
336 #[serde(rename = "BEVEL")]
337 Bevel,
338 #[serde(rename = "ROUND")]
339 Round,
340}
341
342impl Default for StrokeJoin {
343 fn default() -> StrokeJoin {
344 Self::Miter
345 }
346}
347/// A string enum describing the end caps of vector paths.
348#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
349pub enum StrokeCap {
350 #[serde(rename = "NONE")]
351 None,
352 #[serde(rename = "ROUND")]
353 Round,
354 #[serde(rename = "SQUARE")]
355 Square,
356 #[serde(rename = "LINE_ARROW")]
357 LineArrow,
358 #[serde(rename = "TRIANGLE_ARROW")]
359 TriangleArrow,
360 #[serde(rename = "DIAMOND_FILLED")]
361 DiamondFilled,
362 #[serde(rename = "CIRCLE_FILLED")]
363 CircleFilled,
364 #[serde(rename = "TRIANGLE_FILLED")]
365 TriangleFilled,
366 #[serde(rename = "WASHI_TAPE_1")]
367 WashiTape1,
368 #[serde(rename = "WASHI_TAPE_2")]
369 WashiTape2,
370 #[serde(rename = "WASHI_TAPE_3")]
371 WashiTape3,
372 #[serde(rename = "WASHI_TAPE_4")]
373 WashiTape4,
374 #[serde(rename = "WASHI_TAPE_5")]
375 WashiTape5,
376 #[serde(rename = "WASHI_TAPE_6")]
377 WashiTape6,
378}
379
380impl Default for StrokeCap {
381 fn default() -> StrokeCap {
382 Self::None
383 }
384}
385/// If this layer is a mask, this property describes the operation used to mask the layer's siblings. The value may be one of the following: - ALPHA: the mask node's alpha channel will be used to determine the opacity of each pixel in the masked result. - VECTOR: if the mask node has visible fill paints, every pixel inside the node's fill regions will be fully visible in the masked result. If the mask has visible stroke paints, every pixel inside the node's stroke regions will be fully visible in the masked result. - LUMINANCE: the luminance value of each pixel of the mask node will be used to determine the opacity of that pixel in the masked result.
386#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
387pub enum MaskType {
388 #[serde(rename = "ALPHA")]
389 Alpha,
390 #[serde(rename = "VECTOR")]
391 Vector,
392 #[serde(rename = "LUMINANCE")]
393 Luminance,
394}
395
396impl Default for MaskType {
397 fn default() -> MaskType {
398 Self::Alpha
399 }
400}
401/// An array with the same number of elements as lines in the text node, where lines are delimited by newline or paragraph separator characters. Each element in the array corresponds to the list type of a specific line. List types are represented as string enums with one of these possible values: - `NONE`: Not a list item. - `ORDERED`: Text is an ordered list (numbered). - `UNORDERED`: Text is an unordered list (bulleted).
402#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
403pub enum LineTypes {
404 #[serde(rename = "NONE")]
405 None,
406 #[serde(rename = "ORDERED")]
407 Ordered,
408 #[serde(rename = "UNORDERED")]
409 Unordered,
410}
411
412impl Default for LineTypes {
413 fn default() -> LineTypes {
414 Self::None
415 }
416}
417