diff --git a/lapce-ui/src/status.rs b/lapce-ui/src/status.rs index eeecddcc..8f27d517 100644 --- a/lapce-ui/src/status.rs +++ b/lapce-ui/src/status.rs @@ -1,12 +1,12 @@ use druid::{ piet::{Text, TextLayout, TextLayoutBuilder}, - Command, Event, EventCtx, FontFamily, MouseEvent, Point, RenderContext, Size, - Target, Widget, + Command, Event, EventCtx, FontFamily, MouseEvent, PaintCtx, Point, + RenderContext, Size, Target, Widget, }; use lapce_core::mode::Mode; use lapce_data::{ command::{CommandKind, LapceCommand, LapceWorkbenchCommand, LAPCE_COMMAND}, - config::LapceTheme, + config::{Config, LapceTheme}, data::{FocusArea, LapceTabData, PanelKind}, panel::PanelPosition, }; @@ -104,6 +104,46 @@ fn mouse_down(&self, ctx: &mut EventCtx, mouse_event: &MouseEvent) { } } } + + fn paint_icon_with_label( + &self, + left: f64, + height: f64, + icon: &str, + label: String, + ctx: &mut PaintCtx, + config: &Config, + ) -> f64 { + let fg_color = config.get_color_unchecked(LapceTheme::EDITOR_FOREGROUND); + + let text_layout = ctx + .text() + .new_text_layout(label) + .font(FontFamily::SYSTEM_UI, 13.0) + .text_color(fg_color.clone()) + .build() + .unwrap(); + + let icon_padding = (height - self.icon_size) / 2.0; + + let mut left = left; + + if let Some(warnings_icon) = get_svg(icon) { + let rect = Size::new(height, height) + .to_rect() + .inflate(-icon_padding, -icon_padding) + .with_origin(Point::new(left + 2.0 * icon_padding, icon_padding)); + ctx.draw_svg(&warnings_icon, rect, Some(fg_color)); + + left += icon_padding + height; + } + + ctx.draw_text( + &text_layout, + Point::new(left, (height - text_layout.size().height) / 2.0), + ); + left + text_layout.size().width + } } impl Default for LapceStatusNew { @@ -191,12 +231,7 @@ fn layout( self_size } - fn paint( - &mut self, - ctx: &mut druid::PaintCtx, - data: &LapceTabData, - _env: &druid::Env, - ) { + fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, _env: &druid::Env) { let size = ctx.size(); let rect = size.to_rect(); ctx.blurred_rect( @@ -214,29 +249,22 @@ fn paint( let mut left = 0.0; if data.config.lapce.modal { - let (mode, color) = { - let mode = if data.focus_area - == FocusArea::Panel(PanelKind::Terminal) - { - match data.terminal.terminals.get(&data.terminal.active_term_id) - { - Some(terminal) => terminal.mode, - None => Mode::Normal, - } - } else { - data.main_split - .active_editor() - .map(|e| e.new_cursor.get_mode()) - .unwrap_or(Mode::Normal) - }; - match mode { - Mode::Normal => ("Normal", LapceTheme::STATUS_MODAL_NORMAL), - Mode::Insert => ("Insert", LapceTheme::STATUS_MODAL_INSERT), - Mode::Visual => ("Visual", LapceTheme::STATUS_MODAL_VISUAL), - Mode::Terminal => { - ("Terminal", LapceTheme::STATUS_MODAL_TERMINAL) - } - } + let mode = if data.focus_area == FocusArea::Panel(PanelKind::Terminal) { + data.terminal + .terminals + .get(&data.terminal.active_term_id) + .map(|terminal| terminal.mode) + } else { + data.main_split + .active_editor() + .map(|e| e.new_cursor.get_mode()) + }; + + let (mode, color) = match mode.unwrap_or(Mode::Normal) { + Mode::Normal => ("Normal", LapceTheme::STATUS_MODAL_NORMAL), + Mode::Insert => ("Insert", LapceTheme::STATUS_MODAL_INSERT), + Mode::Visual => ("Visual", LapceTheme::STATUS_MODAL_VISUAL), + Mode::Terminal => ("Terminal", LapceTheme::STATUS_MODAL_TERMINAL), }; let text_layout = ctx @@ -260,32 +288,28 @@ fn paint( left += text_size.width + 10.0; } - let text_layout = ctx - .text() - .new_text_layout(format!( - "{} {}", - data.main_split.error_count, data.main_split.warning_count - )) - .font(FontFamily::SYSTEM_UI, 13.0) - .text_color( - data.config - .get_color_unchecked(LapceTheme::EDITOR_FOREGROUND) - .clone(), - ) - .build() - .unwrap(); - ctx.draw_text( - &text_layout, - Point::new(left + 10.0, (size.height - text_layout.size().height) / 2.0), + left = self.paint_icon_with_label( + left, + size.height, + "warning.svg", + data.main_split.warning_count.to_string(), + ctx, + &data.config, + ); + left = self.paint_icon_with_label( + left, + size.height, + "error.svg", + data.main_split.error_count.to_string(), + ctx, + &data.config, ); - left += 10.0 + text_layout.size().width; for progress in data.progresses.iter() { let mut text = progress.title.clone(); - let message = progress.message.clone().unwrap_or_else(|| "".to_string()); - if !message.is_empty() { + if let Some(message) = progress.message.as_ref() { text += ": "; - text += &message; + text += message; } let text_layout = ctx .text() @@ -308,7 +332,7 @@ fn paint( left += 10.0 + text_layout.size().width; } - let icon_padding = (self.height - self.icon_size) / 2.0; + let icon_padding = (size.height - self.icon_size) / 2.0; for icon in self.panel_icons.iter() { if icon.rect.contains(self.mouse_pos) { ctx.fill(