text_edit: scale the single-line horizontal padding with the field height
The previous commit put the password eye, the caret and the whole multiline layout in physical pixels, but the single-line variant still inset its text by the raw `theme::PAD_H`: 20 physical px whatever the scale. On a scale-2 panel a field 88 px tall, drawn as a pill of radius 44, kept a 20 px inset, so the first glyph sat inside the rounded end while everything else in the field had grown. The padding now follows the field height, like the eye already did: `metrics::single_line_pad_h( rect )` is `PAD_H × rect.height / theme::HEIGHT`, built on `single_line_scale`, which replaces the private `password_toggle_scale` of `draw.rs`. The height is the right reference rather than `canvas.geom_px( PAD_H )`: the inset exists to clear the pill's rounded end, whose radius is half the height. With the default height the two agree, since that height is itself `geom_px( HEIGHT )`; when the app pins the height the padding follows that choice instead of the fluid mode, which on a large surface would push it to 1.5 times the design value next to a field the app deliberately kept smaller. It also needs no canvas, so `password_toggle_hit_zone( rect )` keeps its signature. `draw` resolves the padding once and uses it for the narrowed text rect, the inner clip, the selection band, the placeholder, the text and the caret; `password_toggle_hit_zone` uses it for the half padding beside the eye. `single_line_scroll_x`, `single_line_align_offset` and the single-line branch of `byte_offset_at` use the same helper, so a click still maps to the glyph that was drawn. `hit_test.rs` no longer references `theme` and drops the import. A field `HEIGHT` tall at scale 1 keeps exactly the previous geometry.
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
use crate::render::Canvas;
|
||||
use crate::types::{ Length, Point, Rect };
|
||||
|
||||
use super::metrics::MultilineMetrics;
|
||||
use super::theme;
|
||||
use super::metrics::{ single_line_pad_h, MultilineMetrics };
|
||||
use super::wrapping::compute_visual_lines;
|
||||
|
||||
/// Convert a pointer position inside the widget rect to the byte offset
|
||||
@@ -65,7 +64,7 @@ pub( crate ) fn byte_offset_at(
|
||||
let align_x = single_line_align_offset( canvas, rect, value, secure, align, font_size );
|
||||
byte_offset_in_line(
|
||||
canvas, value, 0, value.len(),
|
||||
pos.x - rect.x - theme::PAD_H - align_x + scroll_x,
|
||||
pos.x - rect.x - single_line_pad_h( rect ) - align_x + scroll_x,
|
||||
secure,
|
||||
font_size,
|
||||
)
|
||||
@@ -98,7 +97,7 @@ pub( crate ) fn single_line_scroll_x(
|
||||
font_size: f32,
|
||||
) -> f32
|
||||
{
|
||||
let inner_width = ( rect.width - theme::PAD_H * 2.0 ).max( font_size );
|
||||
let inner_width = ( rect.width - single_line_pad_h( rect ) * 2.0 ).max( font_size );
|
||||
let safe_cursor = cursor.min( value.len() );
|
||||
|
||||
let display_value: String = if secure
|
||||
@@ -147,7 +146,7 @@ pub( crate ) fn single_line_align_offset(
|
||||
{
|
||||
use crate::widget::text::TextAlign;
|
||||
if matches!( align, TextAlign::Left ) { return 0.0; }
|
||||
let inner_width = ( rect.width - theme::PAD_H * 2.0 ).max( font_size );
|
||||
let inner_width = ( rect.width - single_line_pad_h( rect ) * 2.0 ).max( font_size );
|
||||
let display_value: String = if secure
|
||||
{
|
||||
"\u{2022}".repeat( value.chars().count() )
|
||||
|
||||
Reference in New Issue
Block a user