Refactor scrollbar width handling for editor example

This commit is contained in:
Nico Burns 2024-03-04 11:34:40 +13:00 • committed by Jeremy Soller
parent 43d3620e44
commit 9615978557

View file

@ -29,6 +29,7 @@ fn main() {
let mut display_scale = window.scale_factor() as f32; let mut display_scale = window.scale_factor() as f32;
let scrollbar_width = 12.0;
let font_sizes = [ let font_sizes = [
Metrics::new(10.0, 14.0), // Caption Metrics::new(10.0, 14.0), // Caption
Metrics::new(14.0, 20.0), // Body Metrics::new(14.0, 20.0), // Body
@ -40,8 +41,6 @@ fn main() {
let font_size_default = 1; // Body let font_size_default = 1; // Body
let mut font_size_i = font_size_default; let mut font_size_i = font_size_default;
let line_x = 8.0 * (window.scale_factor() as f32);
let mut editor = SyntaxEditor::new( let mut editor = SyntaxEditor::new(
Buffer::new( Buffer::new(
&mut font_system, &mut font_system,
@ -110,8 +109,10 @@ fn main() {
pixmap.fill(tiny_skia::Color::from_rgba8(0, 0, 0, 0xFF)); pixmap.fill(tiny_skia::Color::from_rgba8(0, 0, 0, 0xFF));
editor.with_buffer_mut(|buffer| { editor.with_buffer_mut(|buffer| {
buffer buffer.set_size(
.set_size(width as f32 - line_x * display_scale, height as f32) width as f32 - scrollbar_width * display_scale,
height as f32,
)
}); });
let mut paint = Paint::default(); let mut paint = Paint::default();
@ -151,9 +152,9 @@ fn main() {
if end_y > start_y { if end_y > start_y {
pixmap.fill_rect( pixmap.fill_rect(
Rect::from_xywh( Rect::from_xywh(
width as f32 - line_x * display_scale, width as f32 - scrollbar_width * display_scale,
start_y as f32, start_y as f32,
line_x * display_scale, scrollbar_width * display_scale,
(end_y - start_y) as f32, (end_y - start_y) as f32,
) )
.unwrap(), .unwrap(),
@ -296,7 +297,7 @@ fn main() {
&& mouse_left == ElementState::Released && mouse_left == ElementState::Released
{ {
editor.action(Action::Click { editor.action(Action::Click {
x: mouse_x /*- line_x*/ as i32, x: mouse_x as i32,
y: mouse_y as i32, y: mouse_y as i32,
}); });
window.request_redraw(); window.request_redraw();