summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--core/src/renderer/null.rs4
-rw-r--r--core/src/text/editor.rs4
-rw-r--r--examples/editor/src/main.rs1
-rw-r--r--graphics/src/text/editor.rs6
-rw-r--r--widget/src/text_editor.rs26
6 files changed, 41 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fb9afe47..73043068 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `text_shaping` method for `Tooltip`. [#2172](https://github.com/iced-rs/iced/pull/2172)
- `interaction` method for `MouseArea`. [#2207](https://github.com/iced-rs/iced/pull/2207)
- `hovered` styling for `Svg` widget. [#2163](https://github.com/iced-rs/iced/pull/2163)
+- `height` method for `TextEditor`. [#2221](https://github.com/iced-rs/iced/pull/2221)
- Customizable style for `TextEditor`. [#2159](https://github.com/iced-rs/iced/pull/2159)
- Border width styling for `Toggler`. [#2219](https://github.com/iced-rs/iced/pull/2219)
- `RawText` variant for `Primitive` in `iced_graphics`. [#2158](https://github.com/iced-rs/iced/pull/2158)
@@ -118,6 +119,7 @@ Many thanks to...
- @derezzedex
- @DoomDuck
- @dtzxporter
+- @Dworv
- @fogarecious
- @GyulyVGC
- @hicaru
diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs
index 75a3c8b6..83688ff7 100644
--- a/core/src/renderer/null.rs
+++ b/core/src/renderer/null.rs
@@ -150,6 +150,10 @@ impl text::Editor for () {
Size::ZERO
}
+ fn min_bounds(&self) -> Size {
+ Size::ZERO
+ }
+
fn update(
&mut self,
_new_bounds: Size,
diff --git a/core/src/text/editor.rs b/core/src/text/editor.rs
index f3c6e342..fbf60696 100644
--- a/core/src/text/editor.rs
+++ b/core/src/text/editor.rs
@@ -36,6 +36,10 @@ pub trait Editor: Sized + Default {
/// Returns the current boundaries of the [`Editor`].
fn bounds(&self) -> Size;
+ /// Returns the minimum boundaries to fit the current contents of
+ /// the [`Editor`].
+ fn min_bounds(&self) -> Size;
+
/// Updates the [`Editor`] with some new attributes.
fn update(
&mut self,
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index bf2aaaa3..75b66264 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -191,6 +191,7 @@ impl Application for Editor {
column![
controls,
text_editor(&self.content)
+ .height(Length::Fill)
.on_action(Message::ActionPerformed)
.highlight::<Highlighter>(
highlighter::Settings {
diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs
index d5262ae8..c488a51c 100644
--- a/graphics/src/text/editor.rs
+++ b/graphics/src/text/editor.rs
@@ -470,6 +470,12 @@ impl editor::Editor for Editor {
self.internal().bounds
}
+ fn min_bounds(&self) -> Size {
+ let internal = self.internal();
+
+ text::measure(internal.editor.buffer())
+ }
+
fn update(
&mut self,
new_bounds: Size,
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs
index 8d431991..cbcab1eb 100644
--- a/widget/src/text_editor.rs
+++ b/widget/src/text_editor.rs
@@ -64,7 +64,7 @@ where
text_size: None,
line_height: LineHeight::default(),
width: Length::Fill,
- height: Length::Fill,
+ height: Length::Shrink,
padding: Padding::new(5.0),
style: Default::default(),
on_edit: None,
@@ -83,6 +83,12 @@ where
Theme: StyleSheet,
Renderer: text::Renderer,
{
+ /// Sets the height of the [`TextEditor`].
+ pub fn height(mut self, height: impl Into<Length>) -> Self {
+ self.height = height.into();
+ self
+ }
+
/// Sets the message that should be produced when some action is performed in
/// the [`TextEditor`].
///
@@ -352,6 +358,8 @@ where
state.highlighter_settings = self.highlighter_settings.clone();
}
+ let limits = limits.height(self.height);
+
internal.editor.update(
limits.shrink(self.padding).max(),
self.font.unwrap_or_else(|| renderer.default_font()),
@@ -360,7 +368,21 @@ where
state.highlighter.borrow_mut().deref_mut(),
);
- layout::Node::new(limits.max())
+ match self.height {
+ Length::Fill | Length::FillPortion(_) | Length::Fixed(_) => {
+ layout::Node::new(limits.max())
+ }
+ Length::Shrink => {
+ let min_bounds = internal.editor.min_bounds();
+
+ layout::Node::new(
+ limits
+ .height(min_bounds.height)
+ .max()
+ .expand(Size::new(0.0, self.padding.vertical())),
+ )
+ }
+ }
}
fn on_event(