Document and demonstrate how to expand a TextEdit to fill a Ui
This commit is contained in:
parent
66122e4c9a
commit
1394205f52
3 changed files with 31 additions and 2 deletions
|
@ -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`].
|
||||
///
|
||||
/// ```
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue