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