From 99726decb62e0032a776a603e610530d227a736f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 13 Jan 2021 23:14:46 +0100 Subject: [PATCH] Add option to remove the frame from a TextEdit --- egui/src/widgets/text_edit.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index dc6ee9bf..9cd970ee 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -127,6 +127,7 @@ pub struct TextEdit<'t> { id_source: Option, text_style: Option, text_color: Option, + frame: bool, multiline: bool, enabled: bool, desired_width: Option, @@ -147,6 +148,7 @@ impl<'t> TextEdit<'t> { id_source: None, text_style: None, text_color: None, + frame: true, multiline: false, enabled: true, desired_width: None, @@ -161,6 +163,7 @@ impl<'t> TextEdit<'t> { id: None, id_source: None, text_style: None, + frame: true, text_color: None, multiline: true, enabled: true, @@ -201,6 +204,12 @@ impl<'t> TextEdit<'t> { self } + /// Default is `true`. If set to `false` there will be no frame showing that this is editable text! + pub fn frame(mut self, frame: bool) -> Self { + self.frame = frame; + self + } + /// Set to 0.0 to keep as small as possible pub fn desired_width(mut self, desired_width: f32) -> Self { self.desired_width = Some(desired_width); @@ -218,6 +227,7 @@ impl<'t> TextEdit<'t> { impl<'t> Widget for TextEdit<'t> { fn ui(self, ui: &mut Ui) -> Response { + let frame = self.frame; let margin = Vec2::splat(2.0); let frame_rect = ui.available_rect_before_wrap(); let content_rect = frame_rect.shrink2(margin); @@ -227,17 +237,19 @@ impl<'t> Widget for TextEdit<'t> { let frame_rect = Rect::from_min_max(frame_rect.min, content_ui.min_rect().max + margin); let response = response | ui.allocate_response(frame_rect.size(), Sense::click()); - let visuals = ui.style().interact(&response); - let frame_rect = response.rect.expand(visuals.expansion); - ui.painter().set( - where_to_put_background, - Shape::Rect { - rect: frame_rect, - corner_radius: visuals.corner_radius, - fill: ui.style().visuals.dark_bg_color, - stroke: visuals.bg_stroke, - }, - ); + if frame { + let visuals = ui.style().interact(&response); + let frame_rect = response.rect.expand(visuals.expansion); + ui.painter().set( + where_to_put_background, + Shape::Rect { + rect: frame_rect, + corner_radius: visuals.corner_radius, + fill: ui.style().visuals.dark_bg_color, + stroke: visuals.bg_stroke, + }, + ); + } response } @@ -251,6 +263,7 @@ impl<'t> TextEdit<'t> { id_source, text_style, text_color, + frame: _, multiline, enabled, desired_width,