Skip to main content

Connector

Struct Connector 

Source
pub struct Connector {
    pub id: u32,
    pub name: String,
    pub properties: ShapeProperties,
    pub start_connection: Option<ShapeConnection>,
    pub end_connection: Option<ShapeConnection>,
}
Expand description

A straight/elbow/curved connector line (<p:cxnSp>, CT_Connector), typically used to visually link two other shapes.

Not grounded on a real fixture — see this module’s own top-level doc comment. Structure follows ECMA-376’s CT_Connector/ CT_ConnectorNonVisual directly: a connector’s own <p:spPr> is the exact same CT_ShapeProperties content type an autoshape’s <p:spPr> uses (position/geometry/fill/line), so properties reuses drawing::ShapeProperties verbatim, same as AutoShape — only the non-visual wrapper element name (p:cxnSp/p:nvCxnSpPr instead of p:sp/p:nvSpPr) and the optional start/end shape attachments differ. When properties.geometry is unset, the writer defaults to <a:prstGeom prst="line"> (a straight connector) rather than AutoShape’s own rect default — the same “always write geometry explicitly” discipline, just with a connector-appropriate default preset.

Fields§

§id: u32

<p:cNvPr id=".."> — same uniqueness rules as AutoShape::id.

§name: String

<p:cNvPr name="..">.

§properties: ShapeProperties

<p:spPr>’s content — position/size, outline geometry, fill, line.

§start_connection: Option<ShapeConnection>

<p:nvCxnSpPr><p:cNvCxnSpPr><a:stCxn id=".." idx=".."/> — which other shape (and which of its connection sites) this connector’s start point is attached to. None for a floating, unattached start point (positioned by properties’ own xfrm alone).

§end_connection: Option<ShapeConnection>

<a:endCxn id=".." idx=".."/> — same as start_connection, for the connector’s end point.

Implementations§

Source§

impl Connector

Source

pub fn new(id: u32, name: impl Into<String>) -> Connector

Creates a floating connector (no shape attachments) with no explicit position/size/line.

