CodeEditor

Struct CodeEditor 

Source
pub struct CodeEditor { /* private fields */ }
Expand description

Canvas-based high-performance text editor.

Implementations§

Source§

impl CodeEditor

Source

pub fn update(&mut self, message: &Message) -> Task<Message>

Updates the editor state based on messages and returns scroll commands.

§Arguments
  • message - The message to process
§Returns

A Task that may contain scroll commands to keep cursor visible

Source§

impl CodeEditor

Source

pub fn view(&self) -> Element<'_, Message>

Creates the view element with scrollable wrapper.

Source§

impl CodeEditor

Source

pub fn new(content: &str, syntax: &str) -> Self

Creates a new canvas-based text editor.

§Arguments
  • content - Initial text content
  • syntax - Syntax highlighting language (e.g., “py”, “lua”, “rs”)
§Returns

A new CodeEditor instance

Source

pub fn content(&self) -> String

Returns the current text content as a string.

§Returns

The complete text content of the editor

Source

pub fn with_viewport_height(self, height: f32) -> Self

Sets the viewport height for the editor.

This determines the minimum height of the canvas, ensuring proper background rendering even when content is smaller than the viewport.

§Arguments
  • height - The viewport height in pixels
§Returns

Self for method chaining

§Example
use iced_code_editor::CodeEditor;

let editor = CodeEditor::new("fn main() {}", "rs")
    .with_viewport_height(500.0);
Source

pub fn set_theme(&mut self, style: Style)

Sets the theme style for the editor.

§Arguments
  • style - The style to apply to the editor
§Example
use iced_code_editor::{CodeEditor, theme};

let mut editor = CodeEditor::new("fn main() {}", "rs");
editor.set_theme(theme::light(&iced::Theme::Light));
Source

pub fn is_modified(&self) -> bool

Returns whether the editor has unsaved changes.

§Returns

true if there are unsaved modifications, false otherwise

Source

pub fn mark_saved(&mut self)

Marks the current state as saved.

Call this after successfully saving the file to reset the modified state.

Source

pub fn can_undo(&self) -> bool

Returns whether undo is available.

Source

pub fn can_redo(&self) -> bool

Returns whether redo is available.

Trait Implementations§

Source§

impl Program<Message> for CodeEditor

Source§

type State = ()

The internal state mutated by the Program.
Source§

fn draw( &self, _state: &Self::State, renderer: &Renderer, _theme: &Theme, bounds: Rectangle, _cursor: Cursor, ) -> Vec<Geometry>

Draws the state of the Program, producing a bunch of Geometry. Read more
Source§

fn update( &self, _state: &mut Self::State, event: &Event, bounds: Rectangle, cursor: Cursor, ) -> Option<Action<Message>>

Updates the State of the Program. Read more
Source§

fn mouse_interaction( &self, _state: &Self::State, _bounds: Rectangle, _cursor: Cursor, ) -> Interaction

Returns the current mouse interaction of the Program. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<State, Message> IntoBoot<State, Message> for State

Source§

fn into_boot(self) -> (State, Task<Message>)

Turns some type into the initial state of some Application.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeClone for T

Source§

impl<T> MaybeDebug for T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,