#[non_exhaustive]pub struct Editor {Show 24 fields
pub id: WidgetId,
pub rect: Rect,
pub lines: Vec<EditorLine>,
pub cursor: Option<EditorCursor>,
pub extra_cursors: Vec<CursorPos>,
pub selection: Option<EditorSelection>,
pub extra_selections: Vec<EditorSelection>,
pub yank_highlight: Option<EditorSelection>,
pub scroll_top: usize,
pub scroll_left: usize,
pub total_lines: usize,
pub max_col: usize,
pub gutter_char_width: usize,
pub is_active: bool,
pub show_active_bg: bool,
pub has_git_diff: bool,
pub has_breakpoints: bool,
pub diagnostic_gutter: HashMap<usize, DiagnosticSeverity>,
pub code_action_lines: HashSet<usize>,
pub bracket_match_positions: Vec<(usize, usize)>,
pub active_indent_col: Option<usize>,
pub tabstop: usize,
pub cursorline: bool,
pub lightbulb_glyph: char,
}Expand description
Declarative description of one editor viewport (window / pane).
Mirrors vimcode::render::RenderedWindow field-for-field.
Adding a field here is a breaking change — this struct is
#[non_exhaustive] to require use of Editor::new plus the
with_* builder methods (besides id/rect) and a Default impl.
§Examples
use quadraui::{Editor, EditorHit, EditorLine, Rect, WidgetId};
let line = EditorLine {
raw_text: "fn main() {}\n".to_string(),
gutter_text: " 1".to_string(),
spans: vec![],
line_idx: 0,
is_current_line: true,
is_fold_header: false,
folded_line_count: 0,
git_diff: None,
diff_status: None,
diagnostics: vec![],
spell_errors: vec![],
is_breakpoint: false,
is_conditional_bp: false,
is_dap_current: false,
is_wrap_continuation: false,
segment_col_offset: 0,
annotation: None,
ghost_suffix: None,
is_ghost_continuation: false,
indent_guides: vec![],
colorcolumns: vec![],
};
let rect = Rect::new(0.0, 0.0, 80.0, 24.0);
let editor = Editor::new(WidgetId::new("editor:main"), rect)
.with_lines(vec![line])
.with_total_lines(1)
.with_gutter_char_width(3);
let layout = editor.layout(rect, 1.0, 1.0);
match layout.hit_test(5.0, 0.0) {
EditorHit::BufferPos { line, .. } => assert_eq!(line, 0),
other => panic!("expected a buffer-position hit, got {other:?}"),
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: WidgetId§rect: RectPixel-space rectangle (used by GTK / Win-GUI; TUI ignores).
lines: Vec<EditorLine>Visible lines, one per row.
cursor: Option<EditorCursor>Primary cursor (position + shape). None when scrolled
off-screen.
extra_cursors: Vec<CursorPos>Secondary cursor positions for multi-cursor (Alt-D). Drawn as dimmed blocks.
selection: Option<EditorSelection>Active visual selection.
extra_selections: Vec<EditorSelection>Extra selections for Ctrl+D word-multi-cursor.
yank_highlight: Option<EditorSelection>Transient post-yank flash region. None when no flash active.
scroll_top: usizeIndex of the first visible buffer line.
scroll_left: usizeNumber of character columns scrolled horizontally.
total_lines: usizeTotal lines in the buffer (drives vertical scrollbar geometry).
max_col: usizeMax line length in the buffer (character cells, excl. trailing newline). Drives horizontal scrollbar.
gutter_char_width: usizeWidth of the line-number gutter in character cells (0 = no
gutter). GTK multiplies by char_width to get pixels.
is_active: boolWhether this is the focused window.
show_active_bg: boolWhether to render with the slightly-different active-window
background — only true when is_active AND there are multiple
windows. Drives the rasteriser’s choice between
theme.editor_active_background and theme.background.
has_git_diff: boolWhether the buffer has git diff data (controls git column).
has_breakpoints: boolWhether to show the breakpoint gutter column.
diagnostic_gutter: HashMap<usize, DiagnosticSeverity>Per-line worst diagnostic severity. Used for gutter icons.
code_action_lines: HashSet<usize>Lines with available LSP code actions (lightbulb gutter glyph).
bracket_match_positions: Vec<(usize, usize)>Bracket-pair positions to highlight (cursor bracket + match).
Each (view_line, col). Up to 2 entries.
active_indent_col: Option<usize>Indent-guide column highlighted as “active” (cursor’s scope).
tabstop: usizeTab stop width for expanding \t to spaces (TUI rendering).
cursorline: boolWhether to draw cursorline highlight.
lightbulb_glyph: charGlyph the rasteriser draws in the gutter for lines with an
available LSP code action. The host computes this from its
icon registry per frame so nerd-font / fallback toggles
propagate without the rasteriser depending on a host icon
module. Apps without code-action icons can leave this at
'\0' and the rasteriser skips painting.
Implementations§
Source§impl Editor
impl Editor
Sourcepub fn new(id: WidgetId, rect: Rect) -> Self
pub fn new(id: WidgetId, rect: Rect) -> Self
An editor viewport at rect with no lines, no cursor, and no
overlays — chain with_* to fill it in.
Sourcepub fn with_lines(self, lines: Vec<EditorLine>) -> Self
pub fn with_lines(self, lines: Vec<EditorLine>) -> Self
Replace Self::lines.
Sourcepub fn with_cursor(self, cursor: EditorCursor) -> Self
pub fn with_cursor(self, cursor: EditorCursor) -> Self
Set Self::cursor.
Sourcepub fn with_extra_cursors(self, extra_cursors: Vec<CursorPos>) -> Self
pub fn with_extra_cursors(self, extra_cursors: Vec<CursorPos>) -> Self
Replace Self::extra_cursors.
Sourcepub fn with_selection(self, selection: EditorSelection) -> Self
pub fn with_selection(self, selection: EditorSelection) -> Self
Set Self::selection.
Sourcepub fn with_extra_selections(
self,
extra_selections: Vec<EditorSelection>,
) -> Self
pub fn with_extra_selections( self, extra_selections: Vec<EditorSelection>, ) -> Self
Replace Self::extra_selections.
Sourcepub fn with_yank_highlight(self, yank_highlight: EditorSelection) -> Self
pub fn with_yank_highlight(self, yank_highlight: EditorSelection) -> Self
Set Self::yank_highlight.
Sourcepub fn with_scroll_top(self, scroll_top: usize) -> Self
pub fn with_scroll_top(self, scroll_top: usize) -> Self
Set Self::scroll_top.
Sourcepub fn with_scroll_left(self, scroll_left: usize) -> Self
pub fn with_scroll_left(self, scroll_left: usize) -> Self
Set Self::scroll_left.
Sourcepub fn with_total_lines(self, total_lines: usize) -> Self
pub fn with_total_lines(self, total_lines: usize) -> Self
Set Self::total_lines.
Sourcepub fn with_max_col(self, max_col: usize) -> Self
pub fn with_max_col(self, max_col: usize) -> Self
Set Self::max_col.
Sourcepub fn with_gutter_char_width(self, gutter_char_width: usize) -> Self
pub fn with_gutter_char_width(self, gutter_char_width: usize) -> Self
Sourcepub fn with_is_active(self, is_active: bool) -> Self
pub fn with_is_active(self, is_active: bool) -> Self
Set Self::is_active.
Sourcepub fn with_show_active_bg(self, show_active_bg: bool) -> Self
pub fn with_show_active_bg(self, show_active_bg: bool) -> Self
Set Self::show_active_bg.
Sourcepub fn with_has_git_diff(self, has_git_diff: bool) -> Self
pub fn with_has_git_diff(self, has_git_diff: bool) -> Self
Set Self::has_git_diff.
Sourcepub fn with_has_breakpoints(self, has_breakpoints: bool) -> Self
pub fn with_has_breakpoints(self, has_breakpoints: bool) -> Self
Sourcepub fn with_diagnostic_gutter(
self,
diagnostic_gutter: HashMap<usize, DiagnosticSeverity>,
) -> Self
pub fn with_diagnostic_gutter( self, diagnostic_gutter: HashMap<usize, DiagnosticSeverity>, ) -> Self
Replace Self::diagnostic_gutter.
Sourcepub fn with_code_action_lines(self, code_action_lines: HashSet<usize>) -> Self
pub fn with_code_action_lines(self, code_action_lines: HashSet<usize>) -> Self
Replace Self::code_action_lines.
Sourcepub fn with_bracket_match_positions(
self,
bracket_match_positions: Vec<(usize, usize)>,
) -> Self
pub fn with_bracket_match_positions( self, bracket_match_positions: Vec<(usize, usize)>, ) -> Self
Replace Self::bracket_match_positions.
Sourcepub fn with_active_indent_col(self, active_indent_col: usize) -> Self
pub fn with_active_indent_col(self, active_indent_col: usize) -> Self
Sourcepub fn with_tabstop(self, tabstop: usize) -> Self
pub fn with_tabstop(self, tabstop: usize) -> Self
Set Self::tabstop.
Sourcepub fn with_cursorline(self, cursorline: bool) -> Self
pub fn with_cursorline(self, cursorline: bool) -> Self
Set Self::cursorline.
Sourcepub fn with_lightbulb_glyph(self, lightbulb_glyph: char) -> Self
pub fn with_lightbulb_glyph(self, lightbulb_glyph: char) -> Self
Sourcepub fn layout(
&self,
viewport: Rect,
cell_width: f32,
line_height: f32,
) -> EditorLayout
pub fn layout( &self, viewport: Rect, cell_width: f32, line_height: f32, ) -> EditorLayout
Compute the viewport geometry for hit-testing and rendering layout.
§Arguments
viewport— the rectangle this editor occupies.cell_width— character advance width (1.0 for TUI, font px for GTK).line_height— row height (1.0 for TUI, font px for GTK).
Equivalent to Self::layout_with_options with
EditorPaintOptions::default() — kept as a separate, unchanged
method (rather than growing this one’s argument list) so every
existing caller keeps compiling untouched. See
EditorPaintOptions for why a new parameter here would be a
breaking change for both known downstream consumers.
Sourcepub fn layout_with_options(
&self,
viewport: Rect,
cell_width: f32,
line_height: f32,
options: EditorPaintOptions,
) -> EditorLayout
pub fn layout_with_options( &self, viewport: Rect, cell_width: f32, line_height: f32, options: EditorPaintOptions, ) -> EditorLayout
Self::layout, plus EditorPaintOptions a host can set to
override otherwise-automatic geometry decisions — currently just
suppress_v_scrollbar.
Equivalent to Self::layout_with_options_and_v_scrollbar_w with
v_scrollbar_w: None (a cell_width-wide scrollbar column).
Sourcepub fn layout_with_options_and_v_scrollbar_w(
&self,
viewport: Rect,
cell_width: f32,
line_height: f32,
options: EditorPaintOptions,
v_scrollbar_w: Option<f32>,
) -> EditorLayout
pub fn layout_with_options_and_v_scrollbar_w( &self, viewport: Rect, cell_width: f32, line_height: f32, options: EditorPaintOptions, v_scrollbar_w: Option<f32>, ) -> EditorLayout
Self::layout_with_options, plus a host-settable vertical
scrollbar width in the same pixel units as cell_width /
line_height.
Without an override the vertical scrollbar column is exactly
cell_width wide — right for TUI’s fixed-cell grid, but on a GUI
backend that ties the scrollbar’s width to the font’s glyph
advance rather than to a fixed chrome dimension. VS Code’s editor
scrollbar is a constant 14px column independent of font size.
Some(px) overrides just the scrollbar column’s width (both
v_scrollbar_bounds.width and the text-area narrowing it causes)
while every other geometry calculation keeps using cell_width.
None sizes the column at cell_width. Ignored (there is no
column to size) when options.suppress_v_scrollbar is true or
the buffer doesn’t overflow the viewport.
GUI hosts normally reach this through
crate::Backend::set_editor_v_scrollbar_width rather than
calling it directly.
Trait Implementations§
Source§impl Default for Editor
An editor viewport with no content and every optional/overlay field at
its empty default — the new(required…)/with_*/Default trio
that lets a consumer build an Editor without an
exhaustive struct literal. tabstop defaults to 4 and
lightbulb_glyph to '!', matching [default_lightbulb_glyph] and
every existing call site’s convention — not derived-Default’s 0
/ '\0'.
impl Default for Editor
An editor viewport with no content and every optional/overlay field at
its empty default — the new(required…)/with_*/Default trio
that lets a consumer build an Editor without an
exhaustive struct literal. tabstop defaults to 4 and
lightbulb_glyph to '!', matching [default_lightbulb_glyph] and
every existing call site’s convention — not derived-Default’s 0
/ '\0'.
Source§impl<'de> Deserialize<'de> for Editor
impl<'de> Deserialize<'de> for Editor
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Editor
Auto Trait Implementations§
impl Freeze for Editor
impl RefUnwindSafe for Editor
impl Send for Editor
impl Sync for Editor
impl Unpin for Editor
impl UnsafeUnpin for Editor
impl UnwindSafe for Editor
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
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