Skip to main content

Placeholder

Struct Placeholder 

Source
pub struct Placeholder {
    pub kind: PlaceholderKind,
    pub index: Option<u32>,
}
Expand description

<p:nvPr><p:ph type=".." idx=".."/></p:nvPr> (CT_Placeholder) — a shape’s placeholder role: which slot of the slide layout/master it fills, so its position/formatting can be inherited from there instead of being set explicitly. This crate never resolves that inheritance (no slide layout/master model beyond a single fixed, empty one — see Presentation’s doc comment); recording Placeholder on a read-back shape is purely informational; nothing else in this crate consults it.

Fields§

§kind: PlaceholderKind

type — which slot this shape fills (ST_PlaceholderType).

§index: Option<u32>

idx — disambiguates multiple placeholders of the same kind on one layout (e.g. several body placeholders). None omits the attribute, matching a title placeholder’s own convention (real PowerPoint never writes idx on title/ctrTitle).

Implementations§

Source§

impl Placeholder

Source

pub fn new(kind: PlaceholderKind) -> Placeholder

Creates a placeholder role with no explicit index.

Examples found in repository?
examples/pptx_shapes_and_placeholders.rs (line 44)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("pptx_shapes_and_placeholders.pptx");
16
17    let plain_shape = AutoShape::new(2, "Plain autoshape")
18        .with_properties(
19            ShapeProperties::new().with_transform(
20                Transform2D::new()
21                    .with_offset(838_200, 838_200)
22                    .with_extent(5_000_000, 1_000_000),
23            ),
24        )
25        .with_text_body(
26            TextBody::new()
27                .with_paragraph(TextParagraph::new().with_run(TextRun::text("A plain autoshape."))),
28        );
29
30    let text_box = AutoShape::new(2, "Text box")
31        .with_text_box(true)
32        .with_properties(
33            ShapeProperties::new().with_transform(
34                Transform2D::new()
35                    .with_offset(838_200, 838_200)
36                    .with_extent(5_000_000, 1_000_000),
37            ),
38        )
39        .with_text_body(TextBody::new().with_paragraph(
40            TextParagraph::new().with_run(TextRun::text("A genuine text box (txBox=\"1\").")),
41        ));
42
43    let title = AutoShape::new(2, "Title placeholder")
44        .with_placeholder(Placeholder::new(PlaceholderKind::CenterTitle))
45        .with_properties(
46            ShapeProperties::new().with_transform(
47                Transform2D::new()
48                    .with_offset(838_200, 838_200)
49                    .with_extent(10_515_600, 1_325_563),
50            ),
51        )
52        .with_text_body(
53            TextBody::new()
54                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Title placeholder"))),
55        );
56    let subtitle =
57        AutoShape::new(3, "Subtitle placeholder")
58            .with_placeholder(Placeholder::new(PlaceholderKind::SubTitle).with_index(1))
59            .with_properties(
60                ShapeProperties::new().with_transform(
61                    Transform2D::new()
62                        .with_offset(838_200, 2_400_000)
63                        .with_extent(10_515_600, 800_000),
64                ),
65            )
66            .with_text_body(TextBody::new().with_paragraph(
67                TextParagraph::new().with_run(TextRun::text("Subtitle placeholder")),
68            ));
69
70    let hyperlinked_shape = AutoShape::new(2, "Hyperlinked shape")
71        .with_hyperlink("https://www.rust-lang.org")
72        .with_properties(
73            ShapeProperties::new().with_transform(
74                Transform2D::new()
75                    .with_offset(838_200, 838_200)
76                    .with_extent(5_000_000, 1_000_000),
77            ),
78        )
79        .with_text_body(TextBody::new().with_paragraph(
80            TextParagraph::new().with_run(TextRun::text("Click this shape to open a link.")),
81        ));
82
83    let presentation = Presentation::new()
84        .with_slide(Slide::new().with_shape(Shape::AutoShape(plain_shape)))
85        .with_slide(Slide::new().with_shape(Shape::AutoShape(text_box)))
86        .with_slide(
87            Slide::new()
88                .with_shape(Shape::AutoShape(title))
89                .with_shape(Shape::AutoShape(subtitle)),
90        )
91        .with_slide(Slide::new().with_shape(Shape::AutoShape(hyperlinked_shape)));
92
93    presentation.save_to_file(&path)?;
94    println!("Wrote {}", path.display());
95    Ok(())
96}
Source

pub fn with_index(self, index: u32) -> Placeholder

Sets this placeholder’s idx attribute.

Examples found in repository?
examples/pptx_shapes_and_placeholders.rs (line 58)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("pptx_shapes_and_placeholders.pptx");
16
17    let plain_shape = AutoShape::new(2, "Plain autoshape")
18        .with_properties(
19            ShapeProperties::new().with_transform(
20                Transform2D::new()
21                    .with_offset(838_200, 838_200)
22                    .with_extent(5_000_000, 1_000_000),
23            ),
24        )
25        .with_text_body(
26            TextBody::new()
27                .with_paragraph(TextParagraph::new().with_run(TextRun::text("A plain autoshape."))),
28        );
29
30    let text_box = AutoShape::new(2, "Text box")
31        .with_text_box(true)
32        .with_properties(
33            ShapeProperties::new().with_transform(
34                Transform2D::new()
35                    .with_offset(838_200, 838_200)
36                    .with_extent(5_000_000, 1_000_000),
37            ),
38        )
39        .with_text_body(TextBody::new().with_paragraph(
40            TextParagraph::new().with_run(TextRun::text("A genuine text box (txBox=\"1\").")),
41        ));
42
43    let title = AutoShape::new(2, "Title placeholder")
44        .with_placeholder(Placeholder::new(PlaceholderKind::CenterTitle))
45        .with_properties(
46            ShapeProperties::new().with_transform(
47                Transform2D::new()
48                    .with_offset(838_200, 838_200)
49                    .with_extent(10_515_600, 1_325_563),
50            ),
51        )
52        .with_text_body(
53            TextBody::new()
54                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Title placeholder"))),
55        );
56    let subtitle =
57        AutoShape::new(3, "Subtitle placeholder")
58            .with_placeholder(Placeholder::new(PlaceholderKind::SubTitle).with_index(1))
59            .with_properties(
60                ShapeProperties::new().with_transform(
61                    Transform2D::new()
62                        .with_offset(838_200, 2_400_000)
63                        .with_extent(10_515_600, 800_000),
64                ),
65            )
66            .with_text_body(TextBody::new().with_paragraph(
67                TextParagraph::new().with_run(TextRun::text("Subtitle placeholder")),
68            ));
69
70    let hyperlinked_shape = AutoShape::new(2, "Hyperlinked shape")
71        .with_hyperlink("https://www.rust-lang.org")
72        .with_properties(
73            ShapeProperties::new().with_transform(
74                Transform2D::new()
75                    .with_offset(838_200, 838_200)
76                    .with_extent(5_000_000, 1_000_000),
77            ),
78        )
79        .with_text_body(TextBody::new().with_paragraph(
80            TextParagraph::new().with_run(TextRun::text("Click this shape to open a link.")),
81        ));
82
83    let presentation = Presentation::new()
84        .with_slide(Slide::new().with_shape(Shape::AutoShape(plain_shape)))
85        .with_slide(Slide::new().with_shape(Shape::AutoShape(text_box)))
86        .with_slide(
87            Slide::new()
88                .with_shape(Shape::AutoShape(title))
89                .with_shape(Shape::AutoShape(subtitle)),
90        )
91        .with_slide(Slide::new().with_shape(Shape::AutoShape(hyperlinked_shape)));
92
93    presentation.save_to_file(&path)?;
94    println!("Wrote {}", path.display());
95    Ok(())
96}

Trait Implementations§

Source§

impl Clone for Placeholder

Source§

fn clone(&self) -> Placeholder

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 Placeholder

Source§

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

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

impl Eq for Placeholder

Source§

impl PartialEq for Placeholder

Source§

fn eq(&self, other: &Placeholder) -> 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 Placeholder

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.