diff --git a/ogui.ml b/ogui.ml index 192c9b1..7754f6f 100644 --- a/ogui.ml +++ b/ogui.ml @@ -80,21 +80,6 @@ let string_of_utf_8_uchar uc = let pp_uchar : Uchar.t F.t = fun ppf u -> F.pf ppf "%S" (string_of_utf_8_uchar u) -module Sense = struct - type t = { - click : bool; - drag : bool; - focusable : bool; - edit : bool; - } - - let click = - { click = true; drag = false; focusable = true; edit = false } - - let hover = - { click = false; drag = false; focusable = true; edit = false } -end - module TextBuffer = struct type t = { path : string list Lwd.var; @@ -717,17 +702,7 @@ module Ui = struct | Some (`Char _) -> Lwt_stream.junk events | _ -> Lwt.return_unit) | Accepted _ | Continue _ | Rejected -> Lwt.return_unit) - (*Lwt_stream.peek events >>= function - | Some (`Char cc) -> ( - match res with - | Accepted _ | Continue _ -> - F.epr - "Ui.process_events Lwt_stream.junk events@."; - proc ~skip:(`Char cc) res - | Rejected -> ) - | Some (`Key _) | None -> proc res *) - >>= - fun () -> proc res + >>= fun () -> proc res | `Char char -> F.epr "Ui.process_events `Char '%a'@." pp_uchar (Uchar.of_int char); @@ -1170,10 +1145,9 @@ module Layout = struct |> Lwd.map ~f:(fun tl -> frame ?size ~style (`TextEdit (t, tl))) |> Lwt.return - let system ui ?(style = textedit_style) d (telist : TextEdit.t list) - = + let system ui ?(style = textedit_style) d + (telist : TextEdit.t list Lwd.var) = let cursor = Lwd.var 0 in - let len = List.length telist in Ui.update_bindings ui (fun a -> a |> Event.adds @@ -1183,11 +1157,13 @@ module Layout = struct ( "window_next", fun () -> Lwd.set cursor - (if Lwd.peek cursor < len - 1 then - Lwd.peek cursor + 1 + (if + Lwd.peek cursor + < (List.length @@ Lwd.peek telist) - 1 + then Lwd.peek cursor + 1 else 0); TextEdit.default_bindings - (List.nth telist (Lwd.peek cursor)) + (List.nth (Lwd.peek telist) (Lwd.peek cursor)) ui; Lwt.return_unit ); ] @@ -1200,40 +1176,45 @@ module Layout = struct Lwd.set cursor (if Lwd.peek cursor > 0 then Lwd.peek cursor - 1 - else len - 1); + else (Lwd.peek telist |> List.length) - 1); TextEdit.default_bindings - (List.nth telist (Lwd.peek cursor)) + (List.nth (Lwd.peek telist) (Lwd.peek cursor)) ui; Lwt.return_unit ); ]); (* let teln = List.length telist in *) (* let ratio n = `Ratio (1. /. float (teln - (n + 1))) in *) - Lwt_list.mapi_s - (fun n te -> - textedit - ~size: - (match d with - | `X -> (`Ratio 0.5, `Ratio 1.) - | `Y -> (`Ratio 1., `Ratio 0.5) - | `Z -> (`Ratio 1., `Ratio 1.)) - te - >>= fun tl -> - Lwd.map2 tl (Lwd.get cursor) ~f:(fun tl cursor -> - { - tl with - style = + Lwd.map + ~f:(fun tl -> + Lwt_list.mapi_s + (fun n te -> + textedit + ~size: + (match d with + | `X -> (`Ratio 0.5, `Ratio 1.) + | `Y -> (`Ratio 1., `Ratio 0.5) + | `Z -> (`Ratio 1., `Ratio 1.)) + te + >>= fun tl -> + Lwd.map2 tl (Lwd.get cursor) ~f:(fun tl cursor -> { - tl.style with - stroke = - ( fst style.stroke, - if n == cursor then - Gv.Color.(transf (snd style.stroke) 0.5) - else snd style.stroke ); - }; - }) - |> Lwt.return) - telist - >>= fun framelist -> box ~style d framelist |> Lwt.return + tl with + style = + { + tl.style with + stroke = + ( fst style.stroke, + if n == cursor then + Gv.Color.(transf (snd style.stroke) 0.5) + else snd style.stroke ); + }; + }) + |> Lwt.return) + tl + >>= fun framelist -> box ~style d framelist |> Lwt.return) + (Lwd.get telist) + |> lwt_lwd + >>= fun d -> Lwd.join d |> Lwt.return let pp_dir ppf (t : [ `X | `Y | `Z ]) = F.pf ppf "%s" diff --git a/oplevel.ml b/oplevel.ml index fb9da77..9563cfa 100644 --- a/oplevel.ml +++ b/oplevel.ml @@ -160,7 +160,6 @@ let main = [ [ Key (Press, X, [ Control ]); - Key (Release, X, [ Control ]); Key (Press, E, [ Control ]); ]; ] @@ -168,7 +167,6 @@ let main = Custom ( "toplevel_execute", fun () -> - F.epr "Ctrl-X Ctrl-E@."; TextBuffer.peek tb_init >>= fun str -> Toploop.use_input out_ppf (String str) |> F.epr "Toploop.use_input=%b@."; @@ -179,7 +177,11 @@ let main = system ui `Y ~style: Style.{ default with margin = Margin.symmetric 10.0 10.0 } - [ TextEdit.multiline ui tb_init; TextEdit.multiline ui to_init ]) + (Lwd.var + [ + TextEdit.multiline ui tb_init; + TextEdit.multiline ui to_init; + ])) >>= fun page -> let page_root = Lwd.observe page in