diff options
Diffstat (limited to 'wgpu/src/renderer')
-rw-r--r-- | wgpu/src/renderer/widget/checkbox.rs | 6 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/text.rs | 14 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/text_input.rs | 25 |
3 files changed, 36 insertions, 9 deletions
diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs index ecacf1de..c0f1bf21 100644 --- a/wgpu/src/renderer/widget/checkbox.rs +++ b/wgpu/src/renderer/widget/checkbox.rs @@ -38,7 +38,11 @@ impl checkbox::Renderer for Renderer { content: crate::text::CHECKMARK_ICON.to_string(), font: crate::text::BUILTIN_ICONS, size: bounds.height * 0.7, - bounds, + bounds: Rectangle { + x: bounds.center_x(), + y: bounds.center_y(), + ..bounds + }, color: style.checkmark_color, horizontal_alignment: HorizontalAlignment::Center, vertical_alignment: VerticalAlignment::Center, diff --git a/wgpu/src/renderer/widget/text.rs b/wgpu/src/renderer/widget/text.rs index 33e549cd..80bff574 100644 --- a/wgpu/src/renderer/widget/text.rs +++ b/wgpu/src/renderer/widget/text.rs @@ -31,11 +31,23 @@ impl text::Renderer for Renderer { horizontal_alignment: HorizontalAlignment, vertical_alignment: VerticalAlignment, ) -> Self::Output { + let x = match horizontal_alignment { + iced_native::HorizontalAlignment::Left => bounds.x, + iced_native::HorizontalAlignment::Center => bounds.center_x(), + iced_native::HorizontalAlignment::Right => bounds.x + bounds.width, + }; + + let y = match vertical_alignment { + iced_native::VerticalAlignment::Top => bounds.y, + iced_native::VerticalAlignment::Center => bounds.center_y(), + iced_native::VerticalAlignment::Bottom => bounds.y + bounds.height, + }; + ( Primitive::Text { content: content.to_string(), size: f32::from(size), - bounds, + bounds: Rectangle { x, y, ..bounds }, color: color.unwrap_or(defaults.text.color), font, horizontal_alignment, diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs index 9093b0c6..6f72db68 100644 --- a/wgpu/src/renderer/widget/text_input.rs +++ b/wgpu/src/renderer/widget/text_input.rs @@ -23,11 +23,11 @@ impl text_input::Renderer for Renderer { Size::INFINITY, ); - let spaces_at_the_end = value.len() - value.trim_end().len(); + let spaces_around = value.len() - value.trim().len(); - if spaces_at_the_end > 0 { + if spaces_around > 0 { let space_width = self.text_pipeline.space_width(size as f32); - width += spaces_at_the_end as f32 * space_width; + width += spaces_around as f32 * space_width; } width @@ -109,6 +109,7 @@ impl text_input::Renderer for Renderer { }, font, bounds: Rectangle { + y: text_bounds.center_y(), width: f32::INFINITY, ..text_bounds }, @@ -210,10 +211,20 @@ impl text_input::Renderer for Renderer { (text_value, Vector::new(0, 0)) }; - let contents = Primitive::Clip { - bounds: text_bounds, - offset, - content: Box::new(contents_primitive), + let text_width = self.measure_value( + if text.is_empty() { placeholder } else { &text }, + size, + font, + ); + + let contents = if text_width > text_bounds.width { + Primitive::Clip { + bounds: text_bounds, + offset, + content: Box::new(contents_primitive), + } + } else { + contents_primitive }; ( |