]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
tweaked interfaces and added a scrollmap hook for unit tests
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 24 Oct 2017 17:01:08 +0000 (13:01 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 24 Oct 2017 17:01:08 +0000 (13:01 -0400)
edit.ml
lib/buf.ml
lib/buf.mli [new file with mode: 0644]
lib/scrollmap.ml
lib/scrollmap.mli

diff --git a/edit.ml b/edit.ml
index 84dae0b77207c179d85c573dfa0c725a2924e860..3403e0cb58d95a68b0aecfffae117569dfd26238 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -19,9 +19,9 @@ let draw_bkg color width height pos =
   draw_rect { x = pos.x; y = pos.y; w = width; h = height; c = color }
 
 (* curried helpers *)
-let draw_dark_bkg  = draw_bkg Cfg.Color.palette.(0)
+let draw_dark_bkg = draw_bkg Cfg.Color.palette.(0)
 let draw_light_bkg = draw_bkg Cfg.Color.palette.(1)
-let draw_gray_bkg  = draw_bkg Cfg.Color.palette.(3)
+let draw_gray_bkg = draw_bkg Cfg.Color.palette.(3)
 
 let draw_text text pos =
   draw_string font Cfg.Color.palette.(5) text (pos.x + 2, pos.y + 2);
@@ -63,7 +63,6 @@ let draw_buffer pos width height =
     | 0x0D -> ()
     | 0x09 ->
         let tabsz = ((X11.get_glyph font tabglyph).xoff * tabwidth) in
-        let ntabs = (width - pos.x) / tabsz in
         x := pos.x + (((!x - pos.x) + tabsz) / tabsz * tabsz)
     | _    -> begin
         if (!x + glyph.xoff) > width then (newline ());
@@ -72,7 +71,7 @@ let draw_buffer pos width height =
     end);
     ((!y + font.height) < height)
   in
-  Buf.iter_from draw_char !edit_buf !edit_buf.start;
+  Buf.iter_from draw_char !edit_buf (Buf.start !edit_buf);
   pos
 
 let draw_edit pos width height =
@@ -86,11 +85,10 @@ let onfocus focused =
   () (*print_endline "onfocus"*)
 
 let onkeypress mods rune =
-  print_endline "scroll up"
+  ()
 
 let onmousebtn mods btn x y pressed =
-  print_endline "scroll down";
-  edit_buf := { !edit_buf with start = !edit_buf.start + 1}
+  ()
 
 let onmousemove mods x y =
   () (*print_endline "onmousemove"*)
index 737e9517af8b05e5880e738a0f4b8d51642d56f2..ee81c8f16c4e9ea1876a37f0b6034090b0599e0d 100644 (file)
@@ -1,13 +1,9 @@
-type cursor = { start : int; stop : int }
-
 type t = {
   start : int;
   path : string;
   rope : Rope.t
 }
 
-let font = X11.font_load "Verdana:size=11:antialias=true:autohint=true"
-
 let empty =
   { start = 0; path = ""; rope = Rope.empty }
 
@@ -17,29 +13,12 @@ let load path =
 let rope buf =
   buf.rope
 
+let start buf =
+  buf.start
+
 let iter_from fn buf i =
   Rope.iter_from fn buf.rope i
 
-
-
-(*
-
-let make_cursor buf start stop =
-  { start = (Rope.limit_index buf.rope start);
-    stop = (Rope.limit_index buf.rope stop) }
-
-let move_rune count csr buf ext =
-  let newstop = csr.stop + count in
-  let newstart = if ext then csr.start else newstop in
-  make_cursor buf newstart newstop
-
-let move_word count csr buf ext =
-  ()
-
-let move_line count csr buf ext =
-  ()
-
-*)
 (* Unit Tests *****************************************************************)
 
 let run_unit_tests () =
diff --git a/lib/buf.mli b/lib/buf.mli
new file mode 100644 (file)
index 0000000..5705ee6
--- /dev/null
@@ -0,0 +1,6 @@
+type t
+val empty : t
+val load : string -> t
+val rope : t -> Rope.t
+val start : t -> int
+val iter_from : (int -> bool) -> t -> int -> unit
index 404b000bf118b57b923b96cf72077675442f9aa9..7c8c7ede508ba2683e70d5cf21ab424771ddd59a 100644 (file)
@@ -3,6 +3,10 @@ type t = {
   map : int array
 }
 
-let make buf off =
-  let bol = (Rope.to_bol (Buf.rope buf) off) in
+let make buf =
+  let bol = (Rope.to_bol (Buf.rope buf) (Buf.start buf)) in
   { index = 0; map = [||] }
+
+(* Unit Tests** ***************************************************************)
+
+let run_unit_tests () = ()
index 1d37c0af8e7be52d63fda3a2316f886159fae4e5..52ab68552ce59fe4312955fafbc32e20c758195d 100644 (file)
@@ -1,2 +1,3 @@
 type t
-val make : Buf.t -> int -> t
+val make : Buf.t -> t
+val run_unit_tests : unit -> unit