Skip to content

Commit

Permalink
Make PlainEditor width Option<f32> (#137)
Browse files Browse the repository at this point in the history
This matches `Layout`, and is useful for single-line text inputs that
shouldn't ever wrap.
  • Loading branch information
nicoburns authored Oct 11, 2024
1 parent 91ff8e9 commit 352df19
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/vello_editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ApplicationHandler for SimpleVelloApp<'_> {

self.editor.transact([
PlainEditorOp::SetScale(1.0),
PlainEditorOp::SetWidth(size.width as f32 - 2f32 * text::INSET),
PlainEditorOp::SetWidth(Some(size.width as f32 - 2f32 * text::INSET)),
PlainEditorOp::SetText(text::LOREM.into()),
]);

Expand Down Expand Up @@ -130,7 +130,7 @@ impl ApplicationHandler for SimpleVelloApp<'_> {
render_state.window.request_redraw();
self.editor.transact([
PlainEditorOp::SetScale(1.0),
PlainEditorOp::SetWidth(size.width as f32 - 2f32 * text::INSET),
PlainEditorOp::SetWidth(Some(size.width as f32 - 2f32 * text::INSET)),
PlainEditorOp::SetDefaultStyle(Arc::new([
StyleProperty::FontSize(32.0),
StyleProperty::LineHeight(1.2),
Expand Down
4 changes: 3 additions & 1 deletion examples/vello_editor/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ impl Editor {
self.editor.transact(
&mut self.font_cx,
&mut self.layout_cx,
[PlainEditorOp::SetWidth(size.width as f32 - 2f32 * INSET)],
[PlainEditorOp::SetWidth(Some(
size.width as f32 - 2f32 * INSET,
))],
);
}
WindowEvent::ModifiersChanged(modifiers) => {
Expand Down
8 changes: 4 additions & 4 deletions parley/src/layout/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
layout: Layout<T>,
selection: Selection,
cursor_mode: VisualMode,
width: f32,
width: Option<f32>,
scale: f32,
}

Expand Down Expand Up @@ -63,7 +63,7 @@ where
/// Replace the whole text buffer
SetText(Arc<str>),
/// Set the width of the layout
SetWidth(f32),
SetWidth(Option<f32>),
/// Set the scale for the layout
SetScale(f32),
/// Set the default style for the layout
Expand Down Expand Up @@ -449,8 +449,8 @@ where
builder.push_default(prop.to_owned());
}
builder.build_into(&mut self.layout, &self.buffer);
self.layout.break_all_lines(Some(self.width));
self.layout.align(Some(self.width), Alignment::Start);
self.layout.break_all_lines(self.width);
self.layout.align(self.width, Alignment::Start);
self.selection = self.selection.refresh(&self.layout);
}
}

0 comments on commit 352df19

Please sign in to comment.