Tweak pretty example
This commit is contained in:
bovenliggende
6d46dfc677
commit
ac32d8a5cf
|
@ -73,12 +73,20 @@ let celsius_edit =
|
|||
~on_submit:ignore
|
||||
|
||||
let root =
|
||||
Lwd_utils.pack Ui.pack_y [
|
||||
Lwd.pure (Nottui_widgets.string "Celsius:");
|
||||
celsius_edit;
|
||||
Lwd.pure (Nottui_widgets.string "Farenheight:");
|
||||
farenheit_edit;
|
||||
]
|
||||
let base =
|
||||
Lwd_utils.pack Ui.pack_y [
|
||||
Lwd.pure (Nottui_widgets.string "Celsius:");
|
||||
celsius_edit;
|
||||
Lwd.pure (Nottui_widgets.string "Farenheight:");
|
||||
farenheit_edit;
|
||||
]
|
||||
in
|
||||
let base = Lwd.map2 Ui.join_y base base in
|
||||
let base = Lwd.map2 Ui.join_y base base in
|
||||
let base = Lwd.map2 Ui.join_y base base in
|
||||
let base = Lwd.map2 Ui.join_y base base in
|
||||
let base = Lwd.map2 Ui.join_y base base in
|
||||
base
|
||||
|
||||
(*let () = Statmemprof_emacs.start 1E-4 30 5*)
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
open Nottui
|
||||
module P = Nottui_pretty
|
||||
|
||||
let string ?attr text = P.ui (Nottui_widgets.string ?attr text)
|
||||
|
@ -6,14 +7,52 @@ let (^^) = P.(^^)
|
|||
let (^/^) a b = P.(a ^^ break 1 ^^ b)
|
||||
|
||||
|
||||
let doc =
|
||||
List.fold_left (^^) P.empty [
|
||||
P.group (string "This" ^/^ string "is" ^/^ string "pretty.");
|
||||
P.hardline; P.ui (Nottui.Ui.void 0 1); P.hardline;
|
||||
P.group (P.group (string "This" ^/^ string "is") ^/^ string "pretty.");
|
||||
P.hardline; P.ui (Nottui.Ui.void 0 1); P.hardline;
|
||||
P.group (string "This" ^/^ P.group (string "is" ^/^ string "pretty."));
|
||||
]
|
||||
let spring = P.ui (Ui.resize ~sw:1 Ui.empty)
|
||||
|
||||
let selector text f choices =
|
||||
Nottui_widgets.main_menu_item text (fun () ->
|
||||
Lwd.pure @@
|
||||
Lwd_utils.pure_pack Ui.pack_y (
|
||||
List.map
|
||||
(fun choice ->
|
||||
Nottui_widgets.sub_entry choice (fun () -> f choice))
|
||||
choices
|
||||
)
|
||||
)
|
||||
|
||||
let fruit =
|
||||
let fruits = ["Apple"; "Orange"; "Strawberry"] in
|
||||
let choice = Lwd.var (List.hd fruits) in
|
||||
Lwd.join (
|
||||
Lwd.map' (Lwd.get choice) (fun current ->
|
||||
selector current (Lwd.set choice) fruits
|
||||
)
|
||||
)
|
||||
|
||||
let doc = Lwd_table.make ()
|
||||
|
||||
let () =
|
||||
for _ = 0 to 99 do
|
||||
List.iter (fun doc' -> Lwd_table.append' doc (Lwd.pure doc'))
|
||||
[
|
||||
P.group (string "This" ^/^ string "is" ^/^ string "pretty.");
|
||||
P.hardline; P.ui (Nottui.Ui.void 0 1); P.hardline;
|
||||
P.group (P.group (string "This" ^/^ string "is") ^/^ string "pretty.");
|
||||
P.hardline; P.ui (Nottui.Ui.void 0 1); P.hardline;
|
||||
P.group (string "This" ^/^ P.group (string "is" ^/^ string "pretty."));
|
||||
P.hardline; P.ui (Nottui.Ui.void 0 1); P.hardline;
|
||||
P.group (spring ^^ string "This" ^^ spring ^/^
|
||||
P.group (string "is" ^^ spring ^/^ string "pretty.") ^^ spring);
|
||||
P.hardline; P.ui (Nottui.Ui.void 0 1); P.hardline;
|
||||
];
|
||||
Lwd_table.append' doc
|
||||
(Lwd.map' fruit (fun fruit ->
|
||||
P.group (spring ^^ string "I" ^^ spring ^/^
|
||||
P.group (string "like" ^^ spring ^/^
|
||||
P.ui fruit ^^ spring ^/^
|
||||
string "more.") ^^ spring);
|
||||
))
|
||||
done
|
||||
|
||||
let varying_width f =
|
||||
let width = Lwd.var 0 in
|
||||
|
@ -24,9 +63,14 @@ let varying_width f =
|
|||
(fun w _ -> if Lwd.peek width <> w then Lwd.set width w)
|
||||
(Nottui.Ui.resize ~sw:1 ~sh:1 ~w:0 ui))
|
||||
|
||||
let doc =
|
||||
Lwd.join (Lwd_table.reduce (Lwd_utils.lift_monoid (P.empty, P.(^^))) doc)
|
||||
|
||||
let contents width = Lwd.map2' width doc P.pretty
|
||||
|
||||
let () =
|
||||
Nottui.Ui_loop.run (
|
||||
Nottui_widgets.h_pane
|
||||
(varying_width (Lwd.map (fun width -> P.pretty width doc)))
|
||||
(Nottui_widgets.scroll_area (varying_width contents))
|
||||
(Lwd.pure Nottui.Ui.empty)
|
||||
)
|
||||
|
|
|
@ -508,18 +508,18 @@ struct
|
|||
let h = I.height image in
|
||||
I.pad ~l:ox ~t:oy ~r:(rw - w - ox) ~b:(rh - h - oy) image
|
||||
|
||||
let same_size w h image =
|
||||
(*let same_size w h image =
|
||||
w = I.width image &&
|
||||
h = I.height image
|
||||
h = I.height image*)
|
||||
|
||||
let rec render_node vx1 vy1 vx2 vy2 sw sh t : cache =
|
||||
if
|
||||
(*if
|
||||
let cache = t.cache in
|
||||
vx1 >= cache.vx1 && vy1 >= cache.vy1 &&
|
||||
vx2 <= cache.vx2 && vy2 <= cache.vy2 &&
|
||||
same_size sw sh cache.image
|
||||
then t.cache
|
||||
else if vx2 < 0 || vy2 < 0 || sw < vx1 || sh < vy1 then
|
||||
else*) if vx2 < 0 || vy2 < 0 || sw < vx1 || sh < vy1 then
|
||||
{ vx1; vy1; vx2; vy2; image = I.void sw sh; overlays = [] }
|
||||
else
|
||||
let cache = match t.desc with
|
||||
|
|
Laden…
Verwijs in nieuw issue