]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
Added logic to draw edit buffer to the edit region
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 13 Oct 2017 02:36:08 +0000 (22:36 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 13 Oct 2017 02:36:08 +0000 (22:36 -0400)
edit.ml
lib/buf.ml
lib/rope.ml

diff --git a/edit.ml b/edit.ml
index d1215f95a99b3c7aff27b4bf33505d4da60ae624..82251549649a67543c2116c7665600d2c5ddc10e 100644 (file)
--- 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
  ******************************************************************************)
index cb0c0253dacd2f93662300f0fdf910ba339dd904..a67d558a51baa7d8c525a541f26e8dea7a611f22 100644 (file)
@@ -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 }
index f072b3eb8c69db1815505025dca0095bbd5fb328..a2520e43efcf42e4595307b3cd88d9cc8635ace6 100644 (file)
@@ -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 =