From 0f42ff901e594c5aecc910935d4fb62c15f2b985 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 12 Oct 2017 22:36:08 -0400 Subject: [PATCH] Added logic to draw edit buffer to the edit region --- edit.ml | 24 +++++++++++++++++++++--- lib/buf.ml | 2 +- lib/rope.ml | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/edit.ml b/edit.ml index d1215f9..8225154 100644 --- a/edit.ml +++ b/edit.ml @@ -1,7 +1,7 @@ open X11 -(*let font = font_load "Times New Roman:pixelsize=14"*) -let font = font_load "Monospace:size=10" +(*let font = font_load "Times New Roman:size=12"*) +let font = font_load "Monaco:size=10::antialias=true:autohint=true" let tags_buf = ref Buf.create let edit_buf = ref Buf.create @@ -47,9 +47,27 @@ let draw_scroll pos height = draw_dark_bkg rulepos.x (height/2) pos; draw_vrule height rulepos +let draw_buffer pos width height = + let x = ref pos.x and y = ref pos.y in + let newline () = x := pos.x; y := !y + font.height in + let draw_char c = + let glyph = (X11.get_glyph font c) in + (match c with + | 0x0A -> newline () + | 0x0D -> () + | _ -> begin + if (!x + glyph.width) > width then (newline ()); + let _ = X11.draw_glyph Cfg.Color.palette.(5) glyph (!x, !y) in + x := !x + glyph.xoff + end); + ((!y + font.height) < height) + in + Buf.iter_from draw_char !edit_buf 0; + pos + let draw_edit pos width height = draw_dark_bkg (width - pos.x) (height - pos.y) pos; - draw_text "This is the edit region" pos + draw_buffer { pos with x = pos.x + 2 } width height (* Event functions ******************************************************************************) diff --git a/lib/buf.ml b/lib/buf.ml index cb0c025..a67d558 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -24,7 +24,7 @@ type buf = { } let iter_from fn buf i = - Rope.iter_from fn buf i + Rope.iter_from fn buf.current.rope i let create = let state = { nlines = 0; outpoint = 0; rope = Rope.empty } diff --git a/lib/rope.ml b/lib/rope.ml index f072b3e..a2520e4 100644 --- a/lib/rope.ml +++ b/lib/rope.ml @@ -63,7 +63,7 @@ let del rope i j = (join l_left r_right) let rec iter_from fn rope pos = - if pos < (length rope) && (fn (getc rope pos)) then + if pos < (length rope) && (fn (Char.code (getc rope pos))) then iter_from fn rope (pos + 1) let rec iteri_from fn rope pos = -- 2.52.0