aboutsummaryrefslogtreecommitdiff
path: root/script.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2020-12-22 21:42:55 +0100
committerSébastien Dailly <sebastien@chimrod.com>2020-12-22 21:42:55 +0100
commit6354358caa1dfbf2fe1d481f6ac5fba3775938fc (patch)
tree4fd24d821f37a0626754f6f5078ac77ffe5c469c /script.ml
parent1f1f13a3f02e7f5f5da5926a402d53f2ccbfe536 (diff)
Blog integration
Diffstat (limited to 'script.ml')
-rwxr-xr-xscript.ml68
1 files changed, 57 insertions, 11 deletions
diff --git a/script.ml b/script.ml
index 02492d6..58eae1e 100755
--- a/script.ml
+++ b/script.ml
@@ -6,6 +6,7 @@ module Timer = Events.Timer
module Repr = Path.FillPrinter
+
module Path_Builder = Path.Builder.Make(Path.Point)
module Path_Printer = Path_Builder.Draw(Repr)
module Fixed_Printer = Path_Builder.DrawFixed(Repr)
@@ -35,8 +36,12 @@ type canva_events =
| `Out of float * float
]
+type button_events =
+ [ `Delete ]
+
type events =
[ canva_events
+ | button_events
| `Point of float * (float * float) ]
type canva_signal = Path.Point.t
@@ -47,6 +52,23 @@ module Mouse = Brr_note_kit.Mouse
let canva
: Brr.El.t -> [> canva_events] Note.E.t * (float * float) option Note.S.t * Brr_canvas.Canvas.t
= fun element ->
+
+ El.set_inline_style
+ El.Style.width
+ (Jstr.v "100%")
+ element;
+
+ El.set_prop
+ El.Prop.width
+ (El.prop (El.Prop.int (Jstr.v "offsetWidth")) element)
+ element;
+
+ El.set_inline_style
+ El.Style.width
+ (Jstr.v "")
+ element;
+
+
let module C = Brr_canvas.Canvas in
let c = C.of_el element in
@@ -176,8 +198,10 @@ let do_action
; current }
end
end
-
-
+ | `Delete, Selection s ->
+ let id = Path_Builder.id s in
+ let paths = List.filter state.paths ~f:(fun p -> Path_Builder.id p != id) in
+ { state with paths ; mode = Out}
| _ -> state
let backgroundColor = Jstr.v "#2e3440"
@@ -261,11 +285,32 @@ let page_main id =
; mode = Out
} in
+ let delete_event' =
+ begin match Blog.Sidebar.get () with
+ | None ->
+ Jv.throw (Jstr.v "No sidebar")
+ | Some el ->
+
+ Blog.Sidebar.clean el;
+ let event = Blog.Sidebar.add_button el in
+ event
+ end in
+ let delete_event = E.map (fun () -> `Delete) delete_event' in
+
+
(*begin match Document.find_el_by_id G.document id with*)
begin match (Jv.is_none id) with
| true -> Console.(error [str "No element with id '%s' found"; id])
| false ->
+ (* Add the events to the canva :
+
+ - The mouse position is a signal used for both the update and the
+ canva refresh
+
+ - Get also the click event for starting to draw
+ *)
+
let canva_events, mouse_position, canva = canva (Jv.Id.of_jv id) in
let tick_event =
@@ -276,24 +321,25 @@ let page_main id =
(* The first evaluation is the state. Which is the result of all the
successives events to the initial state *)
let state =
- E.select [canva_events; tick_event]
+ E.select [canva_events; tick_event; delete_event]
|> E.map do_action
|> Note.S.accum init in
(* The seconde evaluation is the canva refresh, which only occurs when
- the mouse is updated *)
- let v =
- E.map (fun _ -> state) (S.changes mouse_position)
- |> E.map (fun x -> on_change canva mouse_position (S.value x) )
- |> fun ev -> E.log ev (fun _ -> ()) in
+ the mouse is updated, or on delete events *)
+ let _ =
+ E.select
+ [ E.map (fun _ -> ()) (S.changes mouse_position)
+ ; delete_event' ]
+ |> fun ev -> E.log ev (fun _ -> on_change canva mouse_position (S.value state) )
+ |> Option.iter Logr.hold in
+
(* Draw the canva for first time *)
on_change canva mouse_position init;
+ (* Hold the state *)
let _ = Logr.hold (S.log state (fun _ -> ())) in
- let _ = match v with
- | None -> ()
- | Some log -> Logr.hold log in
()
end