pub struct FieldSpec { /* private fields */ }Expand description
A form field to create.
The name is the field’s identity: ISO 32000-1 §12.7.3.2 makes the fully
qualified name what an action, an export or a script addresses a field by,
and Form::field is the only lookup the
reader offers. So a name that is already taken is refused rather than
silently merged into the existing field — see Error::DuplicateFieldName.
use kurbo::Rect;
use pdfrum_edit::{FieldKindSpec, FieldSpec};
let spec = FieldSpec::new("email", Rect::new(72.0, 700.0, 300.0, 720.0), FieldKindSpec::Text)
.max_len(64)
.tooltip("Your email address")
.required(true);
assert_eq!(spec.name(), "email");Implementations§
Source§impl FieldSpec
impl FieldSpec
Sourcepub fn new(name: impl Into<String>, rect: Rect, kind: FieldKindSpec) -> Self
pub fn new(name: impl Into<String>, rect: Rect, kind: FieldKindSpec) -> Self
A field of kind named name, drawn in rect in default user space.
For a FieldKindSpec::Radio group rect is the rectangle the field
reports; each button carries its own, so pass the group’s bounding box
or any rectangle — the buttons are what a reader draws.
Sourcepub fn value(self, value: impl Into<String>) -> Self
pub fn value(self, value: impl Into<String>) -> Self
/V: the field’s initial value.
For a text field this is the text. For a check box or a radio group it
is a state name — the on-state of the box, or the export value of
the button to select — and anything else leaves the control clear,
exactly as Off would.
Sourcepub fn default_value(self, value: impl Into<String>) -> Self
pub fn default_value(self, value: impl Into<String>) -> Self
/DV: the value a reset action restores.
Defaults to Self::value when that is set, since a field whose
initial value resets to empty is rarely what an author means.
Sourcepub fn tooltip(self, text: impl Into<String>) -> Self
pub fn tooltip(self, text: impl Into<String>) -> Self
/TU: the tooltip a reader shows, and the accessible name a screen
reader announces.
Sourcepub fn da(self, da: impl Into<String>) -> Self
pub fn da(self, da: impl Into<String>) -> Self
/DA: the appearance string the value is laid out with.
Defaults to DEFAULT_FIELD_DA. A /DA naming a face that is not in
the form’s /DR falls back to a substituted one at draw time rather
than failing, so a caller who embeds a face should name it here and
register it with add_form_font.
Sourcepub fn max_len(self, max: i64) -> Self
pub fn max_len(self, max: i64) -> Self
/MaxLen: the longest value the field accepts, in characters.
Text fields only; ignored on a button. Setting it is also what turns the comb flag (bit 25) into evenly spaced cells, which is why the two are usually written together.
Sourcepub fn required(self, yes: bool) -> Self
pub fn required(self, yes: bool) -> Self
/Ff bit 2: the field must have a value when the form is submitted.
Sourcepub fn multiline(self, yes: bool) -> Self
pub fn multiline(self, yes: bool) -> Self
/Ff bit 13: the text field accepts more than one line.
Text fields only.
Sourcepub fn password(self, yes: bool) -> Self
pub fn password(self, yes: bool) -> Self
/Ff bit 14: the text field masks what is typed.
Text fields only.
Sourcepub fn comb(self, yes: bool) -> Self
pub fn comb(self, yes: bool) -> Self
/Ff bit 25: the text field is divided into Self::max_len evenly
spaced cells.
The comb flag has no meaning without a /MaxLen, and the reader’s
layout ignores it when there is none.
Sourcepub fn flags(self, bits: i64) -> Self
pub fn flags(self, bits: i64) -> Self
Any further /Ff bits, as
FieldFlags::bits reports them.
The named setters above cover the bits a caller reaches for; this is the escape hatch for the rest, and for round-tripping a flag word read off an existing field.
Sourcepub fn appearance(self, appearance: WidgetAppearance) -> Self
pub fn appearance(self, appearance: WidgetAppearance) -> Self
/MK: the background, border and caption the widget is drawn with.
A field with no /MK has no background and no visible border — the
chrome generator paints only what /MK names — so a field meant to
look like a box wants at least a WidgetAppearance::border.