pub struct CodeEditor { /* private fields */ }Expand description
A source code editor: monospaced, no wrapping, line numbers, colors for the
language, Tab and Shift+Tab to indent, and Enter keeping the indentation. Ctrl or Cmd
with Enter is left to shortcuts, so a surrounding Playground can run the
code. Diagnostics mark their lines and underline what they cover.
use ravenrs_reactive::State;
use ravenrs_widgets::{CodeDiagnostic, CodeEditor, Ui};
let source = State::new("fn main() {\n println!(\"hi\");\n}".to_owned());
let editor = CodeEditor::new(source.binding())
.diagnostics(vec![CodeDiagnostic::error(2, 5, 8, "unknown macro")])
.rows(8);
let mut ui = Ui::new(editor, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl CodeEditor
impl CodeEditor
Sourcepub fn new(value: Binding<String>) -> CodeEditor
pub fn new(value: Binding<String>) -> CodeEditor
An editor of value, as Rust, with line numbers and an indent of 4 spaces.
Sourcepub fn language(self, language: CodeLanguage) -> CodeEditor
pub fn language(self, language: CodeLanguage) -> CodeEditor
The language it colors.
Sourcepub fn line_numbers(self, shown: bool) -> CodeEditor
pub fn line_numbers(self, shown: bool) -> CodeEditor
Shows or hides the line numbers.
Sourcepub fn diagnostics(self, diagnostics: Vec<CodeDiagnostic>) -> CodeEditor
pub fn diagnostics(self, diagnostics: Vec<CodeDiagnostic>) -> CodeEditor
Marks these places.
Sourcepub fn indent(self, spaces: usize) -> CodeEditor
pub fn indent(self, spaces: usize) -> CodeEditor
How many spaces Tab inserts; at least 1.
Sourcepub fn rows(self, rows: usize) -> CodeEditor
pub fn rows(self, rows: usize) -> CodeEditor
How many lines are visible; more scroll. 12 by default.
Sourcepub fn fill(self) -> CodeEditor
pub fn fill(self) -> CodeEditor
Takes the height its parent gives, instead of Self::rows.
Sourcepub fn read_only(self, read_only: bool) -> CodeEditor
pub fn read_only(self, read_only: bool) -> CodeEditor
Shows the code without letting it change; it can still be selected and copied.
Trait Implementations§
Source§impl Debug for CodeEditor
impl Debug for CodeEditor
Auto Trait Implementations§
impl !RefUnwindSafe for CodeEditor
impl !Send for CodeEditor
impl !Sync for CodeEditor
impl !UnwindSafe for CodeEditor
impl Freeze for CodeEditor
impl Unpin for CodeEditor
impl UnsafeUnpin for CodeEditor
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Adds padding inside the box, in logical pixels.
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Paints a background behind the content.
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
Fixes the width and/or height in logical pixels;
None keeps the content size.