cursor works
This commit is contained in:
53
human.ml
53
human.ml
@ -809,9 +809,10 @@ module Panel = struct
|
||||
(`String str) )
|
||||
empty_append
|
||||
(empty_append, `Await)
|
||||
end
|
||||
|
||||
let text = Text.lines
|
||||
let text = of_string
|
||||
let nl = atom (`Boundary `Line)
|
||||
end
|
||||
|
||||
module Draw = struct
|
||||
open NVG
|
||||
@ -845,7 +846,6 @@ module Panel = struct
|
||||
let bounds = Text.bounds vg ~x:(V2.x t) ~y:(V2.y t) text in
|
||||
let metrics = Text.metrics vg in
|
||||
let x, y = (V2.x t, V2.y t +. metrics.ascender) in
|
||||
F.epr "Panel.Ui.Draw.uchar x=%f y=%f \"%s\" @." x y text ;
|
||||
Text.text vg ~x ~y text ;
|
||||
P2.v
|
||||
(P2.x t +. bounds.advance)
|
||||
@ -871,11 +871,14 @@ module Panel = struct
|
||||
| `Hint _ -> b
|
||||
| `Empty -> b
|
||||
|
||||
and attr vg t (a, n) : P2.t =
|
||||
and attr t b ((a : attr), n) : P2.t =
|
||||
match a with
|
||||
| `Style s -> node {vg with style= Style.merge vg.style s} t n
|
||||
| `Pad p -> pad vg t p n
|
||||
| _ -> node vg t n
|
||||
| `Style s ->
|
||||
Display.path_box t.vg s.bg
|
||||
(Box2.of_pts b
|
||||
(node {t with style= Style.merge t.style s} b n) )
|
||||
| `Pad p -> pad t b p n
|
||||
| _ -> node t b n
|
||||
|
||||
and pad vg t (p : Pad.t) n =
|
||||
let nv = node vg P2.(v (p.l +. x t) (p.t +. y t)) n in
|
||||
@ -899,7 +902,7 @@ module Panel = struct
|
||||
(Float.max_num (V2.y av) (V2.y bv))
|
||||
|
||||
and node t b (n : node) : P2.t =
|
||||
let b2 =
|
||||
let b' =
|
||||
match n.t with
|
||||
| `Atom a -> atom t b a
|
||||
| `Attr a -> attr t b a
|
||||
@ -907,8 +910,8 @@ module Panel = struct
|
||||
ignore
|
||||
(Display.path_box t.vg
|
||||
(Color.rgbaf ~r:1. ~g:0. ~b:0. ~a:0.2)
|
||||
(Box2.of_pts b b2) ) ;
|
||||
b2
|
||||
(Box2.of_pts b b') ) ;
|
||||
b'
|
||||
end
|
||||
|
||||
module Action = struct
|
||||
@ -1112,7 +1115,9 @@ module Panel = struct
|
||||
let open Key.Bind in
|
||||
empty
|
||||
|> add [([Ctrl], C 'f')] [`Move (`Forward `Char)]
|
||||
|> add [([], U (`Arrow `Right))] [`Move (`Forward `Char)]
|
||||
|> add [([Ctrl], C 'b')] [`Move (`Backward `Char)]
|
||||
|> add [([], U (`Arrow `Left))] [`Move (`Backward `Char)]
|
||||
|> add [([Meta], C 'f')] [`Move (`Forward `Word)]
|
||||
|> add [([Meta], C 'b')] [`Move (`Backward `Word)]
|
||||
|> add
|
||||
@ -1122,7 +1127,9 @@ module Panel = struct
|
||||
[([Ctrl], C 'c'); ([Ctrl], C 'p')]
|
||||
[`Move (`Backward `Phrase)]
|
||||
|> add [([Ctrl], C 'n')] [`Move (`Forward `Line)]
|
||||
|> add [([], U (`Arrow `Down))] [`Move (`Forward `Line)]
|
||||
|> add [([Ctrl], C 'p')] [`Move (`Backward `Line)]
|
||||
|> add [([], U (`Arrow `Up))] [`Move (`Backward `Line)]
|
||||
|> add [([Ctrl], C 'v')] [`Move (`Forward `Page)]
|
||||
|> add [([Meta], C 'v')] [`Move (`Backward `Page)]
|
||||
|> add [([Ctrl], C 'a')] [`Move (`Beginning `Line)]
|
||||
@ -1139,7 +1146,7 @@ module Panel = struct
|
||||
let cursor_attr =
|
||||
`Style Style.(bg NVG.Color.(rgbaf ~r:1. ~g:1. ~b:0. ~a:1.))
|
||||
|
||||
let textedit_handler ?(bindings = textedit_bindings) (n : node) =
|
||||
let textedit ?(bindings = textedit_bindings) (n : node) =
|
||||
Format.pp_set_max_boxes F.stderr 64 ;
|
||||
(*full screen fynn *)
|
||||
Format.pp_safe_set_geometry F.stderr ~max_indent:150 ~margin:230 ;
|
||||
@ -1150,12 +1157,10 @@ module Panel = struct
|
||||
`Attr
|
||||
( `Handler
|
||||
(fun (_ : node) (e : Event.t) : Event.t option ->
|
||||
Fmt.epr "textedit_handler@." ;
|
||||
match Key.Bind.resolve_events bind [e] with
|
||||
| x :: _ ->
|
||||
c.sel <- remove_attr c.sel ;
|
||||
(*F.epr
|
||||
"textedit_handler c.sel.n=%d@ c.root=@ @[%a@]@."
|
||||
pp_node_n c.sel pp_node_structure c.root ; *)
|
||||
( match perform_action x c with
|
||||
| Some n' ->
|
||||
F.epr "textedit action @[%a@] Success@."
|
||||
@ -1177,6 +1182,7 @@ module Panel = struct
|
||||
match f n with Some a -> Some a | None -> search_forward f n
|
||||
|
||||
let handle_event (n : node) (ev : Event.t) : event_status =
|
||||
Fmt.epr "handle_event@." ;
|
||||
match handler_of_node n with
|
||||
| Some f -> (
|
||||
match f n ev with Some ev -> `Event ev | None -> `Handled )
|
||||
@ -1187,22 +1193,17 @@ module Panel = struct
|
||||
( match handle_event t ev with
|
||||
| `Handled -> F.epr "Handled %s@." (Event.to_string ev)
|
||||
| `Event _e ->
|
||||
(* F.epr "Unhandled event: %s@."
|
||||
(Event.to_string _e)*)
|
||||
() ) ;
|
||||
F.epr "Unhandled event: %s@." (Event.to_string _e) ) ;
|
||||
Draw.node {vg; style= Style.dark} p t
|
||||
|
||||
let test =
|
||||
textedit_handler
|
||||
textedit
|
||||
(style Style.dark
|
||||
(join_y
|
||||
(join_y
|
||||
(Text.of_string "-- welcome to my land of idiocy ---")
|
||||
( ( Text.of_string "hello bitch"
|
||||
^^ Text.of_string "!\n sup daddy" )
|
||||
^/^ (text "hello bitch" ^^ text "!\n sup daddy")
|
||||
^/^ text "hello bitch" ^/^ text "!\n sup daddy" ) )
|
||||
(Text.of_string "123") ) )
|
||||
Text.(
|
||||
text "--- welcome to my land of idiocy ---"
|
||||
^/^ (text "hello bitch" ^^ text "! sup daddy" ^^ nl)
|
||||
^/^ lines "hello bitch" ^/^ lines "! sup daddy"
|
||||
^/^ lines "123") )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user