pub struct ToggleState {
pub state: String,
pub on_state: String,
pub checked_control: Option<AnnotId>,
}Expand description
A check box or radio button’s interaction state.
One fact: which appearance state the control is showing.
use pdfrum_form::field::{ToggleKind, ToggleState, activate, toggle::OFF_STATE};
let mut state = ToggleState::new(OFF_STATE, "On");
assert!(!state.is_checked());
activate(&mut state, ToggleKind::Check, false);
assert_eq!(state.state, "On");Fields§
§state: StringThe appearance state name currently selected — the “on” name when the
control is checked, OFF_STATE when it is not.
on_state: StringThe name this control shows when checked, from its appearance dictionary. Empty when the control offers no on state at all.
checked_control: Option<AnnotId>Which control of the field is the checked one, by its raw
/Annots index, once one has been chosen.
A field’s controls share one state here, which is right for a check
box (a field with one kid) and not enough for a radio group, where the
clicked control shows its own on state and every other control of the
field shows Off. This records the half of that a shared state can
express — which control is on — so a sibling’s appearance can be
answered Off without a second state record.
None before any control has been activated, which is the state a
group loaded from a file with no /V is in.
Implementations§
Source§impl ToggleState
impl ToggleState
Sourcepub fn new(state: impl Into<String>, on_state: impl Into<String>) -> ToggleState
pub fn new(state: impl Into<String>, on_state: impl Into<String>) -> ToggleState
A control showing state, whose checked appearance is on_state.
An empty on_state means the control offers no checked appearance at
all, and it can then never be checked.
use pdfrum_form::field::{ToggleState, toggle::OFF_STATE};
let state = ToggleState::new(OFF_STATE, "On");
assert!(!state.is_checked());
assert_eq!(state.checked_control, None, "nothing has been clicked yet");Sourcepub fn is_checked(&self) -> bool
pub fn is_checked(&self) -> bool
Whether the control is currently checked.
An empty state reads as clear rather than as ambiguous: a widget with no appearance state at all is not checked.
use pdfrum_form::field::ToggleState;
assert!(ToggleState::new("On", "On").is_checked());
assert!(!ToggleState::new("Off", "On").is_checked());
assert!(!ToggleState::new("", "On").is_checked());Sourcepub fn state_for_control(&self, control: AnnotId) -> Option<&str>
pub fn state_for_control(&self, control: AnnotId) -> Option<&str>
The appearance state one control of this field should draw.
The per-control answer a shared ToggleState can give: the clicked
control shows its own on state and every other control of the same
field shows Off.
Three cases, and the middle one is why this is not simply
Self::state:
- Nothing has been clicked (
Self::checked_controlisNone):None, meaning “read the widget’s own/AS” — a group loaded from a file must render exactly as the file wrote it, kid by kid. - This control is the chosen one: its own on state, which for a radio group is a name only this kid carries.
- A sibling was chosen:
OFF_STATE, whatever the file’s/ASstill says.
use pdfrum_form::AnnotId;
use pdfrum_form::field::{ToggleState, toggle::OFF_STATE};
let clicked = AnnotId::new(0u32, 1);
let sibling = AnnotId::new(0u32, 2);
let mut state = ToggleState::new(OFF_STATE, "Choice1");
// Nothing clicked yet: read each widget's own `/AS`.
assert_eq!(state.state_for_control(clicked), None);
state.set_checked(true);
state.checked_control = Some(clicked);
assert_eq!(state.state_for_control(clicked), Some("Choice1"));
assert_eq!(state.state_for_control(sibling), Some(OFF_STATE));Sourcepub fn set_checked(&mut self, checked: bool)
pub fn set_checked(&mut self, checked: bool)
Sets the control checked or clear.
Checking a control with no on state leaves it clear: there is no appearance to show.
use pdfrum_form::field::{ToggleState, toggle::OFF_STATE};
let mut none = ToggleState::new(OFF_STATE, "");
none.set_checked(true);
assert!(!none.is_checked());Trait Implementations§
Source§impl Clone for ToggleState
impl Clone for ToggleState
Source§impl Debug for ToggleState
impl Debug for ToggleState
Source§impl Default for ToggleState
impl Default for ToggleState
impl Eq for ToggleState
Source§impl PartialEq for ToggleState
impl PartialEq for ToggleState
impl StructuralPartialEq for ToggleState
Auto Trait Implementations§
impl Freeze for ToggleState
impl RefUnwindSafe for ToggleState
impl Send for ToggleState
impl Sync for ToggleState
impl Unpin for ToggleState
impl UnsafeUnpin for ToggleState
impl UnwindSafe for ToggleState
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.