ltk/input/dispatch/
password_toggle.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use crate::app::App;
use crate::event_loop::{ AppData, SurfaceFocus };
use crate::types::Point;
use crate::widget::WidgetHandlers;

impl<A: App> AppData<A>
{
	/// If the press at `pos` lands on a password-toggle icon zone of
	/// the widget at `idx`, push the toggle message and return
	/// `true` so the caller can skip the rest of the cursor /
	/// selection placement that would otherwise consume the press.
	/// Returns `false` when there is no toggle on that widget or
	/// the press fell outside the icon's hit area, leaving the
	/// caller to dispatch the press normally.
	pub( crate ) fn handle_password_toggle_press
	(
		&mut self,
		focus: SurfaceFocus,
		idx:   usize,
		pos:   Point,
	) -> bool
	{
		let toggle_msg = self.surface( focus ).widget_rects.iter()
			.find( |w| w.flat_idx == idx )
			.and_then( |w| match &w.handlers
			{
				WidgetHandlers::TextEdit { password_toggle_msg: Some( msg ), .. } =>
				{
					let zone = crate::widget::text_edit::password_toggle_hit_zone( w.rect );
					if zone.contains( pos ) { Some( msg.clone() ) } else { None }
				}
				_ => None,
			} );
		if let Some( msg ) = toggle_msg
		{
			self.pending_msgs.push( msg );
			self.surface_mut( focus ).request_redraw();
			true
		}
		else
		{
			false
		}
	}
}