From 1394205f52bf8a1866a53c2dc1741b79cd88ae78 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 2 May 2021 21:56:59 +0200 Subject: [PATCH] Document and demonstrate how to expand a TextEdit to fill a Ui --- egui/src/ui.rs | 2 ++ egui/src/widgets/text_edit.rs | 9 +++++++++ egui_demo_lib/src/apps/demo/tests.rs | 22 ++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/egui/src/ui.rs b/egui/src/ui.rs index b3f35c8e..cc483425 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -817,6 +817,8 @@ impl Ui { /// Add a [`Widget`] to this `Ui` with a given size. /// The widget will attempt to fit within the given size, but some widgets may overflow. /// + /// To fill all remaining area, use `ui.add_sized(ui.available_size(), widget);` + /// /// See also [`Self::add`] and [`Self::put`]. /// /// ``` diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 6b2520ad..055fba41 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -125,6 +125,15 @@ impl CCursorPair { /// // … /// } /// ``` +/// +/// To fill an [`Ui`] with a [`TextEdit`] use [`Ui::add_sized`]: +/// +/// ``` +/// # let mut ui = egui::Ui::__test(); +/// # let mut my_string = String::new(); +/// ui.add_sized(ui.available_size(), egui::TextEdit::multiline(&mut my_string)); +/// ``` +/// #[must_use = "You should put this widget in an ui with `ui.add(widget);`"] #[derive(Debug)] pub struct TextEdit<'t> { diff --git a/egui_demo_lib/src/apps/demo/tests.rs b/egui_demo_lib/src/apps/demo/tests.rs index dbebc633..6c0656fa 100644 --- a/egui_demo_lib/src/apps/demo/tests.rs +++ b/egui_demo_lib/src/apps/demo/tests.rs @@ -319,8 +319,17 @@ impl super::View for InputTest { // ---------------------------------------------------------------------------- -#[derive(Default)] -pub struct WindowResizeTest {} +pub struct WindowResizeTest { + text: String, +} + +impl Default for WindowResizeTest { + fn default() -> Self { + Self { + text: crate::LOREM_IPSUM.to_owned(), + } + } +} impl super::Demo for WindowResizeTest { fn name(&self) -> &'static str { @@ -381,5 +390,14 @@ impl super::Demo for WindowResizeTest { ui.separator(); ui.code(crate::LOREM_IPSUM); }); + + Window::new("↔ resizable with TextEdit") + .open(open) + .scroll(false) + .resizable(true) + .show(ctx, |ui| { + ui.label("Shows how you can fill an area with a widget."); + ui.add_sized(ui.available_size(), TextEdit::multiline(&mut self.text)); + }); } }