telist is lwd.var
This commit is contained in:
99
ogui.ml
99
ogui.ml
@ -80,21 +80,6 @@ let string_of_utf_8_uchar uc =
|
|||||||
let pp_uchar : Uchar.t F.t =
|
let pp_uchar : Uchar.t F.t =
|
||||||
fun ppf u -> F.pf ppf "%S" (string_of_utf_8_uchar u)
|
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
|
module TextBuffer = struct
|
||||||
type t = {
|
type t = {
|
||||||
path : string list Lwd.var;
|
path : string list Lwd.var;
|
||||||
@ -717,17 +702,7 @@ module Ui = struct
|
|||||||
| Some (`Char _) -> Lwt_stream.junk events
|
| Some (`Char _) -> Lwt_stream.junk events
|
||||||
| _ -> Lwt.return_unit)
|
| _ -> Lwt.return_unit)
|
||||||
| Accepted _ | Continue _ | Rejected -> Lwt.return_unit)
|
| Accepted _ | Continue _ | Rejected -> Lwt.return_unit)
|
||||||
(*Lwt_stream.peek events >>= function
|
>>= fun () -> proc res
|
||||||
| 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
|
|
||||||
| `Char char ->
|
| `Char char ->
|
||||||
F.epr "Ui.process_events `Char '%a'@." pp_uchar
|
F.epr "Ui.process_events `Char '%a'@." pp_uchar
|
||||||
(Uchar.of_int char);
|
(Uchar.of_int char);
|
||||||
@ -1170,10 +1145,9 @@ module Layout = struct
|
|||||||
|> Lwd.map ~f:(fun tl -> frame ?size ~style (`TextEdit (t, tl)))
|
|> Lwd.map ~f:(fun tl -> frame ?size ~style (`TextEdit (t, tl)))
|
||||||
|> Lwt.return
|
|> 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 cursor = Lwd.var 0 in
|
||||||
let len = List.length telist in
|
|
||||||
Ui.update_bindings ui (fun a ->
|
Ui.update_bindings ui (fun a ->
|
||||||
a
|
a
|
||||||
|> Event.adds
|
|> Event.adds
|
||||||
@ -1183,11 +1157,13 @@ module Layout = struct
|
|||||||
( "window_next",
|
( "window_next",
|
||||||
fun () ->
|
fun () ->
|
||||||
Lwd.set cursor
|
Lwd.set cursor
|
||||||
(if Lwd.peek cursor < len - 1 then
|
(if
|
||||||
Lwd.peek cursor + 1
|
Lwd.peek cursor
|
||||||
|
< (List.length @@ Lwd.peek telist) - 1
|
||||||
|
then Lwd.peek cursor + 1
|
||||||
else 0);
|
else 0);
|
||||||
TextEdit.default_bindings
|
TextEdit.default_bindings
|
||||||
(List.nth telist (Lwd.peek cursor))
|
(List.nth (Lwd.peek telist) (Lwd.peek cursor))
|
||||||
ui;
|
ui;
|
||||||
Lwt.return_unit );
|
Lwt.return_unit );
|
||||||
]
|
]
|
||||||
@ -1200,40 +1176,45 @@ module Layout = struct
|
|||||||
Lwd.set cursor
|
Lwd.set cursor
|
||||||
(if Lwd.peek cursor > 0 then
|
(if Lwd.peek cursor > 0 then
|
||||||
Lwd.peek cursor - 1
|
Lwd.peek cursor - 1
|
||||||
else len - 1);
|
else (Lwd.peek telist |> List.length) - 1);
|
||||||
TextEdit.default_bindings
|
TextEdit.default_bindings
|
||||||
(List.nth telist (Lwd.peek cursor))
|
(List.nth (Lwd.peek telist) (Lwd.peek cursor))
|
||||||
ui;
|
ui;
|
||||||
Lwt.return_unit );
|
Lwt.return_unit );
|
||||||
]);
|
]);
|
||||||
(* let teln = List.length telist in *)
|
(* let teln = List.length telist in *)
|
||||||
(* let ratio n = `Ratio (1. /. float (teln - (n + 1))) in *)
|
(* let ratio n = `Ratio (1. /. float (teln - (n + 1))) in *)
|
||||||
Lwt_list.mapi_s
|
Lwd.map
|
||||||
(fun n te ->
|
~f:(fun tl ->
|
||||||
textedit
|
Lwt_list.mapi_s
|
||||||
~size:
|
(fun n te ->
|
||||||
(match d with
|
textedit
|
||||||
| `X -> (`Ratio 0.5, `Ratio 1.)
|
~size:
|
||||||
| `Y -> (`Ratio 1., `Ratio 0.5)
|
(match d with
|
||||||
| `Z -> (`Ratio 1., `Ratio 1.))
|
| `X -> (`Ratio 0.5, `Ratio 1.)
|
||||||
te
|
| `Y -> (`Ratio 1., `Ratio 0.5)
|
||||||
>>= fun tl ->
|
| `Z -> (`Ratio 1., `Ratio 1.))
|
||||||
Lwd.map2 tl (Lwd.get cursor) ~f:(fun tl cursor ->
|
te
|
||||||
{
|
>>= fun tl ->
|
||||||
tl with
|
Lwd.map2 tl (Lwd.get cursor) ~f:(fun tl cursor ->
|
||||||
style =
|
|
||||||
{
|
{
|
||||||
tl.style with
|
tl with
|
||||||
stroke =
|
style =
|
||||||
( fst style.stroke,
|
{
|
||||||
if n == cursor then
|
tl.style with
|
||||||
Gv.Color.(transf (snd style.stroke) 0.5)
|
stroke =
|
||||||
else snd style.stroke );
|
( fst style.stroke,
|
||||||
};
|
if n == cursor then
|
||||||
})
|
Gv.Color.(transf (snd style.stroke) 0.5)
|
||||||
|> Lwt.return)
|
else snd style.stroke );
|
||||||
telist
|
};
|
||||||
>>= fun framelist -> box ~style d framelist |> Lwt.return
|
})
|
||||||
|
|> 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 ]) =
|
let pp_dir ppf (t : [ `X | `Y | `Z ]) =
|
||||||
F.pf ppf "%s"
|
F.pf ppf "%s"
|
||||||
|
|||||||
@ -160,7 +160,6 @@ let main =
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
Key (Press, X, [ Control ]);
|
Key (Press, X, [ Control ]);
|
||||||
Key (Release, X, [ Control ]);
|
|
||||||
Key (Press, E, [ Control ]);
|
Key (Press, E, [ Control ]);
|
||||||
];
|
];
|
||||||
]
|
]
|
||||||
@ -168,7 +167,6 @@ let main =
|
|||||||
Custom
|
Custom
|
||||||
( "toplevel_execute",
|
( "toplevel_execute",
|
||||||
fun () ->
|
fun () ->
|
||||||
F.epr "Ctrl-X Ctrl-E@.";
|
|
||||||
TextBuffer.peek tb_init >>= fun str ->
|
TextBuffer.peek tb_init >>= fun str ->
|
||||||
Toploop.use_input out_ppf (String str)
|
Toploop.use_input out_ppf (String str)
|
||||||
|> F.epr "Toploop.use_input=%b@.";
|
|> F.epr "Toploop.use_input=%b@.";
|
||||||
@ -179,7 +177,11 @@ let main =
|
|||||||
system ui `Y
|
system ui `Y
|
||||||
~style:
|
~style:
|
||||||
Style.{ default with margin = Margin.symmetric 10.0 10.0 }
|
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 ->
|
>>= fun page ->
|
||||||
let page_root = Lwd.observe page in
|
let page_root = Lwd.observe page in
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user