Skip to content

Commit

Permalink
Remove lifetime from PlainEditor and PlainEditorOp
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 9, 2024
1 parent 3e13f0d commit e69250b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/vello_editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct SimpleVelloApp<'s> {
scene: Scene,

// Our text state object
editor: text::Editor<'s>,
editor: text::Editor,
}

impl ApplicationHandler for SimpleVelloApp<'_> {
Expand Down
8 changes: 4 additions & 4 deletions examples/vello_editor/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ use parley::{FontContext, LayoutContext, PlainEditor, PlainEditorOp};
pub const INSET: f32 = 32.0;

#[derive(Default)]
pub struct Editor<'a> {
pub struct Editor {
font_cx: FontContext,
layout_cx: LayoutContext<Color>,
editor: PlainEditor<'a, Color>,
editor: PlainEditor<Color>,
last_click_time: Option<Instant>,
click_count: u32,
pointer_down: bool,
cursor_pos: (f32, f32),
modifiers: Option<Modifiers>,
}

impl<'a> Editor<'a> {
pub fn transact(&mut self, t: impl IntoIterator<Item = PlainEditorOp<'a, Color>>) {
impl Editor {
pub fn transact(&mut self, t: impl IntoIterator<Item = PlainEditorOp<Color>>) {
self.editor
.transact(&mut self.font_cx, &mut self.layout_cx, t);
}
Expand Down
14 changes: 7 additions & 7 deletions parley/src/layout/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub enum ActiveText<'a> {
}

/// Basic plain text editor with a single default style.
pub struct PlainEditor<'a, T>
pub struct PlainEditor<T>
where
T: Brush + Clone + Debug + PartialEq + Default,
{
default_style: Arc<[StyleProperty<'a, T>]>,
default_style: Arc<[StyleProperty<'static, T>]>,
buffer: String,
layout: Layout<T>,
selection: Selection,
Expand All @@ -36,7 +36,7 @@ where
}

// TODO: When MSRV >= 1.80 we can remove this. Default was not implemented for Arc<[T]> where T: !Default until 1.80
impl<'a, T> Default for PlainEditor<'a, T>
impl<T> Default for PlainEditor<T>
where
T: Brush + Clone + Debug + PartialEq + Default,
{
Expand All @@ -55,7 +55,7 @@ where

/// Operations on a `PlainEditor` for `PlainEditor::transact`
#[non_exhaustive]
pub enum PlainEditorOp<'a, T>
pub enum PlainEditorOp<T>
where
T: Brush + Clone + Debug + PartialEq + Default,
{
Expand All @@ -66,7 +66,7 @@ where
/// Set the scale for the layout
SetScale(f32),
/// Set the default style for the layout
SetDefaultStyle(Arc<[StyleProperty<'a, T>]>),
SetDefaultStyle(Arc<[StyleProperty<'static, T>]>),
/// Insert at cursor, or replace selection
InsertOrReplaceSelection(Arc<str>),
/// Delete the selection
Expand Down Expand Up @@ -133,7 +133,7 @@ where
ExtendSelectionToPoint(f32, f32),
}

impl<'a, T> PlainEditor<'a, T>
impl<T> PlainEditor<T>
where
T: Brush + Clone + Debug + PartialEq + Default,
{
Expand All @@ -142,7 +142,7 @@ where
&mut self,
font_cx: &mut FontContext,
layout_cx: &mut LayoutContext<T>,
t: impl IntoIterator<Item = PlainEditorOp<'a, T>>,
t: impl IntoIterator<Item = PlainEditorOp<T>>,
) {
let mut layout_after = false;

Expand Down

0 comments on commit e69250b

Please sign in to comment.