use super::editor::{decimal_digits, CodeEditor};
use super::grid::{LineGrid, RowLayout};
use super::types::{
MarkerSeverity, SearchMatch, SyntaxPalette, TextPosition, TokenKind, MIN_TOUCH_TARGET,
};
use crate::core::{Color, Font, HorizontalAlignment, Point, Rect};
use crate::render::{RenderContext, TEXT_FIT_MARGIN};
use crate::widget::metrics::effective_font;
use crate::widget::text_utils::floor_char_boundary;
use crate::widget::{Draw, Widget};
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
mod caret;
mod chrome;
mod diagnostics;
mod metrics;
mod minimap_status;
mod panels;
mod popups;
mod rows;
pub(crate) use chrome::TabSlot;
use chrome::{EditorChrome, RowGeometry};
pub(super) use chrome::{
TAB_CLOSE_SLOT, TAB_LEFT_PAD, TAB_MARKER_SLOT, TAB_MAX_WIDTH, TAB_MIN_WIDTH,
};
pub(super) use metrics::{row_height_of, GUTTER_LEFT_PAD};
fn font_family_hash(family: &str) -> u64 {
let mut hash = 0xcbf2_9ce4_8422_2325u64;
for byte in family.as_bytes() {
hash ^= u64::from(*byte);
hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
}
hash
}
impl Draw for CodeEditor {
fn draw(&mut self, context: &mut RenderContext) {
self.measure_cell_width(context);
self.refresh_visible_rows();
self.prepare_visible_line_cache();
self.prepare_minimap();
self.prepare_occurrences();
let layout_key = (
self.revision(),
font_family_hash(&self.config.font_family),
self.config.font_size.to_bits(),
self.config.tab_width,
self.cell_width().to_bits(),
self.geometry().width,
self.active_language(),
self.layout_lexer_generation,
);
if self.row_layout_key.get() != layout_key {
self.row_layouts.borrow_mut().clear();
self.row_layout_key.set(layout_key);
}
let rect = self.geometry();
let row_height = self.line_height();
let chrome = EditorChrome::resolve(self);
context.fill_rect(rect, chrome.surface);
context.draw_rect(rect, chrome.border);
self.draw_tab_strip(context, rect, &chrome);
self.draw_find_bar(context, rect, &chrome);
self.draw_gutter(context, rect, &chrome);
let mut visible = self.draw_source_rows(context, rect, row_height, &chrome);
self.draw_column_ruler(context, rect, &chrome);
self.draw_diagnostics(context, &visible, &chrome);
visible.clear();
self.draw_scrollbar(context, rect, &chrome);
self.draw_minimap(context, rect, &chrome);
self.draw_status_bar(context, rect, &chrome);
self.draw_preedit(context, rect, &chrome);
self.draw_completion(context, &chrome);
self.draw_context_menu(context, &chrome);
}
}