Skip to content

Commit 242967f

Browse files
committed
minor and mostly cosmetic changes
1 parent 10cf4d1 commit 242967f

2 files changed

Lines changed: 41 additions & 53 deletions

File tree

src/pix_grid.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ macro_rules! unscale {
1111
};
1212
}
1313

14-
macro_rules! width {
15-
( $e: expr ) => {
16-
unscale!($e.width())
17-
};
18-
}
19-
2014
#[derive(Default, Debug)]
2115
pub struct PixModel {
2216
pub matrix: PixMatrix,
@@ -47,14 +41,13 @@ impl PixModel {
4741
let pix_line = &mut self.matrix[row];
4842
pix_line.fill(space_width);
4943
let mut last_non_space: usize = sign_column;
50-
// TODO optimize with filter/map/filter_map/flat_map?
51-
for col in sign_column..self.columns {
44+
for col in sign_column..pix_line.len() {
5245
for item in &line.item_line[col] {
5346
let glyphs = item.glyphs();
5447
if glyphs.is_some() {
5548
for glyph_string in glyphs.iter() {
5649
let n = glyph_string.num_glyphs();
57-
pix_line[col] = width!(glyph_string);
50+
pix_line[col] = unscale!(glyph_string.width());
5851
last_non_space = col + n as usize;
5952
if n > 1 {
6053
/* when multiple glyphs are computed as one, we set the
@@ -123,7 +116,6 @@ pub fn cursor_x(
123116
let mut col: usize = sign_column_len;
124117
let mut cursor_width: f32 = space_width;
125118
let mut word_width_until: f32 = 0.0;
126-
// TODO optimize. see `PixModel.update()`
127119
'l: loop {
128120
for item in &line.item_line[col] {
129121
let glyphs = item.glyphs();
@@ -135,12 +127,12 @@ pub fn cursor_x(
135127
if m > 0 {
136128
let mut new_glyph = glyph_string.clone();
137129
new_glyph.set_size(m as i32);
138-
let w = width!(new_glyph);
130+
let w = unscale!(new_glyph.width());
139131
x += w;
140132
word_width_until = w;
141133
n_glyphs += m;
142134
if let Some(c) = glyph_string.glyph_info().iter().nth(m) {
143-
cursor_width = width!(c.geometry());
135+
cursor_width = unscale!(c.geometry().width());
144136
}
145137
}
146138
break 'l;
@@ -150,7 +142,7 @@ pub fn cursor_x(
150142
* but ensure that it's computed the same way as it is for
151143
* line drawing
152144
* */
153-
x += width!(glyph_string);
145+
x += unscale!(glyph_string.width());
154146
}
155147
}
156148
}

src/render/mod.rs

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,26 @@ impl<'a> RenderStep<'a> {
3636
}
3737
}
3838

39-
// (until match_arm_wrapping stabilizes https://github.com/rust-lang/rustfmt/pull/4924 )
40-
#[rustfmt::skip]
4139
fn to_snapshot(
4240
self,
4341
snapshot: &gtk::Snapshot,
4442
cell_metrics: &CellMetrics,
4543
line_x: &PixLine,
46-
start_x: f32,
44+
start_x: f64,
4745
) {
48-
// TODO optimize
4946
let (start_row, start_col) = self.pos;
5047
let x = line_x[start_col] as f64;
5148
let y = start_row as f64 * cell_metrics.line_height;
5249
let len = line_x[start_col + self.len] as f64 - x;
53-
let x = start_x as f64 + x;
54-
let pos = (x, y);
55-
match self.kind {
56-
RenderStepKind::Background =>
57-
snapshot_bg(snapshot, cell_metrics, self.color, pos, len),
58-
RenderStepKind::Strikethrough =>
59-
snapshot_strikethrough(snapshot, cell_metrics, self.color, pos, len),
60-
RenderStepKind::Underline =>
61-
snapshot_underline(snapshot, cell_metrics, self.color, pos, len),
62-
RenderStepKind::Underdouble =>
63-
snapshot_underdouble(snapshot, cell_metrics, self.color, pos, len),
64-
RenderStepKind::Underdot =>
65-
snapshot_underdot(snapshot, cell_metrics, self.color, pos, len),
66-
RenderStepKind::Underdash =>
67-
snapshot_underdash(snapshot, cell_metrics, self.color, pos, len),
68-
}
50+
let f = match self.kind {
51+
RenderStepKind::Background => snapshot_bg,
52+
RenderStepKind::Strikethrough => snapshot_strikethrough,
53+
RenderStepKind::Underline => snapshot_underline,
54+
RenderStepKind::Underdouble => snapshot_underdouble,
55+
RenderStepKind::Underdot => snapshot_underdot,
56+
RenderStepKind::Underdash => snapshot_underdash,
57+
};
58+
f(snapshot, cell_metrics, self.color, start_x + x, y, len);
6959
}
7060

7161
#[inline]
@@ -163,7 +153,7 @@ fn snapshot_grid(
163153
// optimizing contiguous series of similar drawing operations (source: Company)
164154
let model = ui_model.model();
165155

166-
let start_x = grid.rect.0;
156+
let start_x = grid.rect.0 as f64;
167157
for (row, line) in model.iter().enumerate() {
168158
let mut pending_bg = None;
169159
let mut pending_strikethrough = None;
@@ -348,31 +338,34 @@ pub fn snapshot_cursor<T: CursorRedrawCb + 'static>(
348338
}
349339

350340
if cell.hl.strikethrough {
351-
snapshot_strikethrough(snapshot, cell_metrics, &fg, (x, y), clip_width);
341+
snapshot_strikethrough(snapshot, cell_metrics, &fg, x, y, clip_width);
352342
}
353343

354344
if cell.hl.underdashed {
355345
snapshot_underdash(
356346
snapshot,
357347
cell_metrics,
358348
&underline_color(cell, hl).fade(hl.bg(), fade_percentage),
359-
(x, y),
349+
x,
350+
y,
360351
clip_width,
361352
);
362353
} else if cell.hl.underdotted {
363354
snapshot_underdot(
364355
snapshot,
365356
cell_metrics,
366357
&underdotted_color(cell, hl).fade(hl.bg(), fade_percentage),
367-
(x, y),
358+
x,
359+
y,
368360
clip_width,
369361
);
370362
} else if cell.hl.underline {
371363
snapshot_underline(
372364
snapshot,
373365
cell_metrics,
374366
&underline_color(cell, hl).fade(hl.bg(), fade_percentage),
375-
(x, y),
367+
x,
368+
y,
376369
clip_width,
377370
);
378371
}
@@ -382,7 +375,8 @@ pub fn snapshot_cursor<T: CursorRedrawCb + 'static>(
382375
snapshot,
383376
cell_metrics,
384377
&underline_color(cell, hl).fade(hl.bg(), fade_percentage),
385-
(x, y),
378+
x,
379+
y,
386380
clip_width,
387381
);
388382
}
@@ -392,7 +386,8 @@ fn snapshot_strikethrough(
392386
snapshot: &gtk::Snapshot,
393387
cell_metrics: &CellMetrics,
394388
color: &color::Color,
395-
(x, y): (f64, f64),
389+
x: f64,
390+
y: f64,
396391
len: f64,
397392
) {
398393
snapshot.append_color(
@@ -419,7 +414,8 @@ fn snapshot_underline(
419414
snapshot: &gtk::Snapshot,
420415
cell_metrics: &CellMetrics,
421416
color: &color::Color,
422-
(x, y): (f64, f64),
417+
x: f64,
418+
y: f64,
423419
len: f64,
424420
) {
425421
snapshot.append_color(&color.into(), &underline_rect(cell_metrics, (x, y), len))
@@ -429,15 +425,16 @@ fn snapshot_underdouble(
429425
snapshot: &gtk::Snapshot,
430426
cell_metrics: &CellMetrics,
431427
color: &color::Color,
432-
pos: (f64, f64),
428+
x: f64,
429+
y: f64,
433430
len: f64,
434431
) {
435432
/* We only need to handle the lower underline, the upper underline will be drawn by
436433
* snapshot_underline()
437434
*/
438435
snapshot.append_color(
439436
&color.into(),
440-
&underline_rect(cell_metrics, pos, len)
437+
&underline_rect(cell_metrics, (x, y), len)
441438
.offset_r(0.0, (cell_metrics.underline_thickness * 2.0) as f32),
442439
)
443440
}
@@ -446,7 +443,8 @@ fn snapshot_underdot(
446443
snapshot: &gtk::Snapshot,
447444
cell_metrics: &CellMetrics,
448445
color: &color::Color,
449-
(x, mut y): (f64, f64),
446+
x: f64,
447+
mut y: f64,
450448
len: f64,
451449
) {
452450
let CellMetrics {
@@ -494,7 +492,8 @@ fn snapshot_underdash(
494492
snapshot: &gtk::Snapshot,
495493
cell_metrics: &CellMetrics,
496494
color: &color::Color,
497-
(x, mut y): (f64, f64),
495+
x: f64,
496+
mut y: f64,
498497
len: f64,
499498
) {
500499
let CellMetrics {
@@ -546,9 +545,9 @@ fn plan_and_snapshot_cell_bg<'a>(
546545
hl: &'a HighlightMap,
547546
cell: &'a ui_model::Cell,
548547
cell_metrics: &CellMetrics,
549-
(row, col): (usize, usize),
548+
pos: (usize, usize),
550549
line_x: &PixLine,
551-
start_x: f32,
550+
start_x: f64,
552551
) {
553552
if let Some(cell_bg) = hl.cell_bg(cell).filter(|bg| *bg != hl.bg()) {
554553
if let Some(cur_pending_bg) = pending_bg {
@@ -557,11 +556,7 @@ fn plan_and_snapshot_cell_bg<'a>(
557556
}
558557
cur_pending_bg.to_snapshot(snapshot, cell_metrics, line_x, start_x);
559558
}
560-
*pending_bg = Some(RenderStep::new(
561-
RenderStepKind::Background,
562-
cell_bg,
563-
(row, col),
564-
));
559+
*pending_bg = Some(RenderStep::new(RenderStepKind::Background, cell_bg, pos));
565560
} else if let Some(pending_bg) = pending_bg.take() {
566561
pending_bg.to_snapshot(snapshot, cell_metrics, line_x, start_x);
567562
}
@@ -637,7 +632,8 @@ fn snapshot_bg(
637632
snapshot: &gtk::Snapshot,
638633
cell_metrics: &CellMetrics,
639634
color: &color::Color,
640-
(x, y): (f64, f64),
635+
x: f64,
636+
y: f64,
641637
len: f64,
642638
) {
643639
snapshot.append_color(

0 commit comments

Comments
 (0)