Examples found in repository?
examples/pptx_grouping_and_connectors.rs (line 105)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("pptx_grouping_and_connectors.pptx");
18
19    // Every shape below sets an explicit fill (and the connector an
20    // explicit line): with neither a fill/line nor a `<p:style>` theme
21    // reference, a shape has nothing to paint and renders as fully
22    // invisible — the slide then looks blank even though the shapes are
23    // there. `AutoShape`/`Connector` have no `<p:style>` support yet, so an
24    // explicit `Fill`/`Line` is the only way to make a shape actually show.
25    let circle_fill = || Fill::Solid(Color::Rgb("4472C4".to_string()));
26
27    let circle = AutoShape::new(11, "Circle").with_properties(
28        ShapeProperties::new()
29            .with_transform(
30                Transform2D::new()
31                    .with_offset(0, 0)
32                    .with_extent(1_000_000, 1_000_000),
33            )
34            .with_fill(circle_fill()),
35    );
36    let label = AutoShape::new(12, "Label")
37        .with_properties(
38            ShapeProperties::new()
39                .with_transform(
40                    Transform2D::new()
41                        .with_offset(1_200_000, 300_000)
42                        .with_extent(1_500_000, 400_000),
43                )
44                .with_fill(Fill::Solid(Color::Rgb("E8622C".to_string()))),
45        )
46        .with_text_body(
47            TextBody::new()
48                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Grouped label"))),
49        );
50
51    let group = ShapeGroup::new(2, "Group")
52        .with_transform(
53            (838_200, 838_200),
54            (2_700_000, 1_000_000),
55            (0, 0),
56            (2_700_000, 1_000_000),
57        )
58        .with_shape(Shape::AutoShape(circle))
59        .with_shape(Shape::AutoShape(label));
60
61    let rotated_circle = AutoShape::new(11, "Circle").with_properties(
62        ShapeProperties::new()
63            .with_transform(
64                Transform2D::new()
65                    .with_offset(0, 0)
66                    .with_extent(1_000_000, 1_000_000),
67            )
68            .with_fill(circle_fill()),
69    );
70    let rotated_group = ShapeGroup::new(2, "Rotated and flipped group")
71        .with_transform(
72            (838_200, 838_200),
73            (1_000_000, 1_000_000),
74            (0, 0),
75            (1_000_000, 1_000_000),
76        )
77        .with_rotation_degrees(45.0)
78        .with_flip_horizontal(true)
79        .with_shape(Shape::AutoShape(rotated_circle));
80
81    let box_a = AutoShape::new(2, "Box A").with_properties(
82        ShapeProperties::new()
83            .with_transform(
84                Transform2D::new()
85                    .with_offset(838_200, 838_200)
86                    .with_extent(1_000_000, 1_000_000),
87            )
88            .with_fill(Fill::Solid(Color::Rgb("2E86AB".to_string()))),
89    );
90    let box_b = AutoShape::new(3, "Box B").with_properties(
91        ShapeProperties::new()
92            .with_transform(
93                Transform2D::new()
94                    .with_offset(3_500_000, 838_200)
95                    .with_extent(1_000_000, 1_000_000),
96            )
97            .with_fill(Fill::Solid(Color::Rgb("6FB98F".to_string()))),
98    );
99    // `Connector::new` leaves position/size unset, which the writer then
100    // emits as a zero-size `<a:xfrm>` (off 0,0 / ext 0,0) — a real point
101    // with no length, invisible regardless of line/fill. `stCxn`/`endCxn`
102    // alone don't supply geometry; PowerPoint only recomputes it once you
103    // drag one of the attached shapes. So this also sets an explicit
104    // transform spanning Box A's right edge to Box B's left edge.
105    let connector = Connector::new(4, "Connector")
106        .with_properties(
107            ShapeProperties::new()
108                .with_transform(
109                    Transform2D::new()
110                        .with_offset(1_838_200, 1_338_200)
111                        .with_extent(1_662_000, 0),
112                )
113                .with_line(
114                    Line::new()
115                        .with_width_emu(25_400)
116                        .with_fill(Fill::Solid(Color::Rgb("000000".to_string()))),
117                ),
118        )
119        .with_start_connection(2, 0)
120        .with_end_connection(3, 0);
121
122    let presentation = Presentation::new()
123        .with_slide(Slide::new().with_shape(Shape::Group(group)))
124        .with_slide(Slide::new().with_shape(Shape::Group(rotated_group)))
125        .with_slide(
126            Slide::new()
127                .with_shape(Shape::AutoShape(box_a))
128                .with_shape(Shape::AutoShape(box_b))
129                .with_shape(Shape::Connector(connector)),
130        );
131
132    presentation.save_to_file(&path)?;
133    println!("Wrote {}", path.display());
134    Ok(())
135}
Source

pub fn with_properties(self, properties: ShapeProperties) -> Connector

Sets this connector’s position/size/line/fill.

