14 Commits

4 changed files with 576935 additions and 1373 deletions

573977
_build/default/boot_js.bc.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -4,8 +4,7 @@ module NVG = Graphv_webgl
let _ = let _ =
Logs.set_reporter (Human.Logs_reporter.console_reporter ()); Logs.set_reporter (Human.Logs_reporter.console_reporter ());
Logs.set_level (Some Debug); Logs.set_level (Some Debug)
Logs.debug (fun m -> m "hello")
module Log = (val Logs.src_log Logs.default : Logs.LOG) module Log = (val Logs.src_log Logs.default : Logs.LOG)
@ -27,12 +26,8 @@ let scale_canvas (canvas : Dom_html.canvasElement Js.t) =
canvas##.style##.width := width; canvas##.style##.width := width;
canvas##.style##.height := height canvas##.style##.height := height
let _ = let webgl_initialize canvas =
let canvas =
Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas")
in
scale_canvas canvas; scale_canvas canvas;
let webgl_ctx =
(* Graphv requires a stencil buffer to work properly *) (* Graphv requires a stencil buffer to work properly *)
let attrs = WebGL.defaultContextAttributes in let attrs = WebGL.defaultContextAttributes in
attrs##.stencil := Js._true; attrs##.stencil := Js._true;
@ -43,7 +38,8 @@ let _ =
print_endline "Sorry your browser does not support WebGL"; print_endline "Sorry your browser does not support WebGL";
raise Exit raise Exit
| Some ctx -> ctx | Some ctx -> ctx
in
let graphv_initialize webgl_ctx =
let open NVG in let open NVG in
let vg = let vg =
create create
@ -53,57 +49,74 @@ let _ =
(* File in this case is actually the CSS font name *) (* File in this case is actually the CSS font name *)
Text.create vg ~name:"sans" ~file:"sans" |> ignore; Text.create vg ~name:"sans" ~file:"sans" |> ignore;
webgl_ctx##clearColor 0.3 0.3 0.32 1.; webgl_ctx##clearColor 0.3 0.3 0.32 1.;
vg
(* let request_animation_frame () =
let render ev = let t, s = Lwt.wait () in
webgl_ctx##clear let (_ : Dom_html.animation_frame_request_id) =
(webgl_ctx##._COLOR_BUFFER_BIT_
lor webgl_ctx##._DEPTH_BUFFER_BIT_
lor webgl_ctx##._STENCIL_BUFFER_BIT_);
let device_ratio = Dom_html.window##.devicePixelRatio in
begin_frame vg ~width:canvas##.width ~height:canvas##.height
~device_ratio;
Transform.scale vg ~x:device_ratio ~y:device_ratio;
ignore Human.Panel.Ui.(panel vg Gg.P2.o test ev);
(*
Path.begin_ vg ;
Path.rect vg ~x:40. ~y:40. ~w:320. ~h:320. ;
set_fill_color vg ~color:Color.(rgba ~r:154 ~g:203 ~b:255 ~a:200) ;
fill vg ;
Transform.translate vg ~x:200. ~y:200. ;
Transform.rotate vg ~angle:(time *. 0.0005) ;
Text.set_font_face vg ~name:"sans" ;
Text.set_size vg ~size:48. ;
Text.set_align vg ~align:Align.(center lor middle) ;
set_fill_color vg ~color:Color.white ;
Text.text vg ~x:0. ~y:0. "Hello World!" ; *)
NVG.end_frame vg
in
Dom_html.window##requestAnimationFrame Dom_html.window##requestAnimationFrame
(Js.wrap_callback (fun _ -> render Human.Event.empty)) (Js.wrap_callback (fun (time : float) -> Lwt.wakeup s time))
|> ignore;*) in
let open Js_of_ocaml_lwt.Lwt_js_events in t
async (fun () ->
buffered_loop (make_event Dom_html.Event.keydown) let render_stream canvas webgl_ctx vg
Dom_html.document (fun ev _ -> (render : NVG.t -> ?time:float -> Gg.p2 -> Human.I.t -> unit) :
Human.I.t Lwt_stream.t -> unit Lwt.t =
Lwt_stream.iter_n (fun i ->
request_animation_frame () >>= fun time ->
webgl_ctx##clear webgl_ctx##clear
(webgl_ctx##._COLOR_BUFFER_BIT_ (webgl_ctx##._COLOR_BUFFER_BIT_
lor webgl_ctx##._DEPTH_BUFFER_BIT_ lor webgl_ctx##._DEPTH_BUFFER_BIT_
lor webgl_ctx##._STENCIL_BUFFER_BIT_); lor webgl_ctx##._STENCIL_BUFFER_BIT_);
let device_ratio = Dom_html.window##.devicePixelRatio in let device_ratio = Dom_html.window##.devicePixelRatio in
begin_frame vg ~width:canvas##.width ~height:canvas##.height NVG.begin_frame vg ~width:canvas##.width ~height:canvas##.height
~device_ratio; ~device_ratio;
Transform.scale vg ~x:device_ratio ~y:device_ratio; NVG.Transform.scale vg ~x:device_ratio ~y:device_ratio;
Human.Panel.Ui.( render vg ~time Gg.P2.o i;
render_lwt vg Gg.P2.o
(Human.Event_js.evt_of_jskey `Press ev))
>>= fun p ->
Logs.debug (fun m ->
m "Drawing finished at point: %a" Gg.V2.pp p);
NVG.end_frame vg; NVG.end_frame vg;
Lwt.return_unit)) Lwt.return_unit)
(* Dom_html.document##.onkeydown open Human
:= Dom.handler (fun (evt : Dom_html.keyboardEvent Js.t) ->
render (Human.Event_js.evt_of_jskey `Press evt) ; let _ =
Js._false ) *) let canvas =
Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas")
in
let webgl_ctx = webgl_initialize canvas in
let vg = graphv_initialize webgl_ctx in
let open Js_of_ocaml_lwt.Lwt_js_events in
let open Nottui in
let gravity_pad = Gravity.make ~h:`Negative ~v:`Negative in
let gravity_crop = Gravity.make ~h:`Positive ~v:`Negative in
let body = Lwd.var (Lwd.pure Ui.empty) in
let wm = Nottui_widgets.window_manager (Lwd.join (Lwd.get body)) in
Nav.test_pull () >>= fun test_tree ->
Nottui_widgets.(tree_nav test_tree []) >>= fun ui ->
let root =
Lwd.set body
(Lwd.map ~f:(Ui.resize ~pad:gravity_pad ~crop:gravity_crop) ui);
Nottui_widgets.window_manager_view wm
in
let events, push_event = Lwt_stream.create () in
let images =
Human.Nottui_lwt.render vg
~size:(Gg.P2.v canvas##.width canvas##.height)
events root
in
async (fun () ->
render_stream canvas webgl_ctx vg
(fun vg ?(time = 0.) p i ->
let _ = time in
Log.debug (fun m ->
m "Drawing image: p=%a n=%a" Gg.V2.pp p
(I.Draw.pp ~attr:A.dark)
i);
let p' = I.Draw.node vg A.dark p i in
Logs.debug (fun m ->
m "Drawing finished: p'=%a" Gg.V2.pp p'))
images);
buffered_loop (make_event Dom_html.Event.keydown) Dom_html.document
(fun ev _ ->
Lwt.return
@@ push_event (Some (`Key (Event_js.evt_of_jskey ev))))

3920
human.ml

File diff suppressed because it is too large Load Diff

View File

@ -24,3 +24,21 @@
* principles? * principles?
an "anywhere" programming environment an "anywhere" programming environment
* 221211
ok you got the scroll box mostly working so next:
** fix the scroll jump bugs
** setup better keybindings
** fix cursor and active focus indicators
* 221210 -
** need to resolve the issue with the ui.t Resize type.
this is an issue with the direction of the determination of the .height and .width fields of Ui.t
currently you were planning to combine update_sensors and update_size
in the original nottui.ml library, are Ui.t.w and Ui.t.h determined from the top down orbottom up?
the bottom up, becahse they are chars