From 83171f05d0111808ebafda309222e45062d3a0b0 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Mon, 25 Apr 2022 08:52:10 -0700 Subject: Don't wrap picklist label text --- native/src/widget/pick_list.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'native/src') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index e050ada5..998b9b3c 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -412,6 +412,7 @@ pub fn draw( bounds: Rectangle { x: bounds.x + f32::from(padding.left), y: bounds.center_y(), + width: f32::INFINITY, ..bounds }, horizontal_alignment: alignment::Horizontal::Left, -- cgit From 6e70d9ad83432b45e6bcfd022ba31e192ad99669 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Mon, 25 Apr 2022 09:01:04 -0700 Subject: Clip bounds to prevent text overflow --- native/src/widget/pick_list.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'native/src') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 998b9b3c..4f00c96e 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -402,22 +402,24 @@ pub fn draw( if let Some(label) = label.as_ref().map(String::as_str).or_else(|| placeholder) { - renderer.fill_text(Text { - content: label, - size: f32::from(text_size.unwrap_or(renderer.default_size())), - font: font.clone(), - color: is_selected - .then(|| style.text_color) - .unwrap_or(style.placeholder_color), - bounds: Rectangle { - x: bounds.x + f32::from(padding.left), - y: bounds.center_y(), - width: f32::INFINITY, - ..bounds - }, - horizontal_alignment: alignment::Horizontal::Left, - vertical_alignment: alignment::Vertical::Center, - }) + renderer.with_layer(bounds, |layer| { + layer.fill_text(Text { + content: label, + size: f32::from(text_size.unwrap_or(layer.default_size())), + font: font.clone(), + color: is_selected + .then(|| style.text_color) + .unwrap_or(style.placeholder_color), + bounds: Rectangle { + x: bounds.x + f32::from(padding.left), + y: bounds.center_y(), + width: f32::INFINITY, + ..bounds + }, + horizontal_alignment: alignment::Horizontal::Left, + vertical_alignment: alignment::Vertical::Center, + }) + }); } } -- cgit From 4329f0480bec803346e7e5b8c02cc17f62b6ab35 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Wed, 27 Apr 2022 08:49:55 -0700 Subject: Use top alignment instead of new layer --- native/src/widget/pick_list.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'native/src') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 4f00c96e..5ed07863 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -402,23 +402,20 @@ pub fn draw( if let Some(label) = label.as_ref().map(String::as_str).or_else(|| placeholder) { - renderer.with_layer(bounds, |layer| { - layer.fill_text(Text { - content: label, - size: f32::from(text_size.unwrap_or(layer.default_size())), - font: font.clone(), - color: is_selected - .then(|| style.text_color) - .unwrap_or(style.placeholder_color), - bounds: Rectangle { - x: bounds.x + f32::from(padding.left), - y: bounds.center_y(), - width: f32::INFINITY, - ..bounds - }, - horizontal_alignment: alignment::Horizontal::Left, - vertical_alignment: alignment::Vertical::Center, - }) + renderer.fill_text(Text { + content: label, + size: f32::from(text_size.unwrap_or(renderer.default_size())), + font: font.clone(), + color: is_selected + .then(|| style.text_color) + .unwrap_or(style.placeholder_color), + bounds: Rectangle { + x: bounds.x + f32::from(padding.left), + y: bounds.center_y(), + ..bounds + }, + horizontal_alignment: alignment::Horizontal::Left, + vertical_alignment: alignment::Vertical::Top, }); } } -- cgit From bc8b4bb1828a8bd4fa95b585d0655adec8f85f9d Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Wed, 27 Apr 2022 08:56:43 -0700 Subject: Manually center top aligned text --- native/src/widget/pick_list.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'native/src') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 5ed07863..2e61e036 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -402,16 +402,18 @@ pub fn draw( if let Some(label) = label.as_ref().map(String::as_str).or_else(|| placeholder) { + let text_size = f32::from(text_size.unwrap_or(renderer.default_size())); + renderer.fill_text(Text { content: label, - size: f32::from(text_size.unwrap_or(renderer.default_size())), + size: text_size, font: font.clone(), color: is_selected .then(|| style.text_color) .unwrap_or(style.placeholder_color), bounds: Rectangle { x: bounds.x + f32::from(padding.left), - y: bounds.center_y(), + y: bounds.center_y() - text_size / 2.0, ..bounds }, horizontal_alignment: alignment::Horizontal::Left, -- cgit From d562c27e8ce10ecf4aed4d5fc4c64a737391c2c9 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Wed, 27 Apr 2022 09:13:11 -0700 Subject: Restrict text width & height to prevent overflow --- native/src/widget/pick_list.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'native/src') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 2e61e036..0374aef7 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -414,7 +414,8 @@ pub fn draw( bounds: Rectangle { x: bounds.x + f32::from(padding.left), y: bounds.center_y() - text_size / 2.0, - ..bounds + width: bounds.width - f32::from(padding.horizontal()), + height: text_size, }, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Top, -- cgit