Examples found in repository?
examples/pptx_grouping_and_connectors.rs (lines 106-118)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("pptx_grouping_and_connectors.pptx");
18
19    // Every shape below sets an explicit fill (and the connector an
20    // explicit line): with neither a fill/line nor a `<p:style>` theme
21    // reference, a shape has nothing to paint and renders as fully
22    // invisible — the slide then looks blank even though the shapes are
23    // there. `AutoShape`/`Connector` have no `<p:style>` support yet, so an
24    // explicit `Fill`/`Line` is the only way to make a shape actually show.
25    let circle_fill = || Fill::Solid(Color::Rgb("4472C4".to_string()));
26
27    let circle = AutoShape::new(11, "Circle").with_properties(
28        ShapeProperties::new()
29            .with_transform(
30                Transform2D::new()
31                    .with_offset(0, 0)
32                    .with_extent(1_000_000, 1_000_000),
33            )
34            .with_fill(circle_fill()),
35    );
36    let label = AutoShape::new(12, "Label")
37        .with_properties(
38            ShapeProperties::new()
39                .with_transform(
40                    Transform2D::new()
41                        .with_offset(1_200_000, 300_000)
42                        .with_extent(1_500_000, 400_000),
43                )
44                .with_fill(Fill::Solid(Color::Rgb("E8622C".to_string()))),
45        )
46        .with_text_body(
47            TextBody::new()
48                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Grouped label"))),
49        );
50
51    let group = ShapeGroup::new(2, "Group")
52        .with_transform(
53            (838_200, 838_200),
54            (2_700_000, 1_000_000),
55            (0, 0),
56            (2_700_000, 1_000_000),
57        )
58        .with_shape(Shape::AutoShape(circle))
59        .with_shape(Shape::AutoShape(label));
60
61    let rotated_circle = AutoShape::new(11, "Circle").with_properties(
62        ShapeProperties::new()
63            .with_transform(
64                Transform2D::new()
65                    .with_offset(0, 0)
66                    .with_extent(1_000_000, 1_000_000),
67            )
68            .with_fill(circle_fill()),
69    );
70    let rotated_group = ShapeGroup::new(2, "Rotated and flipped group")
71        .with_transform(
72            (838_200, 838_200),
73            (1_000_000, 1_000_000),
74            (0, 0),
75            (1_000_000, 1_000_000),
76        )
77        .with_rotation_degrees(45.0)
78        .with_flip_horizontal(true)
79        .with_shape(Shape::AutoShape(rotated_circle));
80
81    let box_a = AutoShape::new(2, "Box A").with_properties(
82        ShapeProperties::new()
83            .with_transform(
84                Transform2D::new()
85                    .with_offset(838_200, 838_200)
86                    .with_extent(1_000_000, 1_000_000),
87            )
88            .with_fill(Fill::Solid(Color::Rgb("2E86AB".to_string()))),
89    );
90    let box_b = AutoShape::new(3, "Box B").with_properties(
91        ShapeProperties::new()
92            .with_transform(
93                Transform2D::new()
94                    .with_offset(3_500_000, 838_200)
95                    .with_extent(1_000_000, 1_000_000),
96            )
97            .with_fill(Fill::Solid(Color::Rgb("6FB98F".to_string()))),
98    );
99    // `Connector::new` leaves position/size unset, which the writer then
100    // emits as a zero-size `<a:xfrm>` (off 0,0 / ext 0,0) — a real point
101    // with no length, invisible regardless of line/fill. `stCxn`/`endCxn`
102    // alone don't supply geometry; PowerPoint only recomputes it once you
103    // drag one of the attached shapes. So this also sets an explicit
104    // transform spanning Box A's right edge to Box B's left edge.
105    let connector = Connector::new(4, "Connector")
106        .with_properties(
107            ShapeProperties::new()
108                .with_transform(
109                    Transform2D::new()
110                        .with_offset(1_838_200, 1_338_200)
111                        .with_extent(1_662_000, 0),
112                )
113                .with_line(
114                    Line::new()
115                        .with_width_emu(25_400)
116                        .with_fill(Fill::Solid(Color::Rgb("000000".to_string()))),
117                ),
118        )
119        .with_start_connection(2, 0)
120        .with_end_connection(3, 0);
121
122    let presentation = Presentation::new()
123        .with_slide(Slide::new().with_shape(Shape::Group(group)))
124        .with_slide(Slide::new().with_shape(Shape::Group(rotated_group)))
125        .with_slide(
126            Slide::new()
127                .with_shape(Shape::AutoShape(box_a))
128                .with_shape(Shape::AutoShape(box_b))
129                .with_shape(Shape::Connector(connector)),
130        );
131
132    presentation.save_to_file(&path)?;
133    println!("Wrote {}", path.display());
134    Ok(())
135}
Source

pub fn with_start_connection(self, shape_id: u32, index: u32) -> Connector

Attaches this connector’s start point to another shape’s connection site.

Examples found in repository?
examples/pptx_grouping_and_connectors.rs (line 119)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("pptx_grouping_and_connectors.pptx");
18
19    // Every shape below sets an explicit fill (and the connector an
20    // explicit line): with neither a fill/line nor a `<p:style>` theme
21    // reference, a shape has nothing to paint and renders as fully
22    // invisible — the slide then looks blank even though the shapes are
23    // there. `AutoShape`/`Connector` have no `<p:style>` support yet, so an
24    // explicit `Fill`/`Line` is the only way to make a shape actually show.
25    let circle_fill = || Fill::Solid(Color::Rgb("4472C4".to_string()));
26
27    let circle = AutoShape::new(11, "Circle").with_properties(
28        ShapeProperties::new()
29            .with_transform(
30                Transform2D::new()
31                    .with_offset(0, 0)
32                    .with_extent(1_000_000, 1_000_000),
33            )
34            .with_fill(circle_fill()),
35    );
36    let label = AutoShape::new(12, "Label")
37        .with_properties(
38            ShapeProperties::new()
39                .with_transform(
40                    Transform2D::new()
41                        .with_offset(1_200_000, 300_000)
42                        .with_extent(1_500_000, 400_000),
43                )
44                .with_fill(Fill::Solid(Color::Rgb("E8622C".to_string()))),
45        )
46        .with_text_body(
47            TextBody::new()
48                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Grouped label"))),
49        );
50
51    let group = ShapeGroup::new(2, "Group")
52        .with_transform(
53            (838_200, 838_200),
54            (2_700_000, 1_000_000),
55            (0, 0),
56            (2_700_000, 1_000_000),
57        )
58        .with_shape(Shape::AutoShape(circle))
59        .with_shape(Shape::AutoShape(label));
60
61    let rotated_circle = AutoShape::new(11, "Circle").with_properties(
62        ShapeProperties::new()
63            .with_transform(
64                Transform2D::new()
65                    .with_offset(0, 0)
66                    .with_extent(1_000_000, 1_000_000),
67            )
68            .with_fill(circle_fill()),
69    );
70    let rotated_group = ShapeGroup::new(2, "Rotated and flipped group")
71        .with_transform(
72            (838_200, 838_200),
73            (1_000_000, 1_000_000),
74            (0, 0),
75            (1_000_000, 1_000_000),
76        )
77        .with_rotation_degrees(45.0)
78        .with_flip_horizontal(true)
79        .with_shape(Shape::AutoShape(rotated_circle));
80
81    let box_a = AutoShape::new(2, "Box A").with_properties(
82        ShapeProperties::new()
83            .with_transform(
84                Transform2D::new()
85                    .with_offset(838_200, 838_200)
86                    .with_extent(1_000_000, 1_000_000),
87            )
88            .with_fill(Fill::Solid(Color::Rgb("2E86AB".to_string()))),
89    );
90    let box_b = AutoShape::new(3, "Box B").with_properties(
91        ShapeProperties::new()
92            .with_transform(
93                Transform2D::new()
94                    .with_offset(3_500_000, 838_200)
95                    .with_extent(1_000_000, 1_000_000),
96            )
97            .with_fill(Fill::Solid(Color::Rgb("6FB98F".to_string()))),
98    );
99    // `Connector::new` leaves position/size unset, which the writer then
100    // emits as a zero-size `<a:xfrm>` (off 0,0 / ext 0,0) — a real point
101    // with no length, invisible regardless of line/fill. `stCxn`/`endCxn`
102    // alone don't supply geometry; PowerPoint only recomputes it once you
103    // drag one of the attached shapes. So this also sets an explicit
104    // transform spanning Box A's right edge to Box B's left edge.
105    let connector = Connector::new(4, "Connector")
106        .with_properties(
107            ShapeProperties::new()
108                .with_transform(
109                    Transform2D::new()
110                        .with_offset(1_838_200, 1_338_200)
111                        .with_extent(1_662_000, 0),
112                )
113                .with_line(
114                    Line::new()
115                        .with_width_emu(25_400)
116                        .with_fill(Fill::Solid(Color::Rgb("000000".to_string()))),
117                ),
118        )
119        .with_start_connection(2, 0)
120        .with_end_connection(3, 0);
121
122    let presentation = Presentation::new()
123        .with_slide(Slide::new().with_shape(Shape::Group(group)))
124        .with_slide(Slide::new().with_shape(Shape::Group(rotated_group)))
125        .with_slide(
126            Slide::new()
127                .with_shape(Shape::AutoShape(box_a))
128                .with_shape(Shape::AutoShape(box_b))
129                .with_shape(Shape::Connector(connector)),
130        );
131
132    presentation.save_to_file(&path)?;
133    println!("Wrote {}", path.display());
134    Ok(())
135}
Source

pub fn with_end_connection(self, shape_id: u32, index: u32) -> Connector

Attaches this connector’s end point to another shape’s connection site.

Examples found in repository?
examples/pptx_grouping_and_connectors.rs (line 120)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("pptx_grouping_and_connectors.pptx");
18
19    // Every shape below sets an explicit fill (and the connector an
20    // explicit line): with neither a fill/line nor a `<p:style>` theme
21    // reference, a shape has nothing to paint and renders as fully
22    // invisible — the slide then looks blank even though the shapes are
23    // there. `AutoShape`/`Connector` have no `<p:style>` support yet, so an
24    // explicit `Fill`/`Line` is the only way to make a shape actually show.
25    let circle_fill = || Fill::Solid(Color::Rgb("4472C4".to_string()));
26
27    let circle = AutoShape::new(11, "Circle").with_properties(
28        ShapeProperties::new()
29            .with_transform(
30                Transform2D::new()
31                    .with_offset(0, 0)
32                    .with_extent(1_000_000, 1_000_000),
33            )
34            .with_fill(circle_fill()),
35    );
36    let label = AutoShape::new(12, "Label")
37        .with_properties(
38            ShapeProperties::new()
39                .with_transform(
40                    Transform2D::new()
41                        .with_offset(1_200_000, 300_000)
42                        .with_extent(1_500_000, 400_000),
43                )
44                .with_fill(Fill::Solid(Color::Rgb("E8622C".to_string()))),
45        )
46        .with_text_body(
47            TextBody::new()
48                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Grouped label"))),
49        );
50
51    let group = ShapeGroup::new(2, "Group")
52        .with_transform(
53            (838_200, 838_200),
54            (2_700_000, 1_000_000),
55            (0, 0),
56            (2_700_000, 1_000_000),
57        )
58        .with_shape(Shape::AutoShape(circle))
59        .with_shape(Shape::AutoShape(label));
60
61    let rotated_circle = AutoShape::new(11, "Circle").with_properties(
62        ShapeProperties::new()
63            .with_transform(
64                Transform2D::new()
65                    .with_offset(0, 0)
66                    .with_extent(1_000_000, 1_000_000),
67            )
68            .with_fill(circle_fill()),
69    );
70    let rotated_group = ShapeGroup::new(2, "Rotated and flipped group")
71        .with_transform(
72            (838_200, 838_200),
73            (1_000_000, 1_000_000),
74            (0, 0),
75            (1_000_000, 1_000_000),
76        )
77        .with_rotation_degrees(45.0)
78        .with_flip_horizontal(true)
79        .with_shape(Shape::AutoShape(rotated_circle));
80
81    let box_a = AutoShape::new(2, "Box A").with_properties(
82        ShapeProperties::new()
83            .with_transform(
84                Transform2D::new()
85                    .with_offset(838_200, 838_200)
86                    .with_extent(1_000_000, 1_000_000),
87            )
88            .with_fill(Fill::Solid(Color::Rgb("2E86AB".to_string()))),
89    );
90    let box_b = AutoShape::new(3, "Box B").with_properties(
91        ShapeProperties::new()
92            .with_transform(
93                Transform2D::new()
94                    .with_offset(3_500_000, 838_200)
95                    .with_extent(1_000_000, 1_000_000),
96            )
97            .with_fill(Fill::Solid(Color::Rgb("6FB98F".to_string()))),
98    );
99    // `Connector::new` leaves position/size unset, which the writer then
100    // emits as a zero-size `<a:xfrm>` (off 0,0 / ext 0,0) — a real point
101    // with no length, invisible regardless of line/fill. `stCxn`/`endCxn`
102    // alone don't supply geometry; PowerPoint only recomputes it once you
103    // drag one of the attached shapes. So this also sets an explicit
104    // transform spanning Box A's right edge to Box B's left edge.
105    let connector = Connector::new(4, "Connector")
106        .with_properties(
107            ShapeProperties::new()
108                .with_transform(
109                    Transform2D::new()
110                        .with_offset(1_838_200, 1_338_200)
111                        .with_extent(1_662_000, 0),
112                )
113                .with_line(
114                    Line::new()
115                        .with_width_emu(25_400)
116                        .with_fill(Fill::Solid(Color::Rgb("000000".to_string()))),
117                ),
118        )
119        .with_start_connection(2, 0)
120        .with_end_connection(3, 0);
121
122    let presentation = Presentation::new()
123        .with_slide(Slide::new().with_shape(Shape::Group(group)))
124        .with_slide(Slide::new().with_shape(Shape::Group(rotated_group)))
125        .with_slide(
126            Slide::new()
127                .with_shape(Shape::AutoShape(box_a))
128                .with_shape(Shape::AutoShape(box_b))
129                .with_shape(Shape::Connector(connector)),
130        );
131
132    presentation.save_to_file(&path)?;
133    println!("Wrote {}", path.display());
134    Ok(())
135}

Trait Implementations§

Source§

impl Clone for Connector

Source§

fn clone(&self) -> Connector

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Connector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Connector

Source§

fn eq(&self, other: &Connector) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Connector

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.