Skip to main content

pdfrum_form/field/
button.rs

1//! Push buttons: the one control with no value at all.
2//!
3//! A push button stores nothing and commits nothing. It has a pressed
4//! appearance and an action, and the action is the whole point of it.
5//!
6//! # The asserted-broken behaviour
7//!
8//! Pressing Return on a focused push button **does not fire its action**, and
9//! the event is reported as not consumed. That is what the oracle does today,
10//! it is what its own tests assert, and both sites carry an upstream bug
11//! reference saying the numbers "should" be one and true. It is reproduced
12//! as-asserted: the goldens contain this behaviour, and an implementation
13//! that fixed it would fail the tests that pin it. When upstream fixes it,
14//! the diff here will be a recognizable one-line change rather than a mystery.
15
16/// A push button's interaction state.
17///
18/// ```
19/// use pdfrum_form::field::ButtonState;
20///
21/// let mut state = ButtonState::new();
22/// assert!(!state.pressed);
23/// state.pressed = true;
24/// assert!(state.pressed);
25/// ```
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct ButtonState {
28    /// Whether the button is showing its pressed appearance.
29    pub pressed: bool,
30}
31
32impl ButtonState {
33    /// A released button.
34    ///
35    /// ```
36    /// use pdfrum_form::field::ButtonState;
37    ///
38    /// assert!(!ButtonState::new().pressed);
39    /// ```
40    #[must_use]
41    pub fn new() -> ButtonState {
42        ButtonState::default()
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn a_button_starts_released() {
52        assert!(!ButtonState::new().pressed);
53    }
54}