agg_gui/widgets/text_field/password.rs
1//! Password-mode support for [`TextField`](super::TextField).
2//!
3//! Split out of `text_field.rs` to keep that file under the project's 800-line
4//! cap. Holds the builders that enable masking and the runtime "reveal"
5//! override (a shared cell that the demo's eye-toggle button flips), plus the
6//! `masking_active` helper the render/hit-test paths consult to decide whether
7//! to substitute bullet glyphs for the real text.
8
9use std::cell::Cell;
10use std::rc::Rc;
11
12use super::TextField;
13
14impl TextField {
15 /// Enable/disable masking. When on, every character renders as '•'.
16 pub fn with_password_mode(mut self, v: bool) -> Self {
17 self.password_mode = v;
18 self
19 }
20
21 /// Bind a shared "reveal" cell. While the cell holds `true`, a
22 /// password-mode field renders its plaintext (the eye-toggle affordance in
23 /// the demo flips this cell). Has no effect when `password_mode` is `false`.
24 pub fn with_password_reveal_cell(mut self, cell: Rc<Cell<bool>>) -> Self {
25 self.password_reveal = Some(cell);
26 self
27 }
28
29 /// Whether characters should currently be masked: password mode is on and
30 /// no reveal cell is forcing plaintext.
31 #[inline]
32 pub fn masking_active(&self) -> bool {
33 self.password_mode && !self.password_reveal.as_ref().is_some_and(|c| c.get())
34 }
35}