Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PlainEditor width Option<f32> #137

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -31,7 +31,7 @@ where
layout: Layout<T>,
selection: Selection,
cursor_mode: VisualMode,
width: f32,
width: Option<f32>,
scale: f32,
}

Expand Down Expand Up @@ -62,7 +62,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 @@ -448,8 +448,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);
}
}