Skip to content

Commit

Permalink
Add min_height and max_height to text_editor
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 30, 2025
1 parent fb87c97 commit 6aab76e
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions widget/src/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub struct TextEditor<
line_height: LineHeight,
width: Length,
height: Length,
min_height: f32,
max_height: f32,
padding: Padding,
wrapping: Wrapping,
class: Theme::Class<'a>,
Expand Down Expand Up @@ -139,6 +141,8 @@ where
line_height: LineHeight::default(),
width: Length::Fill,
height: Length::Shrink,
min_height: 0.0,
max_height: f32::INFINITY,
padding: Padding::new(5.0),
wrapping: Wrapping::default(),
class: Theme::default(),
Expand Down Expand Up @@ -169,15 +173,27 @@ where
self
}

/// Sets the width of the [`TextEditor`].
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
self.width = Length::from(width.into());
self
}

/// Sets the height of the [`TextEditor`].
pub fn height(mut self, height: impl Into<Length>) -> Self {
self.height = height.into();
self
}

/// Sets the width of the [`TextEditor`].
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
self.width = Length::from(width.into());
/// Sets the minimum height of the [`TextEditor`].
pub fn min_height(mut self, min_height: impl Into<Pixels>) -> Self {
self.min_height = min_height.into().0;
self
}

/// Sets the maximum height of the [`TextEditor`].
pub fn max_height(mut self, max_height: impl Into<Pixels>) -> Self {
self.max_height = max_height.into().0;
self
}

Expand Down Expand Up @@ -265,6 +281,8 @@ where
line_height: self.line_height,
width: self.width,
height: self.height,
min_height: self.min_height,
max_height: self.max_height,
padding: self.padding,
wrapping: self.wrapping,
class: self.class,
Expand Down Expand Up @@ -549,7 +567,11 @@ where
state.highlighter_settings = self.highlighter_settings.clone();
}

let limits = limits.width(self.width).height(self.height);
let limits = limits
.width(self.width)
.height(self.height)
.min_height(self.min_height)
.max_height(self.max_height);

internal.editor.update(
limits.shrink(self.padding).max(),
Expand Down

0 comments on commit 6aab76e

Please sign in to comment.