aboutsummaryrefslogtreecommitdiff
path: root/script.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2020-12-29 21:41:47 +0100
committerSébastien Dailly <sebastien@chimrod.com>2020-12-29 21:41:47 +0100
commitfae31bdb659b4b14322136e045ea565d38bbd04f (patch)
treeb08636d488b85e0532e84135f39da33f5e47af91 /script.ml
parent9d65e5e6a5bd8666baf0d7d3e0474c721cafc683 (diff)
Dynamic width
Diffstat (limited to 'script.ml')
-rwxr-xr-xscript.ml45
1 files changed, 24 insertions, 21 deletions
diff --git a/script.ml b/script.ml
index 5d011d9..a250c7f 100755
--- a/script.ml
+++ b/script.ml
@@ -3,7 +3,6 @@ open Note
open Brr
open Brr_note
-
module CanvaRepr = Path.FillPrinter.Make(Layer.CanvaPrinter)
module Path_Printer = Paths.Path_Builder.Draw(CanvaRepr)
@@ -13,6 +12,12 @@ type canva_signal = Path.Point.t
module Mouse = Brr_note_kit.Mouse
+let get_height el =
+ match El.at (Jstr.v "height") el with
+ | None -> 0
+ | Some att ->
+ Option.value ~default:0 (Jstr.to_int att)
+
(** Create the element in the page, and the event handler *)
let canva
: Brr.El.t -> [> State.canva_events] Note.E.t * (float * float) option Note.S.t * Brr_canvas.Canvas.t
@@ -128,7 +133,7 @@ let set_sidebar
let input_angle, angle_event =
Elements.Input.slider
~at:At.[ type' (Jstr.v "range")
- ; v (Jstr.v "min") (Jstr.v "1")
+ ; v (Jstr.v "min") (Jstr.v "0")
; v (Jstr.v "max") (Jstr.v "90")
; At.value (Jstr.of_float state.angle)
] in
@@ -143,9 +148,6 @@ let set_sidebar
)
);
- let click = Evr.on_el Ev.click Evr.unit delete in
- let _ = click in
-
let () =
El.append_children element
[ hr ()
@@ -155,7 +157,6 @@ let set_sidebar
; width
; nib_size
- ; El.br ()
; angle
; input_angle
@@ -167,8 +168,8 @@ let set_sidebar
let backgroundColor = Blog.Nord.nord0
let white = Jstr.v "#eceff4"
let green = Jstr.v "#a3be8c"
-let nord8 = Jstr.v "#81a1c1"
+(** Redraw the canva on update *)
let on_change canva mouse_position state =
let module Path' = Path in
let open Brr_canvas.C2d in
@@ -215,25 +216,26 @@ let on_change canva mouse_position state =
List.iter paths
~f:(fun path ->
+
+ let () = match state.mode with
+ | Selection s ->
+ begin match (Paths.Path_Builder.id s) = (Paths.Path_Builder.id path) with
+ | true ->
+ set_fill_style context (color Blog.Nord.nord8);
+ set_stroke_style context (color Blog.Nord.nord8)
+ | false ->
+ set_stroke_style context (color white);
+ set_fill_style context (color white);
+ end
+ | _ -> ()
+ in
+
let path = CanvaRepr.get
@@ Fixed_Printer.draw
path
(CanvaRepr.create_path (fun p -> fill context p)) in
stroke context path;
);
-
-
- (* If there is a selection draw it *)
- let () = match state.mode with
- | Selection path ->
- set_fill_style context (color nord8);
- set_stroke_style context (color nord8);
- let path = CanvaRepr.get
- @@ Fixed_Printer.draw
- path
- (CanvaRepr.create_path (fun p -> fill context p)) in
- stroke context path;
- | _ -> () in
()
@@ -258,7 +260,6 @@ let page_main id =
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])
@@ -297,6 +298,8 @@ let page_main id =
let _ =
E.select
[ E.map (fun _ -> ()) (S.changes mouse_position)
+ ; E.map (fun _ -> ()) (S.changes angle_signal')
+ ; E.map (fun _ -> ()) (S.changes width_signal')
; delete_event' ]
|> fun ev -> E.log ev (fun _ -> on_change canva mouse_position (S.value state) )
|> Option.iter Logr.hold in