pub struct TextEditor { /* private fields */ }Expand description
A text editor view built on top of Editor. See text_editor.
Note: this requires that the document underlying it is a TextDocument for the use of some
logic.
Implementations§
Source§impl TextEditor
impl TextEditor
Sourcepub fn editor_style(
self,
style: impl Fn(EditorCustomStyle) -> EditorCustomStyle + 'static,
) -> Self
pub fn editor_style( self, style: impl Fn(EditorCustomStyle) -> EditorCustomStyle + 'static, ) -> Self
Sets the custom style properties of the TextEditor.
Sourcepub fn with_editor(self, f: impl FnOnce(&Editor)) -> Self
pub fn with_editor(self, f: impl FnOnce(&Editor)) -> Self
Allows for creation of a TextEditor with an existing Editor.
Sourcepub fn with_editor_mut(self, f: impl FnOnce(&mut Editor)) -> Self
pub fn with_editor_mut(self, f: impl FnOnce(&mut Editor)) -> Self
Allows for creation of a TextEditor with an existing mutable Editor.
Sourcepub fn with_doc(self, f: impl FnOnce(&dyn Document)) -> Self
pub fn with_doc(self, f: impl FnOnce(&dyn Document)) -> Self
Opens the TextEditor with the provided Document.
You should usually not swap this out without good reason.
Sourcepub fn doc(&self) -> Rc<dyn Document>
pub fn doc(&self) -> Rc<dyn Document>
Returns a reference to the underlying Document. This should usually be a TextDocument.
pub fn rope_text(&self) -> RopeTextVal
Sourcepub fn use_doc(self, doc: Rc<dyn Document>) -> Self
pub fn use_doc(self, doc: Rc<dyn Document>) -> Self
Use a different document in the text editor
Use the same document as another text editor view.
let primary = text_editor();
let secondary = text_editor().share_document(&primary);
stack((
primary,
secondary,
))If you wish for it to also share the styling, consider using TextEditor::shared_editor
instead.
Create a new TextEditor instance from this instance, sharing the document and styling.
let primary = text_editor();
let secondary = primary.shared_editor();Also see the Editor example.
Sourcepub fn styling_rc(self, styling: Rc<dyn Styling>) -> Self
pub fn styling_rc(self, styling: Rc<dyn Styling>) -> Self
Use an Rc<dyn Styling> to share between different editors.
Sourcepub fn read_only(self) -> Self
pub fn read_only(self) -> Self
Set the text editor to read only.
Equivalent to setting Editor::read_only
Default: false
Sourcepub fn placeholder(self, text: impl Into<String>) -> Self
pub fn placeholder(self, text: impl Into<String>) -> Self
Set the placeholder text that is displayed when the document is empty.
Can span multiple lines.
This is per-editor, not per-document.
Equivalent to calling TextDocument::add_placeholder
Default: None
Note: only works for the default backing TextDocument doc
Sourcepub fn pre_command(
self,
f: impl Fn(PreCommand<'_>) -> CommandExecuted + 'static,
) -> Self
pub fn pre_command( self, f: impl Fn(PreCommand<'_>) -> CommandExecuted + 'static, ) -> Self
When commands are run on the document, this function is called.
If it returns CommandExecuted::Yes then further handlers after it, including the
default handler, are not executed.
use floem::views::editor::command::{Command, CommandExecuted};
use floem::views::text_editor::text_editor;
use floem_editor_core::command::EditCommand;
text_editor("Hello")
.pre_command(|ev| {
if matches!(ev.cmd, Command::Edit(EditCommand::Undo)) {
// Sorry, no undoing allowed
CommandExecuted::Yes
} else {
CommandExecuted::No
}
})
.pre_command(|_| {
// This will never be called if command was an undo
CommandExecuted::Yes
})
.pre_command(|_| {
// This will never be called
CommandExecuted::No
});Note that these are specific to each text editor view.
Note: only works for the default backing TextDocument doc
Sourcepub fn update(self, f: impl Fn(OnUpdate<'_>) + 'static) -> Self
pub fn update(self, f: impl Fn(OnUpdate<'_>) + 'static) -> Self
Listen for deltas applied to the editor.
Useful for anything that has positions based in the editor that can be updated after typing, such as syntax highlighting.
Note: only works for the default backing TextDocument doc
Trait Implementations§
Source§impl View for TextEditor
impl View for TextEditor
fn id(&self) -> ViewId
fn view_style(&self) -> Option<Style>
fn debug_name(&self) -> Cow<'static, str>
Source§fn paint(&mut self, cx: &mut PaintCx<'_>)
fn paint(&mut self, cx: &mut PaintCx<'_>)
View-specific implementation. Will be called in PaintCx::paint_view.
Usually you’ll call paint_view for every child view. But you might also draw text, adjust the offset, clip
or draw text.fn view_class(&self) -> Option<StyleClassRef>
Source§fn update(&mut self, cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
fn update(&mut self, cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
View’s Id handle Read moreSource§fn style_pass(&mut self, cx: &mut StyleCx<'_>)
fn style_pass(&mut self, cx: &mut StyleCx<'_>)
Source§fn layout(&mut self, cx: &mut LayoutCx<'_>) -> NodeId
fn layout(&mut self, cx: &mut LayoutCx<'_>) -> NodeId
LayoutCx::layout_node. Read moreSource§fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn event_before_children( &mut self, cx: &mut EventCx<'_>, event: &Event, ) -> EventPropagation
fn event_after_children( &mut self, cx: &mut EventCx<'_>, event: &Event, ) -> EventPropagation
Auto Trait Implementations§
impl !Freeze for TextEditor
impl !RefUnwindSafe for TextEditor
impl !Send for TextEditor
impl !Sync for TextEditor
impl Unpin for TextEditor
impl !UnwindSafe for TextEditor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ContainerExt for Twhere
T: IntoView + 'static,
impl<T> ContainerExt for Twhere
T: IntoView + 'static,
Source§impl<T> Decorators for Twhere
T: IntoView,
impl<T> Decorators for Twhere
T: IntoView,
Source§fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
fn style(self, style: impl Fn(Style) -> Style + 'static) -> Self::Intermediate
Source§fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
fn debug_name(self, name: impl Into<String>) -> Self::Intermediate
Source§fn debug_name_if<S: Into<String>>(
self,
apply: impl Fn() -> bool + 'static,
name: impl Fn() -> S + 'static,
) -> Self::Intermediate
fn debug_name_if<S: Into<String>>( self, apply: impl Fn() -> bool + 'static, name: impl Fn() -> S + 'static, ) -> Self::Intermediate
Source§fn dragging_style(
self,
style: impl Fn(Style) -> Style + 'static,
) -> Self::Intermediate
fn dragging_style( self, style: impl Fn(Style) -> Style + 'static, ) -> Self::Intermediate
Source§fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Source§fn class_if<C: StyleClass>(
self,
apply: impl Fn() -> bool + 'static,
_class: C,
) -> Self::Intermediate
fn class_if<C: StyleClass>( self, apply: impl Fn() -> bool + 'static, _class: C, ) -> Self::Intermediate
Source§fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
fn remove_class<C: StyleClass>(self, _class: C) -> Self::Intermediate
Style::focusable insteadSource§fn disable_default_event(
self,
disable: impl Fn() -> (EventListener, bool) + 'static,
) -> Self::Intermediate
fn disable_default_event( self, disable: impl Fn() -> (EventListener, bool) + 'static, ) -> Self::Intermediate
Source§fn draggable(self) -> Self::Intermediate
fn draggable(self) -> Self::Intermediate
Style::draggable directly insteadSource§fn disabled(
self,
disabled_fn: impl Fn() -> bool + 'static,
) -> Self::Intermediate
fn disabled( self, disabled_fn: impl Fn() -> bool + 'static, ) -> Self::Intermediate
Style::set_disabled directly insteadSource§fn on_event(
self,
listener: EventListener,
action: impl FnMut(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_event( self, listener: EventListener, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener.Source§fn on_key_down(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_key_down( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
Source§fn on_key_up(
self,
key: Key,
cmp: impl Fn(Modifiers) -> bool + 'static,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_key_up( self, key: Key, cmp: impl Fn(Modifiers) -> bool + 'static, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
Source§fn on_event_cont(
self,
listener: EventListener,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_event_cont( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_event_stop(
self,
listener: EventListener,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_event_stop( self, listener: EventListener, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_click(
self,
action: impl FnMut(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_click( self, action: impl FnMut(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::Click.Source§fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::Intermediate
fn on_click_cont(self, action: impl Fn(&Event) + 'static) -> Self::Intermediate
EventListener::Click. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_click_stop(
self,
action: impl FnMut(&Event) + 'static,
) -> Self::Intermediate
fn on_click_stop( self, action: impl FnMut(&Event) + 'static, ) -> Self::Intermediate
EventListener::Click. This event will be handled with
the given handler and the event will stop propagating.Source§fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
fn action(self, action: impl FnMut() + 'static) -> Self::Intermediate
Source§fn on_double_click(
self,
action: impl Fn(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_double_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::DoubleClickSource§fn on_double_click_cont(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_double_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::DoubleClick. This event will be handled with
the given handler and the event will continue propagating.Source§fn on_double_click_stop(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_double_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::DoubleClick. This event will be handled with
the given handler and the event will stop propagating.Source§fn on_secondary_click(
self,
action: impl Fn(&Event) -> EventPropagation + 'static,
) -> Self::Intermediate
fn on_secondary_click( self, action: impl Fn(&Event) -> EventPropagation + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.Source§fn on_secondary_click_cont(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_secondary_click_cont( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will continue propagating.Source§fn on_secondary_click_stop(
self,
action: impl Fn(&Event) + 'static,
) -> Self::Intermediate
fn on_secondary_click_stop( self, action: impl Fn(&Event) + 'static, ) -> Self::Intermediate
EventListener::SecondaryClick. This is most often the “Right” click.
This event will be handled with the given handler and the event will stop propagating.Source§fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::Intermediate
fn on_resize(self, action: impl Fn(Rect) + 'static) -> Self::Intermediate
Source§fn on_move(self, action: impl Fn(Point) + 'static) -> Self::Intermediate
fn on_move(self, action: impl Fn(Point) + 'static) -> Self::Intermediate
Source§fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
fn on_cleanup(self, action: impl Fn() + 'static) -> Self::Intermediate
Source§fn animation(
self,
animation: impl Fn(Animation) -> Animation + 'static,
) -> Self::Intermediate
fn animation( self, animation: impl Fn(Animation) -> Animation + 'static, ) -> Self::Intermediate
Source§fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn clear_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Source§fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
fn request_focus(self, when: impl Fn() + 'static) -> Self::Intermediate
Source§fn window_scale(
self,
scale_fn: impl Fn() -> f64 + 'static,
) -> Self::Intermediate
fn window_scale( self, scale_fn: impl Fn() -> f64 + 'static, ) -> Self::Intermediate
Source§fn window_title(
self,
title_fn: impl Fn() -> String + 'static,
) -> Self::Intermediate
fn window_title( self, title_fn: impl Fn() -> String + 'static, ) -> Self::Intermediate
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more