-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
lib/capytui/tui/scrollable_list/src/capytui_scrollable_list.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
open! Core | ||
open! Capytui | ||
open! Bonsai | ||
open Bonsai.Let_syntax | ||
|
||
module Action = struct | ||
type 'key t = | ||
| Down | ||
| Up | ||
| Top | ||
| Bottom | ||
| Up_half_page | ||
| Down_half_page | ||
| Scroll_to of 'key | ||
end | ||
|
||
type 'key t = | ||
{ view : Node.t | ||
; inject : 'key Action.t -> unit Effect.t | ||
; less_keybindings_handler : Event.t -> unit Effect.t | ||
} | ||
|
||
module type S = sig | ||
type t [@@deriving sexp, compare] | ||
|
||
include Comparable.S with type t := t | ||
end | ||
|
||
let component | ||
(type key cmp) | ||
(module M : S with type t = key and type comparator_witness = cmp) | ||
~dimensions:(_ : Dimensions.t Value.t) | ||
(items : (key, 'data, cmp) Core.Map.t Value.t) | ||
~(render : key Value.t -> 'data Value.t -> Node.t Computation.t) | ||
~compare:(_ : 'key * 'data -> 'key * 'data -> int) | ||
= | ||
let%sub rendered_nodes = | ||
Bonsai.assoc (module M) items ~f:(fun key data -> render key data) | ||
in | ||
let%sub alist = | ||
let%arr items = items in | ||
Core.Map.to_alist items | ||
in | ||
Bonsai.const | ||
{ view = Node.none | ||
; inject = (fun _ -> Effect.Ignore) | ||
; less_keybindings_handler = (fun _ -> Effect.Ignore) | ||
} | ||
;; |
34 changes: 34 additions & 0 deletions
34
lib/capytui/tui/scrollable_list/src/capytui_scrollable_list.mli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open! Core | ||
open Capytui | ||
open Bonsai | ||
|
||
module Action : sig | ||
type 'key t = | ||
| Down | ||
| Up | ||
| Top | ||
| Bottom | ||
| Up_half_page | ||
| Down_half_page | ||
| Scroll_to of 'key | ||
end | ||
|
||
type 'key t = | ||
{ view : Node.t | ||
; inject : 'key Action.t -> unit Effect.t | ||
; less_keybindings_handler : Event.t -> unit Effect.t | ||
} | ||
|
||
module type S = sig | ||
type t [@@deriving sexp, compare] | ||
|
||
include Comparable.S with type t := t | ||
end | ||
|
||
val component | ||
: (module S with type t = 'key and type comparator_witness = 'cmp) | ||
-> dimensions:Dimensions.t Value.t | ||
-> ('key, 'data, 'cmp) Core.Map.t Value.t | ||
-> render:('key Value.t -> 'data Value.t -> Node.t Computation.t) | ||
-> compare:('key * 'data -> 'key * 'data -> int) | ||
-> 'key t Computation.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(library | ||
(name capytui_scrollable_list) | ||
(libraries core bonsai capytui) | ||
(preprocess | ||
(pps ppx_jane bonsai.ppx_bonsai))) |