From e69250b6c01270f4c313c4136728afe35f4497fc Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 9 Oct 2024 19:37:54 +0100 Subject: [PATCH] Remove lifetime from PlainEditor and PlainEditorOp --- examples/vello_editor/src/main.rs | 2 +- examples/vello_editor/src/text.rs | 8 ++++---- parley/src/layout/editor.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/vello_editor/src/main.rs b/examples/vello_editor/src/main.rs index eb17b3c..3ec0e37 100644 --- a/examples/vello_editor/src/main.rs +++ b/examples/vello_editor/src/main.rs @@ -49,7 +49,7 @@ struct SimpleVelloApp<'s> { scene: Scene, // Our text state object - editor: text::Editor<'s>, + editor: text::Editor, } impl ApplicationHandler for SimpleVelloApp<'_> { diff --git a/examples/vello_editor/src/text.rs b/examples/vello_editor/src/text.rs index 843f313..feeaea5 100644 --- a/examples/vello_editor/src/text.rs +++ b/examples/vello_editor/src/text.rs @@ -20,10 +20,10 @@ 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, - editor: PlainEditor<'a, Color>, + editor: PlainEditor, last_click_time: Option, click_count: u32, pointer_down: bool, @@ -31,8 +31,8 @@ pub struct Editor<'a> { modifiers: Option, } -impl<'a> Editor<'a> { - pub fn transact(&mut self, t: impl IntoIterator>) { +impl Editor { + pub fn transact(&mut self, t: impl IntoIterator>) { self.editor .transact(&mut self.font_cx, &mut self.layout_cx, t); } diff --git a/parley/src/layout/editor.rs b/parley/src/layout/editor.rs index 4c57123..248a524 100644 --- a/parley/src/layout/editor.rs +++ b/parley/src/layout/editor.rs @@ -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 where T: Brush + Clone + Debug + PartialEq + Default, { - default_style: Arc<[StyleProperty<'a, T>]>, + default_style: Arc<[StyleProperty<'static, T>]>, buffer: String, layout: Layout, selection: Selection, @@ -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 Default for PlainEditor where T: Brush + Clone + Debug + PartialEq + Default, { @@ -55,7 +55,7 @@ where /// Operations on a `PlainEditor` for `PlainEditor::transact` #[non_exhaustive] -pub enum PlainEditorOp<'a, T> +pub enum PlainEditorOp where T: Brush + Clone + Debug + PartialEq + Default, { @@ -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), /// Delete the selection @@ -133,7 +133,7 @@ where ExtendSelectionToPoint(f32, f32), } -impl<'a, T> PlainEditor<'a, T> +impl PlainEditor where T: Brush + Clone + Debug + PartialEq + Default, { @@ -142,7 +142,7 @@ where &mut self, font_cx: &mut FontContext, layout_cx: &mut LayoutContext, - t: impl IntoIterator>, + t: impl IntoIterator>, ) { let mut layout_after = false;