more Lwd.t-ification
This commit is contained in:
79
oplevel.ml
79
oplevel.ml
@ -38,7 +38,7 @@ let load_fonts vg =
|
||||
Gv.Text.add_fallback vg ~name:"sans-bold" ~fallback:"emoji";
|
||||
Gv.Text.set_font_face vg ~name:"mono"
|
||||
|
||||
let () =
|
||||
let main =
|
||||
GLFW.init ();
|
||||
at_exit GLFW.terminate;
|
||||
let _res = GLFWExtras.glfwSetErrorCallback errorcb in
|
||||
@ -99,24 +99,24 @@ let () =
|
||||
|> ignore;
|
||||
|
||||
F.pr "oplevel.ml: building initial page@.";
|
||||
TextBuffer.of_repo
|
||||
~initial_path:[ ".config"; "init.ml" ]
|
||||
~repo:rootrepo
|
||||
>>= fun tb_init ->
|
||||
Layout.textedit (TextEdit.multiline ui tb_init) >>= fun te_init ->
|
||||
let page =
|
||||
Lwd.var
|
||||
Layout.(
|
||||
vbox
|
||||
~style:
|
||||
Style.{ default with margin = Margin.symmetric 10.0 10.0 }
|
||||
[
|
||||
textedit
|
||||
(TextEdit.multiline ui
|
||||
(Lwt_main.run
|
||||
(TextBuffer.of_repo
|
||||
~path:[ ".config"; "init.ml" ]
|
||||
~repo:rootrepo)));
|
||||
(*textedit
|
||||
(TextEdit.multiline ui
|
||||
(TextBuffer.of_repo ~path:[ "README" ] ~repo:rootrepo)); *)
|
||||
])
|
||||
Layout.(
|
||||
vbox
|
||||
~style:
|
||||
Style.{ default with margin = Margin.symmetric 10.0 10.0 }
|
||||
[
|
||||
te_init;
|
||||
(*textedit
|
||||
(TextEdit.multiline ui
|
||||
(TextBuffer.of_repo ~path:[ "README" ] ~repo:rootrepo)); *)
|
||||
])
|
||||
in
|
||||
let page_root = Lwd.observe page in
|
||||
|
||||
let open GLFW in
|
||||
let open Event in
|
||||
@ -131,7 +131,23 @@ let () =
|
||||
let period_min = 1.0 /. 30. in
|
||||
let t = GLFW.getTime () |> ref in
|
||||
|
||||
let render page =
|
||||
let render root =
|
||||
let page = Lwd.quick_sample root in
|
||||
let win_w, win_h = GLFW.getWindowSize ~window in
|
||||
let width, height = (float win_w, float win_h) in
|
||||
let box = Gg.(Box2.v V2.zero Size2.(v width (height -. 20.))) in
|
||||
Gv.begin_frame ctx ~width ~height ~device_ratio:1.;
|
||||
Perfgraph.render graph ctx (width -. 205.) 5.;
|
||||
(* F.epr "box=%a@." Gg.Box2.pp box;
|
||||
F.epr "Painter.layout=%a@." Gg.Box2.pp *)
|
||||
Painter.layout box ui page >>= fun _ ->
|
||||
(* Demo.render_demo ctx mx my win_w win_h now !blowup data; *)
|
||||
Gv.end_frame ctx;
|
||||
|
||||
Lwt.return_unit
|
||||
in
|
||||
|
||||
while not GLFW.(windowShouldClose ~window) do
|
||||
let now = GLFW.getTime () in
|
||||
let dt = now -. !t in
|
||||
t := now;
|
||||
@ -143,9 +159,7 @@ let () =
|
||||
min_fps := Float.min avg !min_fps;
|
||||
max_fps := Float.max avg !max_fps);
|
||||
|
||||
let _mx, _my = GLFW.getCursorPos ~window in
|
||||
let win_w, win_h = GLFW.getWindowSize ~window in
|
||||
|
||||
Gl.viewport 0 0 win_w win_h;
|
||||
Gl.clear
|
||||
(Gl.color_buffer_bit lor Gl.depth_buffer_bit
|
||||
@ -154,31 +168,16 @@ let () =
|
||||
Gl.blend_func Gl.src_alpha Gl.one_minus_src_alpha;
|
||||
Gl.enable Gl.cull_face_enum;
|
||||
Gl.disable Gl.depth_test;
|
||||
|
||||
let width, height = (float win_w, float win_h) in
|
||||
let box = Gg.(Box2.v V2.zero Size2.(v width (height -. 20.))) in
|
||||
Gv.begin_frame ctx ~width ~height ~device_ratio:1.;
|
||||
Perfgraph.render graph ctx (width -. 205.) 5.;
|
||||
(* F.epr "box=%a@." Gg.Box2.pp box;
|
||||
F.epr "Painter.layout=%a@." Gg.Box2.pp *)
|
||||
Painter.layout box ui page >>= fun _ ->
|
||||
(* Demo.render_demo ctx mx my win_w win_h now !blowup data; *)
|
||||
Gv.end_frame ctx;
|
||||
|
||||
Lwt.async (fun () -> render page_root);
|
||||
Gc.major_slice 0 |> ignore;
|
||||
GLFW.swapBuffers ~window;
|
||||
GLFW.pollEvents ();
|
||||
Unix.sleepf Float.(max 0. (period_min -. GLFW.getTime () +. !t));
|
||||
Lwt.return_unit
|
||||
in
|
||||
|
||||
while not GLFW.(windowShouldClose ~window) do
|
||||
Lwt_main.run (render (Lwd.peek page))
|
||||
Unix.sleepf Float.(max 0. (period_min -. GLFW.getTime () +. !t))
|
||||
done;
|
||||
|
||||
Printf.printf "MIN %.2f\n" !min_fps;
|
||||
Printf.printf "MAX %.2f\n%!" !max_fps
|
||||
|
||||
Printf.printf "MAX %.2f\n%!" !max_fps;
|
||||
Lwt.return_unit
|
||||
(* let out_ppf =
|
||||
Format.formatter_of_out_functions
|
||||
Format.
|
||||
@ -199,3 +198,5 @@ let () =
|
||||
(* ignore
|
||||
(Toploop.use_input out_ppf
|
||||
(String "#use \"topfind\";;\n#list;;")); *)
|
||||
|
||||
let () = Lwt_main.run main
|
||||
|
||||
Reference in New Issue
Block a user