spreadsheet_ods/format/builder.rs
1use crate::format::{
2 FormatCalendarStyle, FormatNumberStyle, FormatPart, FormatPartType, ValueFormatTrait,
3};
4use icu_locale_core::Locale;
5
6/// Builder for FormatPart with type Number.
7#[derive(Debug)]
8pub struct PartNumberBuilder<'vf, T: ValueFormatTrait> {
9 part: FormatPart,
10 valueformat: &'vf mut T,
11}
12
13impl<'vf, T: ValueFormatTrait> PartNumberBuilder<'vf, T> {
14 /// New builder for the valueformat.
15 pub fn new<'a>(valueformat: &'a mut T) -> Self
16 where
17 'a: 'vf,
18 {
19 Self {
20 part: FormatPart::new(FormatPartType::Number),
21 valueformat,
22 }
23 }
24
25 /// Appends the constructed FormatPart to the original value format.
26 pub fn build(self) {
27 self.valueformat.push_part(self.part);
28 }
29
30 /// Only applies the builder if the test is true.
31 #[must_use]
32 pub fn if_then<F>(self, test: bool, build: F) -> Self
33 where
34 F: Fn(Self) -> Self,
35 {
36 if test {
37 build(self)
38 } else {
39 self
40 }
41 }
42
43 /// If the number:decimal-places attribute is not specified, the number of decimal places
44 /// specified by the default table cell style is used.
45 #[must_use]
46 pub fn decimal_places(mut self, decimal_places: u8) -> Self {
47 self.part
48 .set_attr("number:decimal-places", decimal_places.to_string());
49 self
50 }
51
52 /// Sets decimal_places and min_decimal_places to the same value,
53 /// which in effect always displays the same number of decimals.
54 #[must_use]
55 pub fn fixed_decimal_places(mut self, decimal_places: u8) -> Self {
56 self.part
57 .set_attr("number:decimal-places", decimal_places.to_string());
58 self.part
59 .set_attr("number:min-decimal-places", decimal_places.to_string());
60 self
61 }
62
63 /// The number:grouping attribute specifies whether the integer digits of a number should be
64 /// grouped using a separator character.
65 /// The grouping character that is used and the number of digits that are grouped together depends
66 /// on the language and country of the style.
67 ///
68 /// The defined values for the number:grouping attribute are:
69 /// * false: integer digits of a number are not grouped using a separator character.
70 /// * true: integer digits of a number should be grouped by a separator character.
71 /// The default value for this attribute is false.
72 #[must_use]
73 pub fn grouping(mut self) -> Self {
74 self.part.set_attr("number:grouping", String::from("true"));
75 self
76 }
77
78 /// The number:min-decimal-places attribute specifies the minimum number of digits in the
79 /// decimal part.
80 /// The value of the number:min-decimal-places attribute shall not be greater than the value of
81 /// the number:decimal-places 19.343 attribute.
82 /// If the value of number:min-decimal-places is less than the value of number:decimalplaces, trailing zero digits in decimal places following the position indicated by the value of
83 /// number:min-decimal-places shall not be displayed.
84 #[must_use]
85 pub fn min_decimal_places(mut self, min_decimal_places: u8) -> Self {
86 self.part
87 .set_attr("number:min-decimal-places", min_decimal_places.to_string());
88 self
89 }
90
91 /// The number:min-integer-digits attribute specifies the minimum number of integer digits to
92 /// display in the integer portion of a number, a scientific number, or a fraction.
93 /// For a number:fraction element, if the number:min-integer-digits attribute is not
94 /// present, no integer portion is displayed.
95 #[must_use]
96 pub fn min_integer_digits(mut self, mininteger_digits: u8) -> Self {
97 self.part
98 .set_attr("number:min-integer-digits", mininteger_digits.to_string());
99 self
100 }
101
102 /// The number:display-factor attribute specifies a factor by which each number is scaled
103 /// (divided) before displaying.
104 /// The default value for this attribute is 1
105 #[must_use]
106 pub fn display_factor(mut self, display_factor: f64) -> Self {
107 self.part
108 .set_attr("number:display-factor", display_factor.to_string());
109 self
110 }
111
112 /// The number:decimal-replacement attribute specifies a replacement text for decimal places if
113 /// a number style specifies that decimal places are used but the number displayed is an integer.
114 /// Note: What replacement text is supported is implementation-dependent
115 #[must_use]
116 pub fn decimal_replacement(mut self, decimal_replacement: char) -> Self {
117 self.part.set_attr(
118 "number:decimal-replacement",
119 decimal_replacement.to_string(),
120 );
121 self
122 }
123
124 /// The number:embedded-text element specifies text that is displayed at one specific position
125 /// within a number.
126 ///
127 /// The number:embedded-text element is usable within the following element:
128 /// * number:number 16.29.3.
129 ///
130 /// The number:embedded-text element has the following attribute:
131 /// * number:position 19.358.
132 ///
133 /// The number:position attribute specifies the position where text appears.
134 /// The index of a position starts with 1 and is counted by digits from right to left in the integer part of
135 /// a number, starting left from a decimal separator if one exists, or from the last digit of the number.
136 /// Text is inserted before the digit at the specified position. If the value of number:position
137 /// attribute is greater than the value of number:min-integer-digits 19.355 and greater than
138 /// the number of integer digits in the number, text is prepended to the number.
139 ///
140 /// The number:embedded-text element has no child elements.
141 /// The number:embedded-text element has character data content
142 #[must_use]
143 pub fn embedded_text<S: Into<String>>(mut self, text: S, pos: i32) -> Self {
144 self.part.position = Some(pos);
145 self.part.content = Some(text.into());
146 self
147 }
148}
149
150/// Builder for FormatPart with type Number.
151#[derive(Debug)]
152pub struct PartFillCharacterBuilder<'vf, T: ValueFormatTrait> {
153 part: FormatPart,
154 valueformat: &'vf mut T,
155}
156
157impl<'vf, T: ValueFormatTrait> PartFillCharacterBuilder<'vf, T> {
158 /// New builder for the valueformat.
159 pub fn new<'a>(valueformat: &'a mut T) -> Self
160 where
161 'a: 'vf,
162 {
163 Self {
164 part: FormatPart::new(FormatPartType::FillCharacter),
165 valueformat,
166 }
167 }
168
169 /// Appends the constructed FormatPart to the original value format.
170 pub fn build(self) {
171 self.valueformat.push_part(self.part);
172 }
173
174 /// Only applies the builder if the test is true.
175 #[must_use]
176 pub fn if_then<F>(self, test: bool, build: F) -> Self
177 where
178 F: Fn(Self) -> Self,
179 {
180 if test {
181 build(self)
182 } else {
183 self
184 }
185 }
186
187 /// If the number:decimal-places attribute is not specified, the number of decimal places
188 /// specified by the default table cell style is used.
189 #[must_use]
190 pub fn fill_char(mut self, c: char) -> Self {
191 self.part.set_content(c.to_string());
192 self
193 }
194}
195
196/// Builder for FormatPart with type ScientificNumber.
197///
198/// The number:scientific-number element specifies the display formatting properties for a
199/// number style that should be displayed in scientific format.
200///
201/// The number:scientific-number element is usable within the following element:
202/// * number:number-style 16.27.2.
203///
204/// The number:scientific-number element has the following attributes:
205/// * number:decimal-places 19.343.4,
206/// * number:grouping 19.348,
207/// * number:min-exponentdigits 19.351 and
208/// * number:min-integer-digits 19.352.
209///
210/// The number:scientific-number element has no child elements.
211#[derive(Debug)]
212pub struct PartScientificBuilder<'vf, T: ValueFormatTrait> {
213 part: FormatPart,
214 valueformat: &'vf mut T,
215}
216
217impl<'vf, T: ValueFormatTrait> PartScientificBuilder<'vf, T> {
218 /// New builder for the valueformat.
219 pub fn new<'a>(valueformat: &'a mut T) -> Self
220 where
221 'a: 'vf,
222 {
223 Self {
224 part: FormatPart::new(FormatPartType::ScientificNumber),
225 valueformat,
226 }
227 }
228
229 /// Appends the constructed FormatPart to the original value format.
230 pub fn build(self) {
231 self.valueformat.push_part(self.part);
232 }
233
234 /// Only applies the builder if the test is true.
235 #[must_use]
236 pub fn if_then<F>(self, test: bool, build: F) -> Self
237 where
238 F: Fn(Self) -> Self,
239 {
240 if test {
241 build(self)
242 } else {
243 self
244 }
245 }
246
247 /// If the number:decimal-places attribute is not specified, the number of decimal places
248 /// specified by the default table cell style is used.
249 #[must_use]
250 pub fn decimal_places(mut self, v: u8) -> Self {
251 self.part.set_attr("number:decimal-places", v.to_string());
252 self
253 }
254
255 /// The number:exponent-interval attribute determines the valid exponents to be used: the
256 /// valid exponents are the integer multiples of the value of the number:exponent-interval
257 /// attribute.
258 /// The default value for this attribute is 1.
259 #[must_use]
260 pub fn expontent_interval(mut self, v: u8) -> Self {
261 self.part
262 .set_attr("number:exponent-interval", v.to_string());
263 self
264 }
265
266 /// The number:forced-exponent-sign attribute specifies whether the sign of the exponent for a
267 /// scientific number is always displayed.
268 ///
269 /// The defined values for the number:forced-exponent-sign attribute are:
270 /// * false: the exponent sign is displayed only for a negative value of the exponent, otherwise it
271 /// is not displayed.
272 /// * true: the exponent sign is always displayed regardless of the value of exponent.
273 /// The default value for this attribute is true.
274 #[must_use]
275 pub fn forced_exponent_sign(mut self, v: bool) -> Self {
276 self.part
277 .set_attr("number:forced-exponent-sign", v.to_string());
278 self
279 }
280
281 /// The number:grouping attribute specifies whether the integer digits of a number should be
282 /// grouped using a separator character.
283 /// The grouping character that is used and the number of digits that are grouped together depends
284 /// on the language and country of the style.
285 ///
286 /// The defined values for the number:grouping attribute are:
287 /// * false: integer digits of a number are not grouped using a separator character.
288 /// * true: integer digits of a number should be grouped by a separator character.
289 /// The default value for this attribute is false.
290 #[must_use]
291 pub fn grouping(mut self) -> Self {
292 self.part.set_attr("number:grouping", String::from("true"));
293 self
294 }
295
296 /// The number:min-decimal-places attribute specifies the minimum number of digits in the
297 /// decimal part.
298 /// The value of the number:min-decimal-places attribute shall not be greater than the value of
299 /// the number:decimal-places 19.343 attribute.
300 /// If the value of number:min-decimal-places is less than the value of number:decimalplaces, trailing zero digits in decimal places following the position indicated by the value of
301 /// number:min-decimal-places shall not be displayed.
302 #[must_use]
303 pub fn min_decimal_places(mut self, v: u8) -> Self {
304 self.part
305 .set_attr("number:min-decimal-places", v.to_string());
306 self
307 }
308
309 /// The number:min-exponent-digits attribute specifies the minimum number of digits to use to
310 /// display an exponent.
311 #[must_use]
312 pub fn min_exponent_digits(mut self, v: u8) -> Self {
313 self.part
314 .set_attr("number:min-exponent-digits", v.to_string());
315 self
316 }
317
318 /// The number:min-integer-digits attribute specifies the minimum number of integer digits to
319 /// display in the integer portion of a number, a scientific number, or a fraction.
320 /// For a number:fraction element, if the number:min-integer-digits attribute is not
321 /// present, no integer portion is displayed.
322 #[must_use]
323 pub fn min_integer_digits(mut self, v: u8) -> Self {
324 self.part
325 .set_attr("number:min-integer-digits", v.to_string());
326 self
327 }
328}
329
330/// The number:fraction element specifies the display formatting properties for a number style
331/// that should be displayed as a fraction.
332///
333/// The number:fraction element is usable within the following element:
334/// * number:numberstyle 16.29.2.
335///
336/// The number:fraction element has the following attributes:
337/// * number:denominatorvalue 19.345,
338/// * number:grouping 19.350,
339/// * number:max-denominator-value 19.352,
340/// * number:min-denominator-digits 19.353,
341/// * number:min-integer-digits 19.355 and
342/// * number:min-numerator-digits 19.357.
343///
344/// The number:fraction element has no child elements.
345#[derive(Debug)]
346pub struct PartFractionBuilder<'vf, T: ValueFormatTrait> {
347 part: FormatPart,
348 valueformat: &'vf mut T,
349}
350
351impl<'vf, T: ValueFormatTrait> PartFractionBuilder<'vf, T> {
352 /// New builder for the valueformat.
353 pub fn new<'a>(valueformat: &'a mut T) -> Self
354 where
355 'a: 'vf,
356 {
357 Self {
358 part: FormatPart::new(FormatPartType::Fraction),
359 valueformat,
360 }
361 }
362
363 /// Appends the constructed FormatPart to the original value format.
364 pub fn build(self) {
365 self.valueformat.push_part(self.part);
366 }
367
368 /// Only applies the builder if the test is true.
369 #[must_use]
370 pub fn if_then<F>(self, test: bool, build: F) -> Self
371 where
372 F: Fn(Self) -> Self,
373 {
374 if test {
375 build(self)
376 } else {
377 self
378 }
379 }
380
381 /// The number:denominator-value attribute specifies an integer value that is used as the
382 /// denominator of a fraction. If this attribute is not present, a denominator that is appropriate for
383 /// displaying the number is used.
384 #[must_use]
385 pub fn denominator(mut self, v: i64) -> Self {
386 self.part
387 .set_attr("number:denominator-value", v.to_string());
388 self
389 }
390
391 /// The number:grouping attribute specifies whether the integer digits of a number should be
392 /// grouped using a separator character.
393 /// The grouping character that is used and the number of digits that are grouped together depends
394 /// on the language and country of the style.
395 ///
396 /// The defined values for the number:grouping attribute are:
397 /// * false: integer digits of a number are not grouped using a separator character.
398 /// * true: integer digits of a number should be grouped by a separator character.
399 /// The default value for this attribute is false.
400 #[must_use]
401 pub fn grouping(mut self) -> Self {
402 self.part.set_attr("number:grouping", String::from("true"));
403 self
404 }
405
406 /// The number:max-denominator-value attribute specifies the maximum
407 /// denominator permitted to be chosen if its number:fraction element does not
408 /// have a number:denominator-value attribute. The number:max-denominator-value
409 /// attribute is ignored in the presence of a number:denominator-value 19.345
410 /// attribute. The absence of the number:max-denominator-value attribute indicates
411 /// that no maximum denominator is specified.
412 #[must_use]
413 pub fn max_denominator(mut self, v: i64) -> Self {
414 self.part
415 .set_attr("number:max-denominator-value", v.to_string());
416 self
417 }
418
419 /// The number:min-denominator-digits attribute specifies the minimum number of digits to
420 /// use to display the denominator of a fraction.
421 #[must_use]
422 pub fn min_denominator_digits(mut self, v: u8) -> Self {
423 self.part
424 .set_attr("number:min-denominator-digits", v.to_string());
425 self
426 }
427
428 /// The number:min-integer-digits attribute specifies the minimum number of integer digits to
429 /// display in the integer portion of a number, a scientific number, or a fraction.
430 /// For a number:fraction element, if the number:min-integer-digits attribute is not
431 /// present, no integer portion is displayed.
432 #[must_use]
433 pub fn min_integer_digits(mut self, v: u8) -> Self {
434 self.part
435 .set_attr("number:min-numerator-digits", v.to_string());
436 self
437 }
438
439 /// The number:min-numerator-digits attribute specifies the minimum number of digits to use
440 /// to display the numerator in a fraction.
441 #[must_use]
442 pub fn min_numerator_digits(mut self, v: u8) -> Self {
443 self.part
444 .set_attr("number:min-numerator-digits", v.to_string());
445 self
446 }
447}
448
449/// The number:currency-symbol element specifies whether a currency symbol is displayed in
450/// a currency style.
451/// The content of this element is the text that is displayed as the currency symbol.
452/// If the element is empty or contains white space characters only, the default currency
453/// symbol for the currency style or the language and country of the currency style is displayed.
454///
455/// The number:currency-symbol element is usable within the following element:
456/// * number:currency-style 16.27.7.
457///
458/// The number:currency-symbol element has the following attributes:
459/// * number:country 19.342,
460/// * number:language 19.349,
461/// * number:rfc-language-tag 19.356 and
462/// * number:script 19.357.
463///
464/// The number:currency-symbol element has no child elements.
465/// The number:currency-symbol element has character data content.
466#[derive(Debug)]
467pub struct PartCurrencySymbolBuilder<'vf, T: ValueFormatTrait> {
468 part: FormatPart,
469 valueformat: &'vf mut T,
470}
471
472impl<'vf, T: ValueFormatTrait> PartCurrencySymbolBuilder<'vf, T> {
473 /// New builder for the valueformat.
474 pub fn new<'a>(valueformat: &'a mut T) -> Self
475 where
476 'a: 'vf,
477 {
478 Self {
479 part: FormatPart::new(FormatPartType::CurrencySymbol),
480 valueformat,
481 }
482 }
483
484 /// Appends the constructed FormatPart to the original value format.
485 pub fn build(self) {
486 self.valueformat.push_part(self.part);
487 }
488
489 /// Only applies the builder if the test is true.
490 #[must_use]
491 pub fn if_then<F>(self, test: bool, build: F) -> Self
492 where
493 F: Fn(Self) -> Self,
494 {
495 if test {
496 build(self)
497 } else {
498 self
499 }
500 }
501
502 /// The number:language attribute specifies a language code. The country code is used for
503 /// formatting properties whose evaluation is locale-dependent.
504 /// If a language code is not specified, either the system settings or the setting for the system's
505 /// language are used, depending on the property whose value should be evaluated.
506 ///
507 /// The number:country attribute specifies a country code for a data style. The country code is
508 /// used for formatting properties whose evaluation is locale-dependent.
509 /// If a country is not specified, the system settings are used.
510 /// The number:country attribute on a number:currency-symbol element, specifies the
511 /// country of a currency symbol.
512 ///
513 /// The number:script attribute specifies a script code. The script code is used for formatting
514 /// properties whose evaluation is locale-dependent. The attribute should be used only if necessary
515 /// according to the rules of §2.2.3 of [RFC5646](https://datatracker.ietf.org/doc/html/rfc5646), or its successors.
516 #[must_use]
517 pub fn locale(mut self, v: Locale) -> Self {
518 self.part
519 .set_attr("number:language", v.id.language.to_string());
520 if let Some(region) = v.id.region {
521 self.part.set_attr("number:country", region.to_string());
522 }
523 if let Some(script) = v.id.script {
524 self.part.set_attr("number:script", script.to_string());
525 }
526 self
527 }
528
529 /// Symbol text that is used for the currency symbol. If not set
530 /// the default according to the country is used.
531 #[must_use]
532 pub fn symbol<S: Into<String>>(mut self, v: S) -> Self {
533 self.part.set_content(v.into());
534 self
535 }
536}
537
538/// The number:day element specifies a day of a month in a date.
539///
540/// The number:day element is usable within the following element:
541/// * number:date-style 16.27.10.
542///
543/// The number:day element has the following attributes:
544/// * number:calendar 19.341 and
545/// * number:style 19.358.2.
546///
547/// The number:day element has no child elements.
548#[derive(Debug)]
549pub struct PartDayBuilder<'vf, T: ValueFormatTrait> {
550 part: FormatPart,
551 valueformat: &'vf mut T,
552}
553
554impl<'vf, T: ValueFormatTrait> PartDayBuilder<'vf, T> {
555 /// New builder for the valueformat.
556 pub fn new<'a>(valueformat: &'a mut T) -> Self
557 where
558 'a: 'vf,
559 {
560 Self {
561 part: FormatPart::new(FormatPartType::Day),
562 valueformat,
563 }
564 }
565
566 /// Appends the constructed FormatPart to the original value format.
567 pub fn build(self) {
568 self.valueformat.push_part(self.part);
569 }
570
571 /// Only applies the builder if the test is true.
572 #[must_use]
573 pub fn if_then<F>(self, test: bool, build: F) -> Self
574 where
575 F: Fn(Self) -> Self,
576 {
577 if test {
578 build(self)
579 } else {
580 self
581 }
582 }
583
584 /// The number:style attribute specifies whether the content of a time element is displayed in short
585 /// or long format. The value of this attribute can be short or long. The meaning of these values
586 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
587 /// or time style.
588 #[must_use]
589 pub fn long_style(mut self) -> Self {
590 self.part.set_attr("number:style", "long".to_string());
591 self
592 }
593
594 /// The number:style attribute specifies whether the content of a time element is displayed in short
595 /// or long format. The value of this attribute can be short or long. The meaning of these values
596 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
597 /// or time style.
598 #[must_use]
599 pub fn short_style(mut self) -> Self {
600 self.part.set_attr("number:style", "short".to_string());
601 self
602 }
603
604 /// The number:style attribute specifies whether the content of a time element is displayed in short
605 /// or long format. The value of this attribute can be short or long. The meaning of these values
606 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
607 /// or time style.
608 #[must_use]
609 pub fn style(mut self, style: FormatNumberStyle) -> Self {
610 self.part.set_attr("number:style", style.to_string());
611 self
612 }
613
614 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
615 ///
616 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
617 /// system for the locale of the data style is used.
618 #[must_use]
619 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
620 self.part.set_attr("number:calendar", calendar.to_string());
621 self
622 }
623}
624
625/// Builder for FormatPart with type Month.
626///
627/// The number:month element specifies a month in a date.
628///
629/// The number:month element is usable within the following element:
630/// * number:date-style 16.27.10.
631///
632/// The number:month element has the following attributes:
633/// number:calendar 19.341,
634/// number:possessive-form 19.355,
635/// number:style 19.358.7 and
636/// number:textual 19.359.
637///
638/// The number:month element has no child elements
639#[derive(Debug)]
640pub struct PartMonthBuilder<'vf, T: ValueFormatTrait> {
641 part: FormatPart,
642 valueformat: &'vf mut T,
643}
644
645impl<'vf, T: ValueFormatTrait> PartMonthBuilder<'vf, T> {
646 /// New builder for the valueformat.
647 pub fn new<'a>(valueformat: &'a mut T) -> Self
648 where
649 'a: 'vf,
650 {
651 Self {
652 part: FormatPart::new(FormatPartType::Month),
653 valueformat,
654 }
655 }
656
657 /// Appends the constructed FormatPart to the original value format.
658 pub fn build(self) {
659 self.valueformat.push_part(self.part);
660 }
661
662 /// Only applies the builder if the test is true.
663 #[must_use]
664 pub fn if_then<F>(self, test: bool, build: F) -> Self
665 where
666 F: Fn(Self) -> Self,
667 {
668 if test {
669 build(self)
670 } else {
671 self
672 }
673 }
674
675 /// The number:style attribute specifies whether the content of a time element is displayed in short
676 /// or long format. The value of this attribute can be short or long. The meaning of these values
677 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
678 /// or time style.
679 #[must_use]
680 pub fn long_style(mut self) -> Self {
681 self.part.set_attr("number:style", "long".to_string());
682 self
683 }
684
685 /// The number:style attribute specifies whether the content of a time element is displayed in short
686 /// or long format. The value of this attribute can be short or long. The meaning of these values
687 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
688 /// or time style.
689 #[must_use]
690 pub fn short_style(mut self) -> Self {
691 self.part.set_attr("number:style", "short".to_string());
692 self
693 }
694
695 /// The number:style attribute specifies whether the content of a time element is displayed in short
696 /// or long format. The value of this attribute can be short or long. The meaning of these values
697 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
698 /// or time style.
699 #[must_use]
700 pub fn style(mut self, style: FormatNumberStyle) -> Self {
701 self.part.set_attr("number:style", style.to_string());
702 self
703 }
704
705 /// The number:textual attribute specifies whether the name or number of a month is displayed in
706 /// the month portion of a date.
707 ///
708 /// The defined values for the number:textual element are:
709 /// * false: the number of the month is displayed.
710 /// * true: the name of the month is displayed.
711 ///
712 /// The name or number of a month is defined by the number:calendar 19.341 attribute on the
713 /// same parent element as the number:textual attribute.
714 /// The default value for this attribute is false.
715 #[must_use]
716 pub fn textual(mut self) -> Self {
717 self.part.set_attr("number:textual", true.to_string());
718 self
719 }
720
721 /// The number:possessive-form attribute specifies whether the month is displayed as a noun or
722 /// using the possessive form.
723 /// The number:possessive-form attribute is only applied when a number:textual 19.363
724 /// attribute on the same number:month element has the value of true.
725 ///
726 /// The defined values for the number:possessive-form attribute are:
727 /// * false: the name of the month is displayed in nominative form.
728 /// * true: the name of the month is displayed in possessive form.
729 #[must_use]
730 pub fn possessive_form(mut self) -> Self {
731 self.part
732 .set_attr("number:possessive-form", true.to_string());
733 self
734 }
735
736 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
737 ///
738 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
739 /// system for the locale of the data style is used.
740 #[must_use]
741 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
742 self.part.set_attr("number:calendar", calendar.to_string());
743 self
744 }
745}
746
747/// The number:year element specifies a year in a date.
748/// The number:year element is usable within the following element:
749/// * number:date-style 16.27.10.
750///
751/// The number:year element has the following attributes:
752/// * number:calendar 19.341 and
753/// * number:style 19.358.10.
754///
755/// The number:year element has no child elements.
756#[derive(Debug)]
757pub struct PartYearBuilder<'vf, T: ValueFormatTrait> {
758 part: FormatPart,
759 valueformat: &'vf mut T,
760}
761
762impl<'vf, T: ValueFormatTrait> PartYearBuilder<'vf, T> {
763 /// New builder for the valueformat.
764 pub fn new<'a>(valueformat: &'a mut T) -> Self
765 where
766 'a: 'vf,
767 {
768 Self {
769 part: FormatPart::new(FormatPartType::Year),
770 valueformat,
771 }
772 }
773
774 /// Appends the constructed FormatPart to the original value format.
775 pub fn build(self) {
776 self.valueformat.push_part(self.part);
777 }
778
779 /// Only applies the builder if the test is true.
780 #[must_use]
781 pub fn if_then<F>(self, test: bool, build: F) -> Self
782 where
783 F: Fn(Self) -> Self,
784 {
785 if test {
786 build(self)
787 } else {
788 self
789 }
790 }
791
792 /// The number:style attribute specifies whether the content of a time element is displayed in short
793 /// or long format. The value of this attribute can be short or long. The meaning of these values
794 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
795 /// or time style.
796 #[must_use]
797 pub fn long_style(mut self) -> Self {
798 self.part.set_attr("number:style", "long".to_string());
799 self
800 }
801
802 /// The number:style attribute specifies whether the content of a time element is displayed in short
803 /// or long format. The value of this attribute can be short or long. The meaning of these values
804 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
805 /// or time style.
806 #[must_use]
807 pub fn short_style(mut self) -> Self {
808 self.part.set_attr("number:style", "short".to_string());
809 self
810 }
811
812 /// The number:style attribute specifies whether the content of a time element is displayed in short
813 /// or long format. The value of this attribute can be short or long. The meaning of these values
814 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
815 /// or time style.
816 #[must_use]
817 pub fn style(mut self, style: FormatNumberStyle) -> Self {
818 self.part.set_attr("number:style", style.to_string());
819 self
820 }
821
822 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
823 ///
824 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
825 /// system for the locale of the data style is used.
826 #[must_use]
827 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
828 self.part.set_attr("number:calendar", calendar.to_string());
829 self
830 }
831}
832
833/// The number:era element specifies an era in which a year is counted.
834///
835/// The number:era element is usable within the following element:
836/// * number:date-style 16.27.10.
837///
838/// The number:era element has the following attributes:
839/// * number:calendar 19.341 and
840/// * number:style 19.358.4.
841///
842/// The number:era element has no child elements
843#[derive(Debug)]
844pub struct PartEraBuilder<'vf, T: ValueFormatTrait> {
845 part: FormatPart,
846 valueformat: &'vf mut T,
847}
848
849impl<'vf, T: ValueFormatTrait> PartEraBuilder<'vf, T> {
850 /// New builder for the valueformat.
851 pub fn new<'a>(valueformat: &'a mut T) -> Self
852 where
853 'a: 'vf,
854 {
855 Self {
856 part: FormatPart::new(FormatPartType::Era),
857 valueformat,
858 }
859 }
860
861 /// Appends the constructed FormatPart to the original value format.
862 pub fn build(self) {
863 self.valueformat.push_part(self.part);
864 }
865
866 /// Only applies the builder if the test is true.
867 #[must_use]
868 pub fn if_then<F>(self, test: bool, build: F) -> Self
869 where
870 F: Fn(Self) -> Self,
871 {
872 if test {
873 build(self)
874 } else {
875 self
876 }
877 }
878
879 /// The number:style attribute specifies whether the content of a time element is displayed in short
880 /// or long format. The value of this attribute can be short or long. The meaning of these values
881 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
882 /// or time style.
883 #[must_use]
884 pub fn long_style(mut self) -> Self {
885 self.part.set_attr("number:style", "long".to_string());
886 self
887 }
888
889 /// The number:style attribute specifies whether the content of a time element is displayed in short
890 /// or long format. The value of this attribute can be short or long. The meaning of these values
891 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
892 /// or time style.
893 #[must_use]
894 pub fn short_style(mut self) -> Self {
895 self.part.set_attr("number:style", "short".to_string());
896 self
897 }
898
899 /// The number:style attribute specifies whether the content of a time element is displayed in short
900 /// or long format. The value of this attribute can be short or long. The meaning of these values
901 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
902 /// or time style.
903 #[must_use]
904 pub fn style(mut self, style: FormatNumberStyle) -> Self {
905 self.part.set_attr("number:style", style.to_string());
906 self
907 }
908
909 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
910 ///
911 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
912 /// system for the locale of the data style is used.
913 #[must_use]
914 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
915 self.part.set_attr("number:calendar", calendar.to_string());
916 self
917 }
918}
919
920/// The number:day-of-week element specifies a day of a week in a date.
921///
922/// The number:day-of-week element is usable within the following element:
923/// * number:datestyle 16.27.10.
924///
925/// The number:day-of-week element has the following attributes:
926/// * number:calendar 19.341 and
927/// * number:style 19.358.3.
928///
929/// The number:day-of-week element has no child elements.
930#[derive(Debug)]
931pub struct PartDayOfWeekBuilder<'vf, T: ValueFormatTrait> {
932 part: FormatPart,
933 valueformat: &'vf mut T,
934}
935
936impl<'vf, T: ValueFormatTrait> PartDayOfWeekBuilder<'vf, T> {
937 /// New builder for the valueformat.
938 pub fn new<'a>(valueformat: &'a mut T) -> Self
939 where
940 'a: 'vf,
941 {
942 Self {
943 part: FormatPart::new(FormatPartType::DayOfWeek),
944 valueformat,
945 }
946 }
947
948 /// Appends the constructed FormatPart to the original value format.
949 pub fn build(self) {
950 self.valueformat.push_part(self.part);
951 }
952
953 /// Only applies the builder if the test is true.
954 #[must_use]
955 pub fn if_then<F>(self, test: bool, build: F) -> Self
956 where
957 F: Fn(Self) -> Self,
958 {
959 if test {
960 build(self)
961 } else {
962 self
963 }
964 }
965
966 /// The number:style attribute specifies whether the content of a time element is displayed in short
967 /// or long format. The value of this attribute can be short or long. The meaning of these values
968 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
969 /// or time style.
970 #[must_use]
971 pub fn long_style(mut self) -> Self {
972 self.part.set_attr("number:style", "long".to_string());
973 self
974 }
975
976 /// The number:style attribute specifies whether the content of a time element is displayed in short
977 /// or long format. The value of this attribute can be short or long. The meaning of these values
978 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
979 /// or time style.
980 #[must_use]
981 pub fn short_style(mut self) -> Self {
982 self.part.set_attr("number:style", "short".to_string());
983 self
984 }
985
986 /// The number:style attribute specifies whether the content of a time element is displayed in short
987 /// or long format. The value of this attribute can be short or long. The meaning of these values
988 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
989 /// or time style.
990 #[must_use]
991 pub fn style(mut self, style: FormatNumberStyle) -> Self {
992 self.part.set_attr("number:style", style.to_string());
993 self
994 }
995
996 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
997 ///
998 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
999 /// system for the locale of the data style is used.
1000 #[must_use]
1001 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
1002 self.part.set_attr("number:calendar", calendar.to_string());
1003 self
1004 }
1005}
1006
1007/// The number:week-of-year element specifies a week of a year in a date.
1008///
1009/// The number:week-of-year element is usable within the following element:
1010/// * number:date-style 16.27.10.
1011///
1012/// The number:week-of-year element has the following attribute:
1013/// * number:calendar 19.341.
1014///
1015/// The number:week-of-year element has no child elements.
1016#[derive(Debug)]
1017pub struct PartWeekOfYearBuilder<'vf, T: ValueFormatTrait> {
1018 part: FormatPart,
1019 valueformat: &'vf mut T,
1020}
1021
1022impl<'vf, T: ValueFormatTrait> PartWeekOfYearBuilder<'vf, T> {
1023 /// New builder for the valueformat.
1024 pub fn new<'a>(valueformat: &'a mut T) -> Self
1025 where
1026 'a: 'vf,
1027 {
1028 Self {
1029 part: FormatPart::new(FormatPartType::WeekOfYear),
1030 valueformat,
1031 }
1032 }
1033
1034 /// Appends the constructed FormatPart to the original value format.
1035 pub fn build(self) {
1036 self.valueformat.push_part(self.part);
1037 }
1038
1039 /// Only applies the builder if the test is true.
1040 #[must_use]
1041 pub fn if_then<F>(self, test: bool, build: F) -> Self
1042 where
1043 F: Fn(Self) -> Self,
1044 {
1045 if test {
1046 build(self)
1047 } else {
1048 self
1049 }
1050 }
1051
1052 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
1053 ///
1054 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
1055 /// system for the locale of the data style is used.
1056 #[must_use]
1057 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
1058 self.part.set_attr("number:calendar", calendar.to_string());
1059 self
1060 }
1061}
1062
1063/// The number:quarter element specifies a quarter of the year in a date.
1064///
1065/// The number:quarter element is usable within the following element:
1066/// * number:datestyle 16.27.10.
1067///
1068/// The number:quarter element has the following attributes:
1069/// * number:calendar 19.341 and
1070/// * number:style 19.358.8.
1071///
1072/// The number:quarter element has no child elements
1073#[derive(Debug)]
1074pub struct PartQuarterBuilder<'vf, T: ValueFormatTrait> {
1075 part: FormatPart,
1076 valueformat: &'vf mut T,
1077}
1078
1079impl<'vf, T: ValueFormatTrait> PartQuarterBuilder<'vf, T> {
1080 /// New builder for the valueformat.
1081 pub fn new<'a>(valueformat: &'a mut T) -> Self
1082 where
1083 'a: 'vf,
1084 {
1085 Self {
1086 part: FormatPart::new(FormatPartType::Quarter),
1087 valueformat,
1088 }
1089 }
1090
1091 /// Appends the constructed FormatPart to the original value format.
1092 pub fn build(self) {
1093 self.valueformat.push_part(self.part);
1094 }
1095
1096 /// Only applies the builder if the test is true.
1097 #[must_use]
1098 pub fn if_then<F>(self, test: bool, build: F) -> Self
1099 where
1100 F: Fn(Self) -> Self,
1101 {
1102 if test {
1103 build(self)
1104 } else {
1105 self
1106 }
1107 }
1108
1109 /// The number:style attribute specifies whether the content of a time element is displayed in short
1110 /// or long format. The value of this attribute can be short or long. The meaning of these values
1111 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1112 /// or time style.
1113 #[must_use]
1114 pub fn long_style(mut self) -> Self {
1115 self.part.set_attr("number:style", "long".to_string());
1116 self
1117 }
1118
1119 /// The number:style attribute specifies whether the content of a time element is displayed in short
1120 /// or long format. The value of this attribute can be short or long. The meaning of these values
1121 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1122 /// or time style.
1123 #[must_use]
1124 pub fn short_style(mut self) -> Self {
1125 self.part.set_attr("number:style", "short".to_string());
1126 self
1127 }
1128
1129 /// The number:style attribute specifies whether the content of a time element is displayed in short
1130 /// or long format. The value of this attribute can be short or long. The meaning of these values
1131 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1132 /// or time style.
1133 #[must_use]
1134 pub fn style(mut self, style: FormatNumberStyle) -> Self {
1135 self.part.set_attr("number:style", style.to_string());
1136 self
1137 }
1138
1139 /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
1140 ///
1141 /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
1142 /// system for the locale of the data style is used.
1143 #[must_use]
1144 pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
1145 self.part.set_attr("number:calendar", calendar.to_string());
1146 self
1147 }
1148}
1149
1150/// The number:hours element specifies whether hours are displayed as part of a date or time.
1151///
1152/// The number:hours element is usable within the following elements:
1153/// * number:datestyle 16.27.10 and
1154/// * number:time-style 16.27.18.
1155///
1156/// The number:hours element has the following attribute:
1157/// * number:style 19.358.5.
1158///
1159/// The number:hours element has no child elements.
1160#[derive(Debug)]
1161pub struct PartHoursBuilder<'vf, T: ValueFormatTrait> {
1162 part: FormatPart,
1163 valueformat: &'vf mut T,
1164}
1165
1166impl<'vf, T: ValueFormatTrait> PartHoursBuilder<'vf, T> {
1167 /// New builder for the valueformat.
1168 pub fn new<'a>(valueformat: &'a mut T) -> Self
1169 where
1170 'a: 'vf,
1171 {
1172 Self {
1173 part: FormatPart::new(FormatPartType::Hours),
1174 valueformat,
1175 }
1176 }
1177
1178 /// Appends the constructed FormatPart to the original value format.
1179 pub fn build(self) {
1180 self.valueformat.push_part(self.part);
1181 }
1182
1183 /// Only applies the builder if the test is true.
1184 #[must_use]
1185 pub fn if_then<F>(self, test: bool, build: F) -> Self
1186 where
1187 F: Fn(Self) -> Self,
1188 {
1189 if test {
1190 build(self)
1191 } else {
1192 self
1193 }
1194 }
1195
1196 /// The number:style attribute specifies whether the content of a time element is displayed in short
1197 /// or long format. The value of this attribute can be short or long. The meaning of these values
1198 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1199 /// or time style.
1200 #[must_use]
1201 pub fn long_style(mut self) -> Self {
1202 self.part.set_attr("number:style", "long".to_string());
1203 self
1204 }
1205
1206 /// The number:style attribute specifies whether the content of a time element is displayed in short
1207 /// or long format. The value of this attribute can be short or long. The meaning of these values
1208 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1209 /// or time style.
1210 #[must_use]
1211 pub fn short_style(mut self) -> Self {
1212 self.part.set_attr("number:style", "short".to_string());
1213 self
1214 }
1215
1216 /// The number:style attribute specifies whether the content of a time element is displayed in short
1217 /// or long format. The value of this attribute can be short or long. The meaning of these values
1218 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1219 /// or time style.
1220 #[must_use]
1221 pub fn style(mut self, style: FormatNumberStyle) -> Self {
1222 self.part.set_attr("number:style", style.to_string());
1223 self
1224 }
1225}
1226
1227/// The number:minutes element specifies whether minutes are displayed as part of a date or
1228/// time.
1229/// The number:minutes element is usable within the following elements:
1230/// * number:datestyle 16.27.10 and
1231/// * number:time-style 16.27.18.
1232///
1233/// The number:minutes element has the following attribute:
1234/// * number:style 19.358.6.
1235///
1236/// The number:minutes element has no child elements.
1237#[derive(Debug)]
1238pub struct PartMinutesBuilder<'vf, T: ValueFormatTrait> {
1239 part: FormatPart,
1240 valueformat: &'vf mut T,
1241}
1242
1243impl<'vf, T: ValueFormatTrait> PartMinutesBuilder<'vf, T> {
1244 /// New builder for the valueformat.
1245 pub fn new<'a>(valueformat: &'a mut T) -> Self
1246 where
1247 'a: 'vf,
1248 {
1249 Self {
1250 part: FormatPart::new(FormatPartType::Minutes),
1251 valueformat,
1252 }
1253 }
1254
1255 /// Appends the constructed FormatPart to the original value format.
1256 pub fn build(self) {
1257 self.valueformat.push_part(self.part);
1258 }
1259
1260 /// Only applies the builder if the test is true.
1261 #[must_use]
1262 pub fn if_then<F>(self, test: bool, build: F) -> Self
1263 where
1264 F: Fn(Self) -> Self,
1265 {
1266 if test {
1267 build(self)
1268 } else {
1269 self
1270 }
1271 }
1272
1273 /// The number:style attribute specifies whether the content of a time element is displayed in short
1274 /// or long format. The value of this attribute can be short or long. The meaning of these values
1275 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1276 /// or time style.
1277 #[must_use]
1278 pub fn long_style(mut self) -> Self {
1279 self.part.set_attr("number:style", "long".to_string());
1280 self
1281 }
1282
1283 /// The number:style attribute specifies whether the content of a time element is displayed in short
1284 /// or long format. The value of this attribute can be short or long. The meaning of these values
1285 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1286 /// or time style.
1287 #[must_use]
1288 pub fn short_style(mut self) -> Self {
1289 self.part.set_attr("number:style", "short".to_string());
1290 self
1291 }
1292
1293 /// The number:style attribute specifies whether the content of a time element is displayed in short
1294 /// or long format. The value of this attribute can be short or long. The meaning of these values
1295 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1296 /// or time style.
1297 #[must_use]
1298 pub fn style(mut self, style: FormatNumberStyle) -> Self {
1299 self.part.set_attr("number:style", style.to_string());
1300 self
1301 }
1302}
1303
1304/// The number:seconds element specifies whether seconds are displayed as part of a date or
1305/// time.
1306///
1307/// The number:seconds element is usable within the following elements:
1308/// * number:datestyle 16.27.10 and
1309/// * number:time-style 16.27.18.
1310///
1311/// The number:seconds element has the following attributes:
1312/// * number:decimal-places 19.343.3 and
1313/// * number:style 19.358.9.
1314///
1315/// The number:seconds element has no child elements.
1316#[derive(Debug)]
1317pub struct PartSecondsBuilder<'vf, T: ValueFormatTrait> {
1318 part: FormatPart,
1319 valueformat: &'vf mut T,
1320}
1321
1322impl<'vf, T: ValueFormatTrait> PartSecondsBuilder<'vf, T> {
1323 /// New builder for the valueformat.
1324 pub fn new<'a>(valueformat: &'a mut T) -> Self
1325 where
1326 'a: 'vf,
1327 {
1328 Self {
1329 part: FormatPart::new(FormatPartType::Seconds),
1330 valueformat,
1331 }
1332 }
1333
1334 /// Appends the constructed FormatPart to the original value format.
1335 pub fn build(self) {
1336 self.valueformat.push_part(self.part);
1337 }
1338
1339 /// Only applies the builder if the test is true.
1340 #[must_use]
1341 pub fn if_then<F>(self, test: bool, build: F) -> Self
1342 where
1343 F: Fn(Self) -> Self,
1344 {
1345 if test {
1346 build(self)
1347 } else {
1348 self
1349 }
1350 }
1351
1352 /// If the number:decimal-places attribute is not specified, the number of decimal places
1353 /// specified by the default table cell style is used.
1354 #[must_use]
1355 pub fn decimal_places(mut self, decimal_places: u8) -> Self {
1356 self.part
1357 .set_attr("number:decimal-places", decimal_places.to_string());
1358 self
1359 }
1360
1361 /// The number:style attribute specifies whether the content of a time element is displayed in short
1362 /// or long format. The value of this attribute can be short or long. The meaning of these values
1363 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1364 /// or time style.
1365 #[must_use]
1366 pub fn long_style(mut self) -> Self {
1367 self.part.set_attr("number:style", "long".to_string());
1368 self
1369 }
1370
1371 /// The number:style attribute specifies whether the content of a time element is displayed in short
1372 /// or long format. The value of this attribute can be short or long. The meaning of these values
1373 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1374 /// or time style.
1375 #[must_use]
1376 pub fn short_style(mut self) -> Self {
1377 self.part.set_attr("number:style", "short".to_string());
1378 self
1379 }
1380
1381 /// The number:style attribute specifies whether the content of a time element is displayed in short
1382 /// or long format. The value of this attribute can be short or long. The meaning of these values
1383 /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1384 /// or time style.
1385 #[must_use]
1386 pub fn style(mut self, style: FormatNumberStyle) -> Self {
1387 self.part.set_attr("number:style", style.to_string());
1388 self
1389 }
1390}
1391
1392/// Adds a format part to this format.
1393///
1394/// The number:am-pm element specifies whether AM/PM is included as part of a date or time.
1395/// If a number:am-pm element is contained in a date or time style, hours are displayed using
1396/// values from 1 to 12 only.
1397///
1398/// Can be used with ValueTypes:
1399/// * DateTime
1400/// * TimeDuration
1401#[derive(Debug)]
1402pub struct PartAmPmBuilder<'vf, T: ValueFormatTrait> {
1403 part: FormatPart,
1404 valueformat: &'vf mut T,
1405}
1406
1407impl<'vf, T: ValueFormatTrait> PartAmPmBuilder<'vf, T> {
1408 /// New builder for the valueformat.
1409 pub fn new<'a>(valueformat: &'a mut T) -> Self
1410 where
1411 'a: 'vf,
1412 {
1413 Self {
1414 part: FormatPart::new(FormatPartType::AmPm),
1415 valueformat,
1416 }
1417 }
1418
1419 /// Appends the constructed FormatPart to the original value format.
1420 pub fn build(self) {
1421 self.valueformat.push_part(self.part);
1422 }
1423}
1424
1425/// Adds a format part to this format.
1426///
1427/// The number:boolean element marks the position of the Boolean value of a Boolean style.
1428///
1429/// Can be used with ValueTypes:
1430/// * Boolean
1431#[derive(Debug)]
1432pub struct PartBooleanBuilder<'vf, T: ValueFormatTrait> {
1433 part: FormatPart,
1434 valueformat: &'vf mut T,
1435}
1436
1437impl<'vf, T: ValueFormatTrait> PartBooleanBuilder<'vf, T> {
1438 /// New builder for the valueformat.
1439 pub fn new<'a>(valueformat: &'a mut T) -> Self
1440 where
1441 'a: 'vf,
1442 {
1443 Self {
1444 part: FormatPart::new(FormatPartType::Boolean),
1445 valueformat,
1446 }
1447 }
1448
1449 /// Appends the constructed FormatPart to the original value format.
1450 pub fn build(self) {
1451 self.valueformat.push_part(self.part);
1452 }
1453}
1454
1455/// Adds a format part to this format.
1456///
1457/// The number:text element contains any fixed text for a data style.
1458///
1459/// Can be used with ValueTypes:
1460/// * Boolean
1461/// * Currency
1462/// * DateTime
1463/// * Number
1464/// * Percentage
1465/// * Text
1466/// * TimeDuration
1467#[derive(Debug)]
1468pub struct PartTextBuilder<'vf, T: ValueFormatTrait> {
1469 part: FormatPart,
1470 valueformat: &'vf mut T,
1471}
1472
1473impl<'vf, T: ValueFormatTrait> PartTextBuilder<'vf, T> {
1474 /// New builder for the valueformat.
1475 pub fn new<'a>(valueformat: &'a mut T) -> Self
1476 where
1477 'a: 'vf,
1478 {
1479 Self {
1480 part: FormatPart::new(FormatPartType::Text),
1481 valueformat,
1482 }
1483 }
1484
1485 /// Appends the constructed FormatPart to the original value format.
1486 pub fn build(self) {
1487 self.valueformat.push_part(self.part);
1488 }
1489
1490 /// Only applies the builder if the test is true.
1491 #[must_use]
1492 pub fn if_then<F>(self, test: bool, build: F) -> Self
1493 where
1494 F: Fn(Self) -> Self,
1495 {
1496 if test {
1497 build(self)
1498 } else {
1499 self
1500 }
1501 }
1502
1503 /// Sets the text value.
1504 #[must_use]
1505 pub fn text<S: Into<String>>(mut self, txt: S) -> Self {
1506 self.part.set_content(txt.into());
1507 self
1508 }
1509}
1510
1511/// Adds a format part to this format.
1512///
1513/// The number:text-content element marks the position of variable text content of a text
1514/// style.
1515///
1516/// Can be used with ValueTypes:
1517/// * Text
1518
1519#[derive(Debug)]
1520pub struct PartTextContentBuilder<'vf, T: ValueFormatTrait> {
1521 part: FormatPart,
1522 valueformat: &'vf mut T,
1523}
1524
1525impl<'vf, T: ValueFormatTrait> PartTextContentBuilder<'vf, T> {
1526 /// New builder for the valueformat.
1527 pub fn new<'a>(valueformat: &'a mut T) -> Self
1528 where
1529 'a: 'vf,
1530 {
1531 Self {
1532 part: FormatPart::new(FormatPartType::TextContent),
1533 valueformat,
1534 }
1535 }
1536
1537 /// Appends the constructed FormatPart to the original value format.
1538 pub fn build(self) {
1539 self.valueformat.push_part(self.part);
1540 }
1541}