Compare commits
16 Commits
main
...
f0c5556450
| Author | SHA1 | Date | |
|---|---|---|---|
| f0c5556450 | |||
| 97730899c6 | |||
| 18daf83c1c | |||
| dfef26fcf5 | |||
| 048ea0eab4 | |||
| 3509930195 | |||
| b1ac36ce3e | |||
| a12db025e0 | |||
| 5c10f3860a | |||
| a64fcbb010 | |||
| 7baa6f3648 | |||
| af92f03706 | |||
| cb263b5758 | |||
| 44879eb947 | |||
| 49bddb6365 | |||
| b5d846b35d |
574252
_build/default/boot_js.bc.js
Normal file
574252
_build/default/boot_js.bc.js
Normal file
File diff suppressed because one or more lines are too long
117
boot_js.ml
117
boot_js.ml
@ -4,8 +4,7 @@ module NVG = Graphv_webgl
|
||||
|
||||
let _ =
|
||||
Logs.set_reporter (Human.Logs_reporter.console_reporter ());
|
||||
Logs.set_level (Some Debug);
|
||||
Logs.debug (fun m -> m "hello")
|
||||
Logs.set_level (Some Debug)
|
||||
|
||||
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##.height := height
|
||||
|
||||
let _ =
|
||||
let canvas =
|
||||
Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas")
|
||||
in
|
||||
let webgl_initialize canvas =
|
||||
scale_canvas canvas;
|
||||
let webgl_ctx =
|
||||
(* Graphv requires a stencil buffer to work properly *)
|
||||
let attrs = WebGL.defaultContextAttributes in
|
||||
attrs##.stencil := Js._true;
|
||||
@ -43,7 +38,8 @@ let _ =
|
||||
print_endline "Sorry your browser does not support WebGL";
|
||||
raise Exit
|
||||
| Some ctx -> ctx
|
||||
in
|
||||
|
||||
let graphv_initialize webgl_ctx =
|
||||
let open NVG in
|
||||
let vg =
|
||||
create
|
||||
@ -53,57 +49,74 @@ let _ =
|
||||
(* File in this case is actually the CSS font name *)
|
||||
Text.create vg ~name:"sans" ~file:"sans" |> ignore;
|
||||
webgl_ctx##clearColor 0.3 0.3 0.32 1.;
|
||||
vg
|
||||
|
||||
(*
|
||||
let render ev =
|
||||
webgl_ctx##clear
|
||||
(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
|
||||
let request_animation_frame () =
|
||||
let t, s = Lwt.wait () in
|
||||
let (_ : Dom_html.animation_frame_request_id) =
|
||||
Dom_html.window##requestAnimationFrame
|
||||
(Js.wrap_callback (fun _ -> render Human.Event.empty))
|
||||
|> ignore;*)
|
||||
let open Js_of_ocaml_lwt.Lwt_js_events in
|
||||
async (fun () ->
|
||||
buffered_loop (make_event Dom_html.Event.keydown)
|
||||
Dom_html.document (fun ev _ ->
|
||||
(Js.wrap_callback (fun (time : float) -> Lwt.wakeup s time))
|
||||
in
|
||||
t
|
||||
|
||||
let render_stream canvas webgl_ctx vg
|
||||
(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##._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
|
||||
NVG.begin_frame vg ~width:canvas##.width ~height:canvas##.height
|
||||
~device_ratio;
|
||||
Transform.scale vg ~x:device_ratio ~y:device_ratio;
|
||||
Human.Panel.Ui.(
|
||||
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.Transform.scale vg ~x:device_ratio ~y:device_ratio;
|
||||
render vg ~time Gg.P2.o i;
|
||||
NVG.end_frame vg;
|
||||
Lwt.return_unit))
|
||||
Lwt.return_unit)
|
||||
|
||||
(* Dom_html.document##.onkeydown
|
||||
:= Dom.handler (fun (evt : Dom_html.keyboardEvent Js.t) ->
|
||||
render (Human.Event_js.evt_of_jskey `Press evt) ;
|
||||
Js._false ) *)
|
||||
open Human
|
||||
|
||||
let _ =
|
||||
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 = Widgets.window_manager (Lwd.join (Lwd.get body)) in
|
||||
Nav.test_pull () >>= fun test_tree ->
|
||||
Widgets.(tree_nav test_tree []) >>= fun ui ->
|
||||
let root =
|
||||
Lwd.set body
|
||||
(Lwd.map ~f:(Ui.resize ~pad:gravity_pad ~crop:gravity_crop) ui);
|
||||
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))))
|
||||
|
||||
18
notes.org
18
notes.org
@ -24,3 +24,21 @@
|
||||
* principles?
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user