From cac6d037d098752b2e552fc9a77b0942475600d3 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 14:24:17 +0200 Subject: [PATCH 01/14] Copy ocsigen-widget color picker code as ot_color_picker* files --- src/widgets/ot_color_picker.eliom | 187 +++++++++++++++++++++++++++++ src/widgets/ot_color_picker.eliomi | 64 ++++++++++ 2 files changed, 251 insertions(+) create mode 100644 src/widgets/ot_color_picker.eliom create mode 100644 src/widgets/ot_color_picker.eliomi diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom new file mode 100644 index 00000000..d22f6ce5 --- /dev/null +++ b/src/widgets/ot_color_picker.eliom @@ -0,0 +1,187 @@ +[%%shared + +open Eliom_content.Html +open Eliom_content.Html.F + +type div = Html_types.div Eliom_content.Html.D.elt +type t = (string ref * div * div list * div) + +let raise_exception str = + failwith "ew_table_color_picker." ^ str + +let genere_lll_color precision = + + let color_list = match precision with + | p when p <= 1 -> + ignore (raise_exception + "genere_list_color, the argument have to be greater than 1"); + [] + | precision -> + let step = 255 / (precision - 1) in + let rec aux_build nl v = + if (v > 255) + then nl + else aux_build ((Printf.sprintf "%02X" v)::nl) (v + step) + in aux_build [] 0 + in + let max_iteration = List.length color_list in + + let rec aux_red nl = function + | n when n >= max_iteration -> nl + | n -> + let red = List.nth color_list n in + + let rec aux_green nl = function + | n when n >= max_iteration -> nl + | n -> + let green = List.nth color_list n in + + let rec aux_blue nl = function + | n when n >= max_iteration -> nl + | n -> + let blue = List.nth color_list n in + aux_blue (("#" ^ red ^ green ^ blue)::nl) (n + 1) + + in aux_green ((aux_blue [] 0)::nl) (n + 1) + + in aux_red ((aux_green [] 0)::nl) (n + 1) + + in aux_red [] 0 + + +(* Some pre-genereated ll_color in several precision *) +let lll_color_p2 = lazy (genere_lll_color 2) +let lll_color_p3 = lazy (genere_lll_color 3) +let lll_color_p4 = lazy (genere_lll_color 4) +let lll_color_p5 = lazy (genere_lll_color 5) +let lll_color_p6 = lazy (genere_lll_color 6) + +(* Some hand-mained lll_color *) +let lll_color_10 = [[["#E03625"; "#FF4B3A"]; + ["#FF7E02"; "#FFC503"]; + ["#01CD64"; "#AF58B9"]; + ["#0198DD"; "#254760"]; + ["#FFFFFF"; "#000000"]]] + +let lll_color_6 = [[["#BEC3C7"; "#7A8E8D"]; + ["#1C3D50"; "#0280B4"]; + ["#00A385"; "#A444B2"]]] + + +(** +** Take one list of list of list of color (string) and build table list with it. +** return also div_color_list to allow to launch start script detection +**) +let genere_color_table lll_color = + + let build_color_div color = + D.div ~a:[a_class["ew_table_color_picker_square"]; + a_title color; + a_style ("background-color: " ^ color ^ ";")] + [] + in + let build_td_color color_div = + td ~a:[a_class["ew_table_color_picker_td"]] [color_div] + in + let build_tr_color tds = + tr ~a:[a_class["ew_table_color_picker_tr"]] tds + in + + let rec build_table div_color_list tables = function + | [] -> div_color_list, tables + | head::tail -> + + let rec build_column div_color_list trs = function + | [] -> div_color_list, trs + | head::tail -> + + let rec build_line div_color_list tds = function + | [] -> div_color_list, tds + | color::tail -> + + let color_div = build_color_div color in + build_line + (color_div::div_color_list) + ((build_td_color color_div)::tds) + tail + in + + let div_color_list', tds = build_line div_color_list [] head in + build_column + div_color_list' + ((build_tr_color tds)::trs) + tail + in + + let div_color_list', trs = build_column div_color_list [] head in + let tbl = table ~a:[a_class["ew_table_color_picker_table"]] trs in + build_table + div_color_list' + (tbl::tables) + tail + in + + let div_color_list, tables = build_table [] [] lll_color in + div_color_list, tables + +let create + ?(initial_color = 0, 0, 0) ?(lll_color = Lazy.force lll_color_p5) () = + let tbl, trl, tdl = initial_color in + let color_ref = ref (List.nth (List.nth (List.nth lll_color tbl) trl) tdl) in + let div_color_list, tables = genere_color_table lll_color in + let color_div = D.div ~a:[a_class["ew_table_color_picker_color_div"]; + a_title !color_ref; + a_style ("background-color: " ^ !color_ref ^ ";")] [] + in + let block = D.div ~a:[a_class["ew_table_color_picker_block"]] tables in + let type_t = (color_ref, color_div, div_color_list, block) in + type_t, color_div, block + +] + +[%%client + +open Lwt + +let fusion (color_ref, color_div, fst_list, block) (_, _, snd_list, _) = + (color_ref, color_div, fst_list@snd_list, block) + +let start (color_ref, color_div, color_list, _) = + let dom_color_div = Eliom_content.Html.To_dom.of_element color_div in + let rec aux = function + | [] -> () + | div_elt::tail -> + let dom_div = Eliom_content.Html.To_dom.of_element div_elt in + Lwt.async (fun () -> + Lwt_js_events.clicks dom_div (fun _ _ -> + Lwt.return + (let color = dom_div##.title in + dom_color_div##.style##.backgroundColor := color; + dom_color_div##.title := color; + color_ref := (Js.to_string color)))); + aux tail + in aux color_list + +let genere_and_append (color_ref, color_div, fst_list, block) new_list = + let div_color_list, tables = genere_color_table new_list in + let aux = function + | tbl::t -> Eliom_content.Html.Manip.appendChild block tbl + | [] -> () + in aux tables; + div_color_list + +let add_square_color color_picker new_list = + let color_ref, color_div, fst_list, block = color_picker in + color_ref, color_div, + fst_list@(genere_and_append color_picker new_list), block + +let add_square_color_and_start color_picker new_list = + let color_ref, color_div, fst_list, block = color_picker in + ignore (start (color_ref, color_div, + genere_and_append color_picker new_list, block)) + +let get_color (color_ref, _ , _, _) = !color_ref + +let get_square_color_div_list (_, _, color_list, _) = color_list + +] diff --git a/src/widgets/ot_color_picker.eliomi b/src/widgets/ot_color_picker.eliomi new file mode 100644 index 00000000..156c2e2a --- /dev/null +++ b/src/widgets/ot_color_picker.eliomi @@ -0,0 +1,64 @@ +[%%shared.start] + +type t +type div = Html_types.div Eliom_content.Html.D.elt + +(** The agrument is the divisor of 255 +*** It have to be greater than 1 **) +val genere_lll_color : int -> string list list list + +(* Some pre-genereated lll_color in several precision *) +val lll_color_p2 : string list list list Lazy.t +val lll_color_p3 : string list list list Lazy.t +val lll_color_p4 : string list list list Lazy.t +val lll_color_p5 : string list list list Lazy.t +val lll_color_p6 : string list list list Lazy.t + +(* Some hand-mained lll_color *) +val lll_color_6 : string list list list (* 1 table 2 columns 5 lines *) +val lll_color_10 : string list list list (* 1 table 2 columns 3 lines *) + +(** +*** Take one list (tables) of list (columns) of list (lines) of color (string) +*** and build table list with it. +*** By default this list is initialised with lll_color_p5 +*** +*** It return +*** - t to future action, +*** - color_div, to display current select color, +*** it is not mandatory to include it in page +*** - and the block with all color square content in the genered table **) +val create : + ?initial_color: int * int * int -> + ?lll_color: string list list list -> + unit -> + (t * div * div) + + + +[%%client.start] + +(** Get two color_picker to fusion in single + This new color_picker use color squares of both + It use color_div of first color_picker given in argument + It also keep referend on first color_picker's block to future append color + + This action have to be made before start function *) +val fusion : t -> t -> t + +(** It allow to add square color and append directly in block + It have to be made before start *) +val add_square_color : t -> string list list list -> t + +(** Launch listeners *) +val start : t -> unit + +(** It allow to add square color after start + It have not to be used before start **) +val add_square_color_and_start : t -> string list list list -> unit + +(** It is not disturbe by fusion or add square **) +val get_color: t -> string + +(** get all square color div element *) +val get_square_color_div_list : t -> div list From 4b090da77e0e522c7328f994d172403b09e861f2 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 15:02:04 +0200 Subject: [PATCH 02/14] Fix genere -> generate typos --- src/widgets/ot_color_picker.eliom | 14 +++++++------- src/widgets/ot_color_picker.eliomi | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index d22f6ce5..79526fa6 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -9,7 +9,7 @@ type t = (string ref * div * div list * div) let raise_exception str = failwith "ew_table_color_picker." ^ str -let genere_lll_color precision = +let generate_lll_color precision = let color_list = match precision with | p when p <= 1 -> @@ -72,7 +72,7 @@ let lll_color_6 = [[["#BEC3C7"; "#7A8E8D"]; ** Take one list of list of list of color (string) and build table list with it. ** return also div_color_list to allow to launch start script detection **) -let genere_color_table lll_color = +let generate_color_table lll_color = let build_color_div color = D.div ~a:[a_class["ew_table_color_picker_square"]; @@ -128,7 +128,7 @@ let create ?(initial_color = 0, 0, 0) ?(lll_color = Lazy.force lll_color_p5) () = let tbl, trl, tdl = initial_color in let color_ref = ref (List.nth (List.nth (List.nth lll_color tbl) trl) tdl) in - let div_color_list, tables = genere_color_table lll_color in + let div_color_list, tables = generate_color_table lll_color in let color_div = D.div ~a:[a_class["ew_table_color_picker_color_div"]; a_title !color_ref; a_style ("background-color: " ^ !color_ref ^ ";")] [] @@ -162,8 +162,8 @@ let start (color_ref, color_div, color_list, _) = aux tail in aux color_list -let genere_and_append (color_ref, color_div, fst_list, block) new_list = - let div_color_list, tables = genere_color_table new_list in +let generate_and_append (color_ref, color_div, fst_list, block) new_list = + let div_color_list, tables = generate_color_table new_list in let aux = function | tbl::t -> Eliom_content.Html.Manip.appendChild block tbl | [] -> () @@ -173,12 +173,12 @@ let genere_and_append (color_ref, color_div, fst_list, block) new_list = let add_square_color color_picker new_list = let color_ref, color_div, fst_list, block = color_picker in color_ref, color_div, - fst_list@(genere_and_append color_picker new_list), block + fst_list@(generate_and_append color_picker new_list), block let add_square_color_and_start color_picker new_list = let color_ref, color_div, fst_list, block = color_picker in ignore (start (color_ref, color_div, - genere_and_append color_picker new_list, block)) + generate_and_append color_picker new_list, block)) let get_color (color_ref, _ , _, _) = !color_ref diff --git a/src/widgets/ot_color_picker.eliomi b/src/widgets/ot_color_picker.eliomi index 156c2e2a..e53ec467 100644 --- a/src/widgets/ot_color_picker.eliomi +++ b/src/widgets/ot_color_picker.eliomi @@ -5,9 +5,9 @@ type div = Html_types.div Eliom_content.Html.D.elt (** The agrument is the divisor of 255 *** It have to be greater than 1 **) -val genere_lll_color : int -> string list list list +val generate_lll_color : int -> string list list list -(* Some pre-genereated lll_color in several precision *) +(* Some pre-generated lll_color in several precision *) val lll_color_p2 : string list list list Lazy.t val lll_color_p3 : string list list list Lazy.t val lll_color_p4 : string list list list Lazy.t @@ -27,7 +27,7 @@ val lll_color_10 : string list list list (* 1 table 2 columns 3 lines *) *** - t to future action, *** - color_div, to display current select color, *** it is not mandatory to include it in page -*** - and the block with all color square content in the genered table **) +*** - and the block with all color square content in the generated table **) val create : ?initial_color: int * int * int -> ?lll_color: string list list list -> From ba78525b42569aeb45c07906c3cf172dfb980fec Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 15:17:22 +0200 Subject: [PATCH 03/14] Fix comments and change lll_color to color_samples --- src/widgets/ot_color_picker.eliom | 30 ++++++++++---------- src/widgets/ot_color_picker.eliomi | 45 +++++++++++++++--------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 79526fa6..8d5c42ce 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -9,7 +9,7 @@ type t = (string ref * div * div list * div) let raise_exception str = failwith "ew_table_color_picker." ^ str -let generate_lll_color precision = +let generate_color_samples precision = let color_list = match precision with | p when p <= 1 -> @@ -50,20 +50,20 @@ let generate_lll_color precision = (* Some pre-genereated ll_color in several precision *) -let lll_color_p2 = lazy (genere_lll_color 2) -let lll_color_p3 = lazy (genere_lll_color 3) -let lll_color_p4 = lazy (genere_lll_color 4) -let lll_color_p5 = lazy (genere_lll_color 5) -let lll_color_p6 = lazy (genere_lll_color 6) - -(* Some hand-mained lll_color *) -let lll_color_10 = [[["#E03625"; "#FF4B3A"]; +let color_samples_p2 = lazy (genere_color_samples 2) +let color_samples_p3 = lazy (genere_color_samples 3) +let color_samples_p4 = lazy (genere_color_samples 4) +let color_samples_p5 = lazy (genere_color_samples 5) +let color_samples_p6 = lazy (genere_color_samples 6) + +(* Some hand-mained color_samples *) +let color_samples_10 = [[["#E03625"; "#FF4B3A"]; ["#FF7E02"; "#FFC503"]; ["#01CD64"; "#AF58B9"]; ["#0198DD"; "#254760"]; ["#FFFFFF"; "#000000"]]] -let lll_color_6 = [[["#BEC3C7"; "#7A8E8D"]; +let color_samples_6 = [[["#BEC3C7"; "#7A8E8D"]; ["#1C3D50"; "#0280B4"]; ["#00A385"; "#A444B2"]]] @@ -72,7 +72,7 @@ let lll_color_6 = [[["#BEC3C7"; "#7A8E8D"]; ** Take one list of list of list of color (string) and build table list with it. ** return also div_color_list to allow to launch start script detection **) -let generate_color_table lll_color = +let generate_color_table color_samples = let build_color_div color = D.div ~a:[a_class["ew_table_color_picker_square"]; @@ -121,14 +121,14 @@ let generate_color_table lll_color = tail in - let div_color_list, tables = build_table [] [] lll_color in + let div_color_list, tables = build_table [] [] color_samples in div_color_list, tables let create - ?(initial_color = 0, 0, 0) ?(lll_color = Lazy.force lll_color_p5) () = + ?(initial_color = 0, 0, 0) ?(color_samples = Lazy.force color_samples_p5) () = let tbl, trl, tdl = initial_color in - let color_ref = ref (List.nth (List.nth (List.nth lll_color tbl) trl) tdl) in - let div_color_list, tables = generate_color_table lll_color in + let color_ref = ref (List.nth (List.nth (List.nth color_samples tbl) trl) tdl) in + let div_color_list, tables = generate_color_table color_samples in let color_div = D.div ~a:[a_class["ew_table_color_picker_color_div"]; a_title !color_ref; a_style ("background-color: " ^ !color_ref ^ ";")] [] diff --git a/src/widgets/ot_color_picker.eliomi b/src/widgets/ot_color_picker.eliomi index e53ec467..150dc4db 100644 --- a/src/widgets/ot_color_picker.eliomi +++ b/src/widgets/ot_color_picker.eliomi @@ -3,34 +3,35 @@ type t type div = Html_types.div Eliom_content.Html.D.elt -(** The agrument is the divisor of 255 -*** It have to be greater than 1 **) -val generate_lll_color : int -> string list list list +(** The agrument is the divisor of 255. It have to be greater than 1 *) +val generate_color_samples : int -> string list list list -(* Some pre-generated lll_color in several precision *) -val lll_color_p2 : string list list list Lazy.t -val lll_color_p3 : string list list list Lazy.t -val lll_color_p4 : string list list list Lazy.t -val lll_color_p5 : string list list list Lazy.t -val lll_color_p6 : string list list list Lazy.t +(* Some pre-generated color samples in several precision. Color samples + are list of list of list of colors represented in string of hexadecimal + values.*) +val color_samples_p2 : string list list list Lazy.t +val color_samples_p3 : string list list list Lazy.t +val color_samples_p4 : string list list list Lazy.t +val color_samples_p5 : string list list list Lazy.t +val color_samples_p6 : string list list list Lazy.t -(* Some hand-mained lll_color *) -val lll_color_6 : string list list list (* 1 table 2 columns 5 lines *) -val lll_color_10 : string list list list (* 1 table 2 columns 3 lines *) +(* Some hand-mained color samples. *) +val color_samples_6 : string list list list (* 1 table 2 columns 5 lines *) +val color_samples_10 : string list list list (* 1 table 2 columns 3 lines *) (** -*** Take one list (tables) of list (columns) of list (lines) of color (string) -*** and build table list with it. -*** By default this list is initialised with lll_color_p5 -*** -*** It return -*** - t to future action, -*** - color_div, to display current select color, -*** it is not mandatory to include it in page -*** - and the block with all color square content in the generated table **) + Take one list (tables) of list (columns) of list (lines) of color (string) + and build table list with it. + By default this list is initialised with color_samples_p5 + + It return + - t to future action, + - color_div, to display current select color, + it is not mandatory to include it in page + - and the block with all color square content in the generated table *) val create : ?initial_color: int * int * int -> - ?lll_color: string list list list -> + ?color_samples: string list list list -> unit -> (t * div * div) From c7b594a9e93a4678a289232ea0be4f25c47caae3 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 15:21:07 +0200 Subject: [PATCH 04/14] Fix style issues (alignment) and typo --- src/widgets/ot_color_picker.eliom | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 8d5c42ce..04357c50 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -14,7 +14,7 @@ let generate_color_samples precision = let color_list = match precision with | p when p <= 1 -> ignore (raise_exception - "genere_list_color, the argument have to be greater than 1"); + "generate_list_color, the argument have to be greater than 1"); [] | precision -> let step = 255 / (precision - 1) in @@ -58,14 +58,14 @@ let color_samples_p6 = lazy (genere_color_samples 6) (* Some hand-mained color_samples *) let color_samples_10 = [[["#E03625"; "#FF4B3A"]; - ["#FF7E02"; "#FFC503"]; - ["#01CD64"; "#AF58B9"]; - ["#0198DD"; "#254760"]; - ["#FFFFFF"; "#000000"]]] + ["#FF7E02"; "#FFC503"]; + ["#01CD64"; "#AF58B9"]; + ["#0198DD"; "#254760"]; + ["#FFFFFF"; "#000000"]]] let color_samples_6 = [[["#BEC3C7"; "#7A8E8D"]; - ["#1C3D50"; "#0280B4"]; - ["#00A385"; "#A444B2"]]] + ["#1C3D50"; "#0280B4"]; + ["#00A385"; "#A444B2"]]] (** From 83a98b113c643ab8efb517c0b6cbbdaddeec3a04 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 15:33:57 +0200 Subject: [PATCH 05/14] ot_color_picker.eliom : Fix comments issues. --- src/widgets/ot_color_picker.eliom | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 04357c50..0168e1ab 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -49,14 +49,14 @@ let generate_color_samples precision = in aux_red [] 0 -(* Some pre-genereated ll_color in several precision *) +(* Some pre-generated color samples in several precisions. *) let color_samples_p2 = lazy (genere_color_samples 2) let color_samples_p3 = lazy (genere_color_samples 3) let color_samples_p4 = lazy (genere_color_samples 4) let color_samples_p5 = lazy (genere_color_samples 5) let color_samples_p6 = lazy (genere_color_samples 6) -(* Some hand-mained color_samples *) +(* Some hand-mained color samples *) let color_samples_10 = [[["#E03625"; "#FF4B3A"]; ["#FF7E02"; "#FFC503"]; ["#01CD64"; "#AF58B9"]; @@ -68,10 +68,8 @@ let color_samples_6 = [[["#BEC3C7"; "#7A8E8D"]; ["#00A385"; "#A444B2"]]] -(** -** Take one list of list of list of color (string) and build table list with it. -** return also div_color_list to allow to launch start script detection -**) +(* Take one list of list of list of color (string) and build table list with it. + return also div_color_list to allow to launch start script detection. *) let generate_color_table color_samples = let build_color_div color = From 19ec8c4467856ec6042d32945ebf40443219c501 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 15:42:25 +0200 Subject: [PATCH 06/14] ot_color_picker.eliom : Fix genere to generate typos. --- src/widgets/ot_color_picker.eliom | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 0168e1ab..aa6ac696 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -50,11 +50,11 @@ let generate_color_samples precision = (* Some pre-generated color samples in several precisions. *) -let color_samples_p2 = lazy (genere_color_samples 2) -let color_samples_p3 = lazy (genere_color_samples 3) -let color_samples_p4 = lazy (genere_color_samples 4) -let color_samples_p5 = lazy (genere_color_samples 5) -let color_samples_p6 = lazy (genere_color_samples 6) +let color_samples_p2 = lazy (generate_color_samples 2) +let color_samples_p3 = lazy (generate_color_samples 3) +let color_samples_p4 = lazy (generate_color_samples 4) +let color_samples_p5 = lazy (generate_color_samples 5) +let color_samples_p6 = lazy (generate_color_samples 6) (* Some hand-mained color samples *) let color_samples_10 = [[["#E03625"; "#FF4B3A"]; From 8a6c7c570c27a1fbb32fe73225306192c628be84 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 15:55:57 +0200 Subject: [PATCH 07/14] ot_color_picker.eliom : add raise_color_sample_exception helper. --- src/widgets/ot_color_picker.eliom | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index aa6ac696..a54153eb 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -6,16 +6,15 @@ open Eliom_content.Html.F type div = Html_types.div Eliom_content.Html.D.elt type t = (string ref * div * div list * div) -let raise_exception str = - failwith "ew_table_color_picker." ^ str +let raise_color_samples_exception () = + let message = "Ot_color_picker.generate_color_samples, \ + the argument have to be greater than 1" in + invalid_arg message let generate_color_samples precision = let color_list = match precision with - | p when p <= 1 -> - ignore (raise_exception - "generate_list_color, the argument have to be greater than 1"); - [] + | p when p <= 1 -> raise_color_samples_exception () | precision -> let step = 255 / (precision - 1) in let rec aux_build nl v = From 2551b948ff83ccdf47f0297b17aee63888047967 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 16:16:32 +0200 Subject: [PATCH 08/14] ot_color_picker.eliomi: improve comments. --- src/widgets/ot_color_picker.eliomi | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/widgets/ot_color_picker.eliomi b/src/widgets/ot_color_picker.eliomi index 150dc4db..1e58725c 100644 --- a/src/widgets/ot_color_picker.eliomi +++ b/src/widgets/ot_color_picker.eliomi @@ -1,9 +1,14 @@ [%%shared.start] +(** Ot_color_picker : this module allows to generate, client side, a color + selector. This selector consists of a color table and an html div that + displays the current selected color. *) + +(** The main type of Ot_color_picker module *) type t type div = Html_types.div Eliom_content.Html.D.elt -(** The agrument is the divisor of 255. It have to be greater than 1 *) +(** The argument is the divisor of 255. It have to be greater than 1 *) val generate_color_samples : int -> string list list list (* Some pre-generated color samples in several precision. Color samples @@ -19,9 +24,8 @@ val color_samples_p6 : string list list list Lazy.t val color_samples_6 : string list list list (* 1 table 2 columns 5 lines *) val color_samples_10 : string list list list (* 1 table 2 columns 3 lines *) -(** - Take one list (tables) of list (columns) of list (lines) of color (string) - and build table list with it. +(** Take one list (tables) of list (columns) of list (lines) of color (string) + and build the table of colors with it. By default this list is initialised with color_samples_p5 It return @@ -39,26 +43,27 @@ val create : [%%client.start] -(** Get two color_picker to fusion in single - This new color_picker use color squares of both - It use color_div of first color_picker given in argument - It also keep referend on first color_picker's block to future append color +(** Get two color_picker to fusion in a single one. This new color_picker uses + color squares of both. + It uses color_div of first color_picker given in argument. It also keeps + referend on first color_picker's block to future append color - This action have to be made before start function *) + This action has to be done before using the start function *) val fusion : t -> t -> t -(** It allow to add square color and append directly in block - It have to be made before start *) +(** It allows to add square color and to append directly in block + It has to be made before start *) val add_square_color : t -> string list list list -> t (** Launch listeners *) val start : t -> unit -(** It allow to add square color after start - It have not to be used before start **) +(** It allows to add square color after the start function. It have not to be + used before start *) val add_square_color_and_start : t -> string list list list -> unit -(** It is not disturbe by fusion or add square **) +(** Get the currently selected color of the selector. The fusion or add_square + functions have no effects on it. *) val get_color: t -> string (** get all square color div element *) From 75bb2db6a3722aa38566f00c604030e959b246c1 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 18:10:50 +0200 Subject: [PATCH 09/14] Rename CSS classes --- src/widgets/ot_color_picker.eliom | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index a54153eb..73127cf7 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -72,16 +72,16 @@ let color_samples_6 = [[["#BEC3C7"; "#7A8E8D"]; let generate_color_table color_samples = let build_color_div color = - D.div ~a:[a_class["ew_table_color_picker_square"]; + D.div ~a:[a_class["ot-color-picker-square"]; a_title color; a_style ("background-color: " ^ color ^ ";")] [] in let build_td_color color_div = - td ~a:[a_class["ew_table_color_picker_td"]] [color_div] + td ~a:[a_class["ot-color-picker-table-td"]] [color_div] in let build_tr_color tds = - tr ~a:[a_class["ew_table_color_picker_tr"]] tds + tr ~a:[a_class["ot-color-picker-table-tr"]] tds in let rec build_table div_color_list tables = function @@ -111,7 +111,7 @@ let generate_color_table color_samples = in let div_color_list', trs = build_column div_color_list [] head in - let tbl = table ~a:[a_class["ew_table_color_picker_table"]] trs in + let tbl = table ~a:[a_class["ot-color-picker-table"]] trs in build_table div_color_list' (tbl::tables) @@ -126,11 +126,11 @@ let create let tbl, trl, tdl = initial_color in let color_ref = ref (List.nth (List.nth (List.nth color_samples tbl) trl) tdl) in let div_color_list, tables = generate_color_table color_samples in - let color_div = D.div ~a:[a_class["ew_table_color_picker_color_div"]; + let color_div = D.div ~a:[a_class["ot-color-picker-current-color"]; a_title !color_ref; a_style ("background-color: " ^ !color_ref ^ ";")] [] in - let block = D.div ~a:[a_class["ew_table_color_picker_block"]] tables in + let block = D.div ~a:[a_class["ot-color-picker-block"]] tables in let type_t = (color_ref, color_div, div_color_list, block) in type_t, color_div, block From 379b14c6bb7d527f603d7e29b830e5255133f2db Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 18:11:15 +0200 Subject: [PATCH 10/14] Add a CSS file for the color picker --- css/ot_color_picker.css | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 css/ot_color_picker.css diff --git a/css/ot_color_picker.css b/css/ot_color_picker.css new file mode 100644 index 00000000..f96f4a97 --- /dev/null +++ b/css/ot_color_picker.css @@ -0,0 +1,26 @@ +/* It regroups one table of colors */ +.ot-color-picker-table { +} + +.ot-color-picker-table-td { +} + +.ot-color-picker-table-tr { +} + +/* A class for the div contained in each table cell. It is used to display the + * color to select. */ +.ot-color-picker-square { + height: 0.9em; + width: 0.9em; + border-radius:0.1em; +} + +/* The set of tables of colors */ +.ot-color-picker-block { +} + + +/* A class for the div that displays the currently selected color. */ +.ot-color-picker-current-color { +} From 49d599c0a6fe80801164459cc13a8c9200ea58a1 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 25 May 2017 18:15:55 +0200 Subject: [PATCH 11/14] Rename Ot_color_picker.create to Ot_color_picker.make --- src/widgets/ot_color_picker.eliom | 3 +-- src/widgets/ot_color_picker.eliomi | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 73127cf7..5e76fb67 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -121,8 +121,7 @@ let generate_color_table color_samples = let div_color_list, tables = build_table [] [] color_samples in div_color_list, tables -let create - ?(initial_color = 0, 0, 0) ?(color_samples = Lazy.force color_samples_p5) () = +let make ?(initial_color = 0, 0, 0) ?(color_samples = Lazy.force color_samples_p5) () = let tbl, trl, tdl = initial_color in let color_ref = ref (List.nth (List.nth (List.nth color_samples tbl) trl) tdl) in let div_color_list, tables = generate_color_table color_samples in diff --git a/src/widgets/ot_color_picker.eliomi b/src/widgets/ot_color_picker.eliomi index 1e58725c..9c2f20f8 100644 --- a/src/widgets/ot_color_picker.eliomi +++ b/src/widgets/ot_color_picker.eliomi @@ -33,7 +33,7 @@ val color_samples_10 : string list list list (* 1 table 2 columns 3 lines *) - color_div, to display current select color, it is not mandatory to include it in page - and the block with all color square content in the generated table *) -val create : +val make : ?initial_color: int * int * int -> ?color_samples: string list list list -> unit -> From 5d61d329b4f30625273149cc854f414b55aa2dd3 Mon Sep 17 00:00:00 2001 From: cedlemo Date: Wed, 31 May 2017 22:40:16 +0200 Subject: [PATCH 12/14] Fix style issue : use if instead of matching pattern --- src/widgets/ot_color_picker.eliom | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 5e76fb67..0ce29385 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -13,9 +13,9 @@ let raise_color_samples_exception () = let generate_color_samples precision = - let color_list = match precision with - | p when p <= 1 -> raise_color_samples_exception () - | precision -> + let color_list = + if precision <= 1 || precision > 256 then raise_color_samples_exception () + else let step = 255 / (precision - 1) in let rec aux_build nl v = if (v > 255) From a24217838ea2f35c7283d7a0f4dde478b949cb0c Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 1 Jun 2017 18:30:09 +0200 Subject: [PATCH 13/14] Improve generate_color_samples function --- src/widgets/ot_color_picker.eliom | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index 0ce29385..d3e338fc 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -12,7 +12,6 @@ let raise_color_samples_exception () = invalid_arg message let generate_color_samples precision = - let color_list = if precision <= 1 || precision > 256 then raise_color_samples_exception () else @@ -22,31 +21,11 @@ let generate_color_samples precision = then nl else aux_build ((Printf.sprintf "%02X" v)::nl) (v + step) in aux_build [] 0 - in - let max_iteration = List.length color_list in - - let rec aux_red nl = function - | n when n >= max_iteration -> nl - | n -> - let red = List.nth color_list n in - - let rec aux_green nl = function - | n when n >= max_iteration -> nl - | n -> - let green = List.nth color_list n in - - let rec aux_blue nl = function - | n when n >= max_iteration -> nl - | n -> - let blue = List.nth color_list n in - aux_blue (("#" ^ red ^ green ^ blue)::nl) (n + 1) - - in aux_green ((aux_blue [] 0)::nl) (n + 1) - - in aux_red ((aux_green [] 0)::nl) (n + 1) - - in aux_red [] 0 - + in List.map (fun red -> + List.map (fun green -> + List.map (fun blue -> + String.concat "" ["#"; red; green; blue] + ) color_list ) color_list ) color_list (* Some pre-generated color samples in several precisions. *) let color_samples_p2 = lazy (generate_color_samples 2) From 746a3cf9f712b81d02e08dddc3ad50cecd2ef27e Mon Sep 17 00:00:00 2001 From: cedlemo Date: Thu, 1 Jun 2017 18:50:33 +0200 Subject: [PATCH 14/14] Improve comments --- src/widgets/ot_color_picker.eliom | 4 +-- src/widgets/ot_color_picker.eliomi | 39 ++++++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/widgets/ot_color_picker.eliom b/src/widgets/ot_color_picker.eliom index d3e338fc..34497bf8 100644 --- a/src/widgets/ot_color_picker.eliom +++ b/src/widgets/ot_color_picker.eliom @@ -46,8 +46,8 @@ let color_samples_6 = [[["#BEC3C7"; "#7A8E8D"]; ["#00A385"; "#A444B2"]]] -(* Take one list of list of list of color (string) and build table list with it. - return also div_color_list to allow to launch start script detection. *) +(* Take a list of lists of lists of colors (strings) and returns a table list. + Also returns a div_color_list for launching start script detection. *) let generate_color_table color_samples = let build_color_div color = diff --git a/src/widgets/ot_color_picker.eliomi b/src/widgets/ot_color_picker.eliomi index 9c2f20f8..b5e01e4d 100644 --- a/src/widgets/ot_color_picker.eliomi +++ b/src/widgets/ot_color_picker.eliomi @@ -8,31 +8,33 @@ type t type div = Html_types.div Eliom_content.Html.D.elt -(** The argument is the divisor of 255. It have to be greater than 1 *) +(** The argument is the divisor of 255. It has to be greater than 1 *) val generate_color_samples : int -> string list list list -(* Some pre-generated color samples in several precision. Color samples - are list of list of list of colors represented in string of hexadecimal - values.*) +(** Some pre-generated color samples in several precision. Color samples + are list of lists of lists of colors represented in string of hexadecimal + values.*) + val color_samples_p2 : string list list list Lazy.t val color_samples_p3 : string list list list Lazy.t val color_samples_p4 : string list list list Lazy.t val color_samples_p5 : string list list list Lazy.t val color_samples_p6 : string list list list Lazy.t -(* Some hand-mained color samples. *) +(** Some hand-mained color samples. *) + val color_samples_6 : string list list list (* 1 table 2 columns 5 lines *) val color_samples_10 : string list list list (* 1 table 2 columns 3 lines *) -(** Take one list (tables) of list (columns) of list (lines) of color (string) - and build the table of colors with it. +(** Take one list (tables) of lists (columns) of lists (lines) of colors (string) + and builds the table of colors with it. By default this list is initialised with color_samples_p5 - It return - - t to future action, - - color_div, to display current select color, - it is not mandatory to include it in page - - and the block with all color square content in the generated table *) + It returns + - t for future actions, + - color_div, to display the currently selected color, + it is not mandatory to include it in the page + - and the block with all the color squares in the generated table *) val make : ?initial_color: int * int * int -> ?color_samples: string list list list -> @@ -43,15 +45,16 @@ val make : [%%client.start] -(** Get two color_picker to fusion in a single one. This new color_picker uses - color squares of both. - It uses color_div of first color_picker given in argument. It also keeps - referend on first color_picker's block to future append color - +(** Get two color pickers to fusion in a single one. This new color picker uses + the color squares of both. + It uses color_div of the first color picker given in argument. It also keeps + a reference to the first color picker's block for appending a color in the + future. This action has to be done before using the start function *) val fusion : t -> t -> t -(** It allows to add square color and to append directly in block +(** It allows to add square color and to append directly in the block that + contains the square colors. It has to be made before start *) val add_square_color : t -> string list list list -> t