Skip to content

Commit 637269f

Browse files
committed
Don't draw backgrounds for domains that aren't visible
1 parent 4bb1490 commit 637269f

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

lib/render.ml

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -264,50 +264,52 @@ module Make (C : CANVAS) = struct
264264
let render_gc_events v cr (ring : Layout.Ring.t) layer =
265265
let y = y_of_row v ring.y in
266266
let h = float ring.height *. Style.line_spacing in
267-
let event = ref (0, 0.0, []) in
268-
C.set_font_size cr Style.big_text;
269-
ring |> iter_gc_spans v (fun event' ->
270-
let i, t0, stack = !event in
271-
let prev_stack = if i = 0 then [] else snd (ring.events.(i - 1)) in
272-
event := event';
273-
let _, t1, _ = event' in
274-
let x0 = View.x_of_time v t0 in
275-
let x1 = View.x_of_time v t1 in
276-
let w = x1 -. x0 in
277-
begin match stack with
278-
| [] -> ()
279-
| Suspend op :: p ->
280-
begin match layer with
267+
if y <= v.height && y +. h >= 0. then(
268+
let event = ref (0, 0.0, []) in
269+
C.set_font_size cr Style.big_text;
270+
ring |> iter_gc_spans v (fun event' ->
271+
let i, t0, stack = !event in
272+
let prev_stack = if i = 0 then [] else snd (ring.events.(i - 1)) in
273+
event := event';
274+
let _, t1, _ = event' in
275+
let x0 = View.x_of_time v t0 in
276+
let x1 = View.x_of_time v t1 in
277+
let w = x1 -. x0 in
278+
begin match stack with
279+
| [] -> ()
280+
| Suspend op :: p ->
281+
begin match layer with
282+
| `Bg ->
283+
let g = 0.9 in
284+
C.set_source_rgb cr ~r:g ~g:g ~b:(g /. 2.);
285+
C.rectangle cr ~x:x0 ~y ~w ~h;
286+
C.fill cr
287+
| `Fg ->
288+
if p == prev_stack then (
289+
let clip_area = (w -. 0.2, v.height) in
290+
C.set_source_rgb cr ~r:0.0 ~g:0.0 ~b:0.0;
291+
C.paint_text cr ~x:(x0 +. 2.) ~y:(y +. 12.) op
292+
~clip_area
293+
)
294+
end
295+
| Gc op :: p ->
296+
let g = max 0.1 (0.1 *. float (List.length stack)) in
297+
match layer with
281298
| `Bg ->
282-
let g = 0.9 in
283-
C.set_source_rgb cr ~r:g ~g:g ~b:(g /. 2.);
299+
C.set_source_rgb cr ~r:1.0 ~g:g ~b:(g /. 2.);
284300
C.rectangle cr ~x:x0 ~y ~w ~h;
285301
C.fill cr
286302
| `Fg ->
287303
if p == prev_stack then (
288304
let clip_area = (w -. 0.2, v.height) in
289-
C.set_source_rgb cr ~r:0.0 ~g:0.0 ~b:0.0;
305+
if g < 0.5 then C.set_source_rgb cr ~r:1.0 ~g:1.0 ~b:1.0
306+
else C.set_source_rgb cr ~r:0.0 ~g:0.0 ~b:0.0;
290307
C.paint_text cr ~x:(x0 +. 2.) ~y:(y +. 12.) op
291308
~clip_area
292309
)
293-
end
294-
| Gc op :: p ->
295-
let g = max 0.1 (0.1 *. float (List.length stack)) in
296-
match layer with
297-
| `Bg ->
298-
C.set_source_rgb cr ~r:1.0 ~g:g ~b:(g /. 2.);
299-
C.rectangle cr ~x:x0 ~y ~w ~h;
300-
C.fill cr
301-
| `Fg ->
302-
if p == prev_stack then (
303-
let clip_area = (w -. 0.2, v.height) in
304-
if g < 0.5 then C.set_source_rgb cr ~r:1.0 ~g:1.0 ~b:1.0
305-
else C.set_source_rgb cr ~r:0.0 ~g:0.0 ~b:0.0;
306-
C.paint_text cr ~x:(x0 +. 2.) ~y:(y +. 12.) op
307-
~clip_area
308-
)
309-
end
310-
)
310+
end
311+
)
312+
)
311313

312314
let link_domain v cr ~x (fiber : Layout.item) (ring : Layout.Ring.t) =
313315
let fiber_y = y_of_row v fiber.y +. Style.fiber_padding_top in

0 commit comments

Comments
 (0)