scroll bar size for small area

This commit is contained in:
Dongdong Zhou 2022-03-24 10:52:40 +00:00
parent 6aae20705b
commit 52a3f0ef8c
6 changed files with 56 additions and 24 deletions

View File

@ -79,6 +79,8 @@ impl LapceTheme {
pub const INPUT_LINE_HEIGHT: druid::Key<f64> =
druid::Key::new("lapce.input_line_height");
pub const INPUT_LINE_PADDING: druid::Key<f64> =
druid::Key::new("lapce.input_line_padding");
pub const INPUT_FONT_SIZE: druid::Key<u64> =
druid::Key::new("lapce.input_font_size");
}

View File

@ -127,8 +127,11 @@ pub fn load(event_sink: ExtEventSink) -> Self {
pub fn reload_env(&self, env: &mut Env) {
env.set(theme::SCROLLBAR_WIDTH, 10.0);
env.set(theme::SCROLLBAR_EDGE_WIDTH, 0.0);
env.set(theme::SCROLLBAR_PAD, 0.0);
env.set(theme::SCROLLBAR_MAX_OPACITY, 0.7);
env.set(LapceTheme::INPUT_LINE_HEIGHT, 20.0);
env.set(LapceTheme::INPUT_LINE_PADDING, 5.0);
env.set(LapceTheme::INPUT_FONT_SIZE, 13u64);
}

View File

@ -244,7 +244,8 @@ pub fn get_size(
| LocalBufferKind::Settings
| LocalBufferKind::Keymap => Size::new(
editor_size.width.max(width * self.buffer.rope.len() as f64),
env.get(LapceTheme::INPUT_LINE_HEIGHT),
env.get(LapceTheme::INPUT_LINE_HEIGHT)
+ env.get(LapceTheme::INPUT_LINE_PADDING) * 2.0,
),
LocalBufferKind::SourceControl => {
for (pos, panels) in panels.iter() {
@ -278,7 +279,8 @@ pub fn get_size(
},
BufferContent::Value(_) => Size::new(
editor_size.width.max(width * self.buffer.rope.len() as f64),
env.get(LapceTheme::INPUT_LINE_HEIGHT),
env.get(LapceTheme::INPUT_LINE_HEIGHT)
+ env.get(LapceTheme::INPUT_LINE_PADDING) * 2.0,
),
}
}
@ -2122,6 +2124,7 @@ pub fn paint_content(
env: &Env,
) {
let line_height = self.line_height(env);
let line_padding = self.line_padding(env);
let font_size = if self.editor.content.is_input() {
env.get(LapceTheme::INPUT_FONT_SIZE) as usize
@ -2397,7 +2400,10 @@ pub fn paint_content(
);
ctx.draw_text(
&text_layout,
Point::new(0.0, line_height * line as f64 + y_shift),
Point::new(
0.0,
line_height * line as f64 + y_shift + line_padding,
),
);
}
}
@ -2762,6 +2768,14 @@ fn line_height(&self, env: &Env) -> f64 {
}
}
fn line_padding(&self, env: &Env) -> f64 {
if self.editor.content.is_input() {
env.get(LapceTheme::INPUT_LINE_PADDING)
} else {
0.0
}
}
fn paint_cursor(
&self,
ctx: &mut PaintCtx,
@ -2772,6 +2786,7 @@ fn paint_cursor(
env: &Env,
) {
let line_height = self.line_height(env);
let line_padding = self.line_padding(env);
let start_line =
(self.editor.scroll_offset.y / line_height).floor() as usize;
let end_line = ((self.editor.size.borrow().height
@ -2789,7 +2804,10 @@ fn paint_cursor(
let char_width = if x1 > x0 { x1 - x0 } else { width };
ctx.fill(
Rect::ZERO
.with_origin(Point::new(x0, line as f64 * line_height))
.with_origin(Point::new(
x0,
line as f64 * line_height + line_padding,
))
.with_size(Size::new(char_width, line_height)),
self.config.get_color_unchecked(LapceTheme::EDITOR_CARET),
);
@ -2873,7 +2891,7 @@ fn paint_cursor(
if !line_content.is_empty() {
let x1 = right_col as f64 * width;
let y0 = line as f64 * line_height;
let y0 = line as f64 * line_height + line_padding;
let y1 = y0 + line_height;
ctx.fill(
Rect::new(x0, y0, x1, y1),
@ -2895,7 +2913,7 @@ fn paint_cursor(
Rect::ZERO
.with_origin(Point::new(
x0,
line as f64 * line_height,
line as f64 * line_height + line_padding,
))
.with_size(Size::new(char_width, line_height)),
self.config
@ -2964,7 +2982,7 @@ fn paint_cursor(
if !line_content.is_empty() {
let x1 = right_col as f64 * width;
let y0 = line as f64 * line_height;
let y0 = line as f64 * line_height + line_padding;
let y1 = y0 + line_height;
ctx.fill(
Rect::new(x0, y0, x1, y1),
@ -2984,7 +3002,7 @@ fn paint_cursor(
self.config.editor.tab_width,
);
let x = col as f64 * width;
let y = line as f64 * line_height;
let y = line as f64 * line_height + line_padding;
ctx.stroke(
Line::new(
Point::new(x, y),

View File

@ -1782,20 +1782,25 @@ fn layout(
fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {
let editor = data.main_split.editors.get(&self.view_id).unwrap();
if editor.content.is_special() {
let size = ctx.size();
ctx.fill(
size.to_rect().inflate(5.0, 5.0),
data.config
.get_color_unchecked(LapceTheme::EDITOR_BACKGROUND),
);
}
if editor.content.is_input() {
let size = ctx.size();
ctx.stroke(
size.to_rect().inflate(4.5, 4.5),
data.config.get_color_unchecked(LapceTheme::LAPCE_BORDER),
1.0,
);
let rect = ctx.size().to_rect();
if editor.content.is_input() {
ctx.fill(
rect.inflate(5.0, 0.0),
data.config
.get_color_unchecked(LapceTheme::EDITOR_BACKGROUND),
);
ctx.stroke(
rect.inflate(4.5, -0.5),
data.config.get_color_unchecked(LapceTheme::LAPCE_BORDER),
1.0,
);
} else {
ctx.fill(
rect.inflate(5.0, 5.0),
data.config
.get_color_unchecked(LapceTheme::EDITOR_BACKGROUND),
);
}
}
self.editor.paint(ctx, data, env);

View File

@ -23,7 +23,7 @@ pub fn new(view_id: WidgetId, parent_view_id: WidgetId) -> Self {
let input = LapceEditorView::new(view_id, None)
.hide_header()
.hide_gutter()
.padding((10.0, 10.0));
.padding((10.0, 5.0));
let icons = vec![
LapceIcon {
icon: "arrow-up.svg".to_string(),

View File

@ -543,7 +543,11 @@ pub fn calc_horizontal_bar_bounds(
return None;
}
let bar_width = env.get(theme::SCROLLBAR_WIDTH);
let bar_width = if viewport_size.height < 40.0 {
5.0
} else {
env.get(theme::SCROLLBAR_WIDTH)
};
let bar_pad = env.get(theme::SCROLLBAR_PAD);
let percent_visible = viewport_size.width / content_size.width;