pub struct ListLevel {
pub format: NumberFormat,
pub text: String,
pub indent_twips: i32,
pub hanging_twips: i32,
}Expand description
A single indent level of a NumberingDefinition (w:lvl, CT_Lvl).
Only the handful of properties needed to produce a correctly-formatted, correctly-indented list
are modeled (numFmt, lvlText, and the indentation CT_Lvl’s own pPr sets) — not pStyle
(a paragraph style tied to the level), lvlPicBulletId (a picture bullet), lvlJc
(WordprocessingML lets a level’s own number/bullet be right/center aligned within its indent —
always left here, matching the common case), suff (what follows the number: tab/space/nothing
— always a tab, Word’s default), or per-level run formatting (rPr) — a deliberately plain
bullet/number, styled the same as the surrounding text, rather than needing this crate to also
model fonts just to reproduce Word’s own Wingdings/Symbol-font bullet glyphs.
Fields§
§format: NumberFormatHow this level’s number/bullet is formatted (w:numFmt).
text: StringThe level’s number/bullet template (w:lvlText‘s val) — a literal bullet character for
NumberFormat::Bullet (e.g. "•"), or a placeholder template for the numbered formats,
where %1 is this level’s own counter and %2/%3/. refer to ancestor levels’ counters
(e.g. "%1." for a simple “1.”, or "%1.%2." for a second level that repeats its parent’s
number, matching Word’s own default multilevel numbering).
indent_twips: i32This level’s left indent, in twips (1/20 pt) — w:pPr/w:ind’s left attribute.
hanging_twips: i32How far the number/bullet hangs to the left of the following text’s left edge, in twips —
w:pPr/w:ind’s hanging attribute. Word’s own default lists always use 360 regardless of
level.
Implementations§
Source§impl ListLevel
impl ListLevel
Sourcepub fn new(
format: NumberFormat,
text: impl Into<String>,
indent_twips: i32,
hanging_twips: i32,
) -> ListLevel
pub fn new( format: NumberFormat, text: impl Into<String>, indent_twips: i32, hanging_twips: i32, ) -> ListLevel
Creates a single indent level with explicit formatting and indentation.
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("docx_styles_and_lists.docx");
15
16 let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17 .with_bold(true)
18 .with_font_size(32);
19 let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20 .with_bold(true)
21 .with_color("C00000");
22
23 let bulleted = NumberingDefinition::bullet(1);
24 let numbered = NumberingDefinition::decimal(2);
25 let custom = NumberingDefinition::new(
26 3,
27 vec![
28 ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29 ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30 ],
31 );
32
33 let document = Document::new()
34 .with_style(heading_style)
35 .with_style(emphasis_style)
36 .with_numbering_definition(bulleted)
37 .with_numbering_definition(numbered)
38 .with_numbering_definition(custom)
39 .with_paragraph(heading("Named paragraph and character styles", false))
40 .with_paragraph(
41 Paragraph::with_text("This paragraph uses the Heading 1 style.")
42 .with_style_id("Heading1"),
43 )
44 .with_paragraph(
45 Paragraph::new()
46 .with_run(Run::new("Plain text, then "))
47 .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48 .with_run(Run::new(", then plain text again.")),
49 )
50 .with_paragraph(heading("Bulleted list", true))
51 .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52 .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53 .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54 .with_paragraph(heading("Numbered list", true))
55 .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56 .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57 .with_paragraph(
58 Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59 )
60 .with_paragraph(heading(
61 "Custom multi-level list (roman numerals, then letters)",
62 true,
63 ))
64 .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65 .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66 .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68 document.save_to_file(&path)?;
69 println!("Wrote {}", path.display());
70 Ok(())
71}Trait Implementations§
impl Eq for ListLevel
impl StructuralPartialEq for ListLevel
Auto Trait Implementations§
impl Freeze for ListLevel
impl RefUnwindSafe for ListLevel
impl Send for ListLevel
impl Sync for ListLevel
impl Unpin for ListLevel
impl UnsafeUnpin for ListLevel
impl UnwindSafe for ListLevel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.