From d6b32b795685a9ae1e44abeb7eae3d17544a2563 Mon Sep 17 00:00:00 2001 From: BctfN0HUK7Yg Date: Mon, 17 Jan 2022 16:56:27 +0300 Subject: [PATCH] Add set margin method to TextEdit (#1104) --- egui/src/widgets/text_edit/builder.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/egui/src/widgets/text_edit/builder.rs b/egui/src/widgets/text_edit/builder.rs index 4337e682..0c06260a 100644 --- a/egui/src/widgets/text_edit/builder.rs +++ b/egui/src/widgets/text_edit/builder.rs @@ -57,6 +57,7 @@ pub struct TextEdit<'t> { layouter: Option<&'t mut dyn FnMut(&Ui, &str, f32) -> Arc>, password: bool, frame: bool, + margin: Vec2, multiline: bool, interactive: bool, desired_width: Option, @@ -101,6 +102,7 @@ impl<'t> TextEdit<'t> { layouter: None, password: false, frame: true, + margin: vec2(4.0, 2.0), multiline: true, interactive: true, desired_width: None, @@ -200,6 +202,12 @@ impl<'t> TextEdit<'t> { self } + /// Set margin of text. Default is [4.0,2.0] + pub fn margin(mut self, margin: Vec2) -> Self { + self.margin = margin; + self + } + /// Set to 0.0 to keep as small as possible. /// Set to [`f32::INFINITY`] to take up all available space (i.e. disable automatic word wrap). pub fn desired_width(mut self, desired_width: f32) -> Self { @@ -264,7 +272,7 @@ impl<'t> TextEdit<'t> { let interactive = self.interactive; let where_to_put_background = ui.painter().add(Shape::Noop); - let margin = Vec2::new(4.0, 2.0); + let margin = self.margin; let max_rect = ui.available_rect_before_wrap().shrink2(margin); let mut content_ui = ui.child_ui(max_rect, *ui.layout()); let mut output = self.show_content(&mut content_ui); @@ -327,6 +335,7 @@ impl<'t> TextEdit<'t> { layouter, password, frame: _, + margin: _, multiline, interactive, desired_width,