header paint

This commit is contained in:
Dongdong Zhou 2021-07-30 16:16:04 +01:00
parent 4535ca14b9
commit 855bb49313
2 changed files with 66 additions and 9 deletions

View File

@ -890,6 +890,7 @@ pub fn save_jump_location(&mut self, buffer: &BufferNew) {
#[derive(Clone, Data, Lens)] #[derive(Clone, Data, Lens)]
pub struct LapceEditorViewData { pub struct LapceEditorViewData {
pub main_split: LapceMainSplitData, pub main_split: LapceMainSplitData,
pub workspace: Arc<LapceWorkspace>,
pub proxy: Arc<LapceProxy>, pub proxy: Arc<LapceProxy>,
pub editor: Arc<LapceEditorData>, pub editor: Arc<LapceEditorData>,
pub buffer: Arc<BufferNew>, pub buffer: Arc<BufferNew>,
@ -1706,6 +1707,7 @@ fn with<V, F: FnOnce(&LapceEditorViewData) -> V>(
.clone(); .clone();
let editor_view = LapceEditorViewData { let editor_view = LapceEditorViewData {
buffer: main_split.open_files.get(&editor.buffer).unwrap().clone(), buffer: main_split.open_files.get(&editor.buffer).unwrap().clone(),
workspace: data.workspace.clone(),
editor: editor.clone(), editor: editor.clone(),
main_split: main_split.clone(), main_split: main_split.clone(),
diagnostics, diagnostics,
@ -1734,6 +1736,7 @@ fn with_mut<V, F: FnOnce(&mut LapceEditorViewData) -> V>(
.clone(); .clone();
let mut editor_view = LapceEditorViewData { let mut editor_view = LapceEditorViewData {
buffer, buffer,
workspace: data.workspace.clone(),
editor: editor.clone(), editor: editor.clone(),
diagnostics: diagnostics.clone(), diagnostics: diagnostics.clone(),
all_diagnostics: data.diagnostics.clone(), all_diagnostics: data.diagnostics.clone(),

View File

@ -1,5 +1,6 @@
use crate::find::Find; use crate::find::Find;
use crate::signature::SignatureState; use crate::signature::SignatureState;
use crate::svg::file_svg_new;
use crate::{buffer::get_word_property, state::LapceFocus}; use crate::{buffer::get_word_property, state::LapceFocus};
use crate::{buffer::matching_char, data::LapceEditorViewData}; use crate::{buffer::matching_char, data::LapceEditorViewData};
use crate::{buffer::previous_has_unmatched_pair, movement::Cursor}; use crate::{buffer::previous_has_unmatched_pair, movement::Cursor};
@ -216,12 +217,12 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) {
for rect in &rects { for rect in &rects {
ctx.fill(rect, &env.get(LapceTheme::EDITOR_BACKGROUND)); ctx.fill(rect, &env.get(LapceTheme::EDITOR_BACKGROUND));
} }
self.header.paint(ctx, data, env);
let start = std::time::SystemTime::now(); let start = std::time::SystemTime::now();
self.editor.paint(ctx, data, env); self.editor.paint(ctx, data, env);
let end = std::time::SystemTime::now(); let end = std::time::SystemTime::now();
let duration = end.duration_since(start).unwrap().as_micros(); let duration = end.duration_since(start).unwrap().as_micros();
// println!("editor paint took {}", duration); // println!("editor paint took {}", duration);
self.header.paint(ctx, data, env);
} }
} }
@ -538,8 +539,8 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) {
for rect in &rects { for rect in &rects {
ctx.fill(rect, &env.get(LapceTheme::EDITOR_BACKGROUND)); ctx.fill(rect, &env.get(LapceTheme::EDITOR_BACKGROUND));
} }
self.gutter.paint(ctx, data, env);
self.editor.paint(ctx, data, env); self.editor.paint(ctx, data, env);
self.gutter.paint(ctx, data, env);
} }
} }
@ -592,21 +593,70 @@ fn layout(
data: &LapceEditorViewData, data: &LapceEditorViewData,
env: &Env, env: &Env,
) -> Size { ) -> Size {
Size::new(bc.max().width, 25.0) ctx.set_paint_insets((0.0, 0.0, 0.0, 10.0));
let line_height = env.get(LapceTheme::EDITOR_LINE_HEIGHT);
Size::new(bc.max().width, line_height)
} }
fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) { fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) {
let text = format!( let blur_color = Color::grey8(180);
"{}{}", let shadow_width = 5.0;
if data.buffer.dirty { "* " } else { "" }, let rect = ctx.size().to_rect();
data.editor.buffer.to_str().unwrap() ctx.blurred_rect(rect, shadow_width, &blur_color);
ctx.fill(rect, &env.get(LapceTheme::EDITOR_BACKGROUND));
let path = data.editor.buffer.clone();
let svg = file_svg_new(
&path
.extension()
.and_then(|s| s.to_str())
.unwrap_or("")
.to_string(),
); );
let mut text_layout = TextLayout::<String>::from_text(text);
let line_height = env.get(LapceTheme::EDITOR_LINE_HEIGHT);
if let Some(svg) = svg.as_ref() {
let width = 13.0;
let height = 13.0;
let rect = Size::new(width, height).to_rect().with_origin(Point::new(
(line_height - width) / 2.0 + 5.0,
(line_height - height) / 2.0,
));
svg.paint(ctx, rect, None);
}
let mut file_name = path
.file_name()
.and_then(|s| s.to_str())
.unwrap_or("")
.to_string();
if data.buffer.dirty {
file_name += " *"
}
let mut text_layout = TextLayout::<String>::from_text(file_name);
text_layout text_layout
.set_font(FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0)); .set_font(FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0));
text_layout.set_text_color(LapceTheme::EDITOR_FOREGROUND); text_layout.set_text_color(LapceTheme::EDITOR_FOREGROUND);
text_layout.rebuild_if_needed(ctx.text(), env); text_layout.rebuild_if_needed(ctx.text(), env);
text_layout.draw(ctx, Point::new(10.0, 5.0)); text_layout.draw(ctx, Point::new(5.0 + line_height, 5.0));
let path = path.strip_prefix(&data.workspace.path).unwrap_or(&path);
let folder = path
.parent()
.and_then(|s| s.to_str())
.unwrap_or("")
.to_string();
if folder != "" {
let x = text_layout.size().width;
let mut text_layout = TextLayout::<String>::from_text(folder);
text_layout.set_font(
FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(13.0),
);
text_layout.set_text_color(LapceTheme::EDITOR_COMMENT);
text_layout.rebuild_if_needed(ctx.text(), env);
text_layout.draw(ctx, Point::new(5.0 + line_height + x + 5.0, 5.0));
}
} }
} }
@ -1252,6 +1302,10 @@ fn update(
ctx.request_paint(); ctx.request_paint();
} }
if old_data.diagnostics.len() != data.diagnostics.len() {
ctx.request_paint();
}
if (*old_data.main_split.active == self.view_id if (*old_data.main_split.active == self.view_id
&& *data.main_split.active != self.view_id) && *data.main_split.active != self.view_id)
|| (*old_data.main_split.active != self.view_id || (*old_data.main_split.active != self.view_id