telist is lwd.var

This commit is contained in:
cqc
2024-07-06 00:14:56 -05:00
parent 023495b3b0
commit b117b6916b
2 changed files with 45 additions and 62 deletions

53
ogui.ml
View File

@ -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,14 +1176,16 @@ 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 *)
Lwd.map
~f:(fun tl ->
Lwt_list.mapi_s
(fun n te ->
textedit
@ -1232,8 +1210,11 @@ module Layout = struct
};
})
|> Lwt.return)
telist
>>= fun framelist -> box ~style d framelist |> 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"

View File

@ -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