Skip to main content

TabStop

Struct TabStop 

Source
pub struct TabStop {
    pub position_twips: i32,
    pub alignment: TabStopAlignment,
    pub leader: Option<TabLeader>,
}
Expand description

A single custom tab stop (w:tab, CT_TabStop), one entry of Paragraph.tabs.

Fields§

§position_twips: i32

The tab stop’s position, in twips, measured from the paragraph’s left margin (w:tab/@pos, ST_SignedTwipsMeasure — signed, since a tab stop can be positioned left of the margin under a negative indent).

§alignment: TabStopAlignment

How text is aligned relative to this tab stop (w:tab/@val).

§leader: Option<TabLeader>

The leader character repeated between the preceding text and this tab stop (w:tab/@leader), or None for a blank leader (Word’s default when the attribute is omitted).

Implementations§

Source§

impl TabStop

Source

pub fn new(position_twips: i32) -> TabStop

Creates a left-aligned tab stop at the given position, with no leader — the most common case.

Examples found in repository?
examples/docx_text_formatting.rs (line 63)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("docx_text_formatting.docx");
18
19    let document = Document::new()
20        .with_paragraph(heading("Docx text formatting — bold, italic, underline, strike", false))
21        .with_paragraph(Paragraph::new().with_run(Run::new("Bold text.").with_bold(true)))
22        .with_paragraph(Paragraph::new().with_run(Run::new("Italic text.").with_italic(true)))
23        .with_paragraph(Paragraph::new().with_run(Run::new("Single underline.").with_underline(UnderlineStyle::Single)))
24        .with_paragraph(Paragraph::new().with_run(Run::new("Wavy underline.").with_underline(UnderlineStyle::Wave)))
25        .with_paragraph(Paragraph::new().with_run(Run::new("Strikethrough text.").with_strike(true)))
26        .with_paragraph(heading("Colors and highlight", true))
27        .with_paragraph(Paragraph::new().with_run(Run::new("Red text on the default background.").with_color("FF0000")))
28        .with_paragraph(Paragraph::new().with_run(Run::new("Text highlighted in yellow.").with_highlight(Highlight::Yellow)))
29        .with_paragraph(
30            Paragraph::new()
31                .with_run(Run::new("Larger, custom font.").with_font_size(32).with_font_family("Georgia")),
32        )
33        .with_paragraph(heading("Superscript and subscript", true))
34        .with_paragraph(
35            Paragraph::new()
36                .with_run(Run::new("Water is H"))
37                .with_run(Run::new("2").with_vertical_align(VerticalAlign::Subscript))
38                .with_run(Run::new("O.")),
39        )
40        .with_paragraph(
41            Paragraph::new()
42                .with_run(Run::new("Squared: x"))
43                .with_run(Run::new("2").with_vertical_align(VerticalAlign::Superscript))
44                .with_run(Run::new(".")),
45        )
46        .with_paragraph(heading("Small caps, all caps, character spacing", true))
47        .with_paragraph(Paragraph::new().with_run(Run::new("rendered in small caps").with_small_caps(true)))
48        .with_paragraph(Paragraph::new().with_run(Run::new("rendered in all caps").with_all_caps(true)))
49        .with_paragraph(Paragraph::new().with_run(Run::new("Widely spaced letters.").with_character_spacing(120)))
50        .with_paragraph(heading("Paragraph alignment", true))
51        .with_paragraph(Paragraph::with_text("Left-aligned (the default).").with_alignment(Alignment::Left))
52        .with_paragraph(Paragraph::with_text("Centered.").with_alignment(Alignment::Center))
53        .with_paragraph(Paragraph::with_text("Right-aligned.").with_alignment(Alignment::Right))
54        .with_paragraph(
55            Paragraph::with_text(
56                "Justified: this line is long enough for Word to stretch the spacing between words so both edges line up.",
57            )
58            .with_alignment(Alignment::Justify),
59        )
60        .with_paragraph(heading("Tab stops", true))
61        .with_paragraph(
62            Paragraph::new()
63                .with_tab(TabStop::new(1_440).with_alignment(TabStopAlignment::Center))
64                .with_tab(TabStop::new(2_880).with_alignment(TabStopAlignment::Right).with_leader(TabLeader::Dot))
65                .with_run(Run::new("Left\tCentered\tRight, dot leader")),
66        );
67
68    document.save_to_file(&path)?;
69    println!("Wrote {}", path.display());
70    Ok(())
71}
Source

pub fn with_alignment(self, alignment: TabStopAlignment) -> TabStop

Sets this tab stop’s alignment and returns it for chaining.

Examples found in repository?
examples/docx_text_formatting.rs (line 63)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("docx_text_formatting.docx");
18
19    let document = Document::new()
20        .with_paragraph(heading("Docx text formatting — bold, italic, underline, strike", false))
21        .with_paragraph(Paragraph::new().with_run(Run::new("Bold text.").with_bold(true)))
22        .with_paragraph(Paragraph::new().with_run(Run::new("Italic text.").with_italic(true)))
23        .with_paragraph(Paragraph::new().with_run(Run::new("Single underline.").with_underline(UnderlineStyle::Single)))
24        .with_paragraph(Paragraph::new().with_run(Run::new("Wavy underline.").with_underline(UnderlineStyle::Wave)))
25        .with_paragraph(Paragraph::new().with_run(Run::new("Strikethrough text.").with_strike(true)))
26        .with_paragraph(heading("Colors and highlight", true))
27        .with_paragraph(Paragraph::new().with_run(Run::new("Red text on the default background.").with_color("FF0000")))
28        .with_paragraph(Paragraph::new().with_run(Run::new("Text highlighted in yellow.").with_highlight(Highlight::Yellow)))
29        .with_paragraph(
30            Paragraph::new()
31                .with_run(Run::new("Larger, custom font.").with_font_size(32).with_font_family("Georgia")),
32        )
33        .with_paragraph(heading("Superscript and subscript", true))
34        .with_paragraph(
35            Paragraph::new()
36                .with_run(Run::new("Water is H"))
37                .with_run(Run::new("2").with_vertical_align(VerticalAlign::Subscript))
38                .with_run(Run::new("O.")),
39        )
40        .with_paragraph(
41            Paragraph::new()
42                .with_run(Run::new("Squared: x"))
43                .with_run(Run::new("2").with_vertical_align(VerticalAlign::Superscript))
44                .with_run(Run::new(".")),
45        )
46        .with_paragraph(heading("Small caps, all caps, character spacing", true))
47        .with_paragraph(Paragraph::new().with_run(Run::new("rendered in small caps").with_small_caps(true)))
48        .with_paragraph(Paragraph::new().with_run(Run::new("rendered in all caps").with_all_caps(true)))
49        .with_paragraph(Paragraph::new().with_run(Run::new("Widely spaced letters.").with_character_spacing(120)))
50        .with_paragraph(heading("Paragraph alignment", true))
51        .with_paragraph(Paragraph::with_text("Left-aligned (the default).").with_alignment(Alignment::Left))
52        .with_paragraph(Paragraph::with_text("Centered.").with_alignment(Alignment::Center))
53        .with_paragraph(Paragraph::with_text("Right-aligned.").with_alignment(Alignment::Right))
54        .with_paragraph(
55            Paragraph::with_text(
56                "Justified: this line is long enough for Word to stretch the spacing between words so both edges line up.",
57            )
58            .with_alignment(Alignment::Justify),
59        )
60        .with_paragraph(heading("Tab stops", true))
61        .with_paragraph(
62            Paragraph::new()
63                .with_tab(TabStop::new(1_440).with_alignment(TabStopAlignment::Center))
64                .with_tab(TabStop::new(2_880).with_alignment(TabStopAlignment::Right).with_leader(TabLeader::Dot))
65                .with_run(Run::new("Left\tCentered\tRight, dot leader")),
66        );
67
68    document.save_to_file(&path)?;
69    println!("Wrote {}", path.display());
70    Ok(())
71}
Source

pub fn with_leader(self, leader: TabLeader) -> TabStop

Sets this tab stop’s leader character and returns it for chaining.

Examples found in repository?
examples/docx_text_formatting.rs (line 64)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("docx_text_formatting.docx");
18
19    let document = Document::new()
20        .with_paragraph(heading("Docx text formatting — bold, italic, underline, strike", false))
21        .with_paragraph(Paragraph::new().with_run(Run::new("Bold text.").with_bold(true)))
22        .with_paragraph(Paragraph::new().with_run(Run::new("Italic text.").with_italic(true)))
23        .with_paragraph(Paragraph::new().with_run(Run::new("Single underline.").with_underline(UnderlineStyle::Single)))
24        .with_paragraph(Paragraph::new().with_run(Run::new("Wavy underline.").with_underline(UnderlineStyle::Wave)))
25        .with_paragraph(Paragraph::new().with_run(Run::new("Strikethrough text.").with_strike(true)))
26        .with_paragraph(heading("Colors and highlight", true))
27        .with_paragraph(Paragraph::new().with_run(Run::new("Red text on the default background.").with_color("FF0000")))
28        .with_paragraph(Paragraph::new().with_run(Run::new("Text highlighted in yellow.").with_highlight(Highlight::Yellow)))
29        .with_paragraph(
30            Paragraph::new()
31                .with_run(Run::new("Larger, custom font.").with_font_size(32).with_font_family("Georgia")),
32        )
33        .with_paragraph(heading("Superscript and subscript", true))
34        .with_paragraph(
35            Paragraph::new()
36                .with_run(Run::new("Water is H"))
37                .with_run(Run::new("2").with_vertical_align(VerticalAlign::Subscript))
38                .with_run(Run::new("O.")),
39        )
40        .with_paragraph(
41            Paragraph::new()
42                .with_run(Run::new("Squared: x"))
43                .with_run(Run::new("2").with_vertical_align(VerticalAlign::Superscript))
44                .with_run(Run::new(".")),
45        )
46        .with_paragraph(heading("Small caps, all caps, character spacing", true))
47        .with_paragraph(Paragraph::new().with_run(Run::new("rendered in small caps").with_small_caps(true)))
48        .with_paragraph(Paragraph::new().with_run(Run::new("rendered in all caps").with_all_caps(true)))
49        .with_paragraph(Paragraph::new().with_run(Run::new("Widely spaced letters.").with_character_spacing(120)))
50        .with_paragraph(heading("Paragraph alignment", true))
51        .with_paragraph(Paragraph::with_text("Left-aligned (the default).").with_alignment(Alignment::Left))
52        .with_paragraph(Paragraph::with_text("Centered.").with_alignment(Alignment::Center))
53        .with_paragraph(Paragraph::with_text("Right-aligned.").with_alignment(Alignment::Right))
54        .with_paragraph(
55            Paragraph::with_text(
56                "Justified: this line is long enough for Word to stretch the spacing between words so both edges line up.",
57            )
58            .with_alignment(Alignment::Justify),
59        )
60        .with_paragraph(heading("Tab stops", true))
61        .with_paragraph(
62            Paragraph::new()
63                .with_tab(TabStop::new(1_440).with_alignment(TabStopAlignment::Center))
64                .with_tab(TabStop::new(2_880).with_alignment(TabStopAlignment::Right).with_leader(TabLeader::Dot))
65                .with_run(Run::new("Left\tCentered\tRight, dot leader")),
66        );
67
68    document.save_to_file(&path)?;
69    println!("Wrote {}", path.display());
70    Ok(())
71}

Trait Implementations§

Source§

impl Clone for TabStop

Source§

fn clone(&self) -> TabStop

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 Copy for TabStop

Source§

impl Debug for TabStop

Source§

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

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

impl Eq for TabStop

Source§

impl PartialEq for TabStop

Source§

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

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.