Merge pull request #473 from bugadani/info

Display problem type icon in front of counter
This commit is contained in:
Dongdong Zhou 2022-05-07 10:13:27 +01:00 committed by GitHub
commit eeeca9ebd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 78 additions and 54 deletions

View File

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