···1515 let default_scroll_state = { position = 0; bound = 0 }
16161717 (** Primative for implementing scrolling, should be avoided unless you actually have reason to be changing the scroll state *)
1818- let vscroll_area_intern ~state ~change t =
1818+ let vscroll_area_intern ?(reset_on_content_change = true) ~state ~change t =
1919 let visible = ref (-1) in
2020 let total = ref (-1) in
2121 let scroll state delta =
···5959 else false
6060 in
6161 if tchange || vchange
6262- then change `Content { state with bound = maxi 0 (!total - !visible) })
6262+ then
6363+ change
6464+ `Content
6565+ { position = (if reset_on_content_change then 0 else state.position)
6666+ ; bound = maxi 0 (!total - !visible)
6767+ })
6368 |> Ui.mouse_area (scroll_handler state)
6469 |> Ui.keyboard_area (focus_handler state)
6570 (*restore original max height*)
6671 |> Ui.resize ~mh:tmh)
6772 ;;
68736969- let scroll_area_intern ?focus ~state ~change t =
7474+ let scroll_area_intern ?(reset_on_content_change = true) ?focus ~state ~change t =
7075 let open Lwd_utils in
7176 let w_visible = ref (-1) in
7277 let w_total = ref (-1) in
···132137 else false
133138 in
134139 if tchange || vchange
135135- then Some { state with bound = maxi 0 (!total - !visible) }
140140+ then
141141+ Some
142142+ { bound = maxi 0 (!total - !visible)
143143+ ; position = (if reset_on_content_change then 0 else state_w.position)
144144+ }
136145 else None
137146 in
138147 let w_update = sense tw w state_w w_total w_visible in
···151160152161open Internal
153162154154-let v_area ui =
163163+let v_area ?(reset_on_content_change = true) ui =
155164 let state = Lwd.var Internal.default_scroll_state in
156165 ui
157166 |> Internal.vscroll_area_intern ~change:(fun _ x -> state $= x) ~state:(Lwd.get state)
158167;;
159168160160-let area ?focus ui =
169169+let area ?(reset_on_content_change = true) ?focus ui =
161170 let state = Lwd.var (Internal.default_scroll_state, Internal.default_scroll_state) in
162171 ui
163172 |> Internal.scroll_area_intern
+2-2
forks/nottui/lib/nottui/widgets/scroll.mli
···11(** A keyboard scroll area that only scrolls in the vertical direction *)
22-val v_area : Nottui_main.ui Lwd.t -> Nottui_main.ui Lwd.t
22+val v_area : ?reset_on_content_change:bool -> Nottui_main.ui Lwd.t -> Nottui_main.ui Lwd.t
3344(** A scroll area that allows keyboard scrolling in both x and y directions*)
55-val area : ?focus:Nottui_main.Focus.status -> Nottui_main.ui Lwd.t -> Nottui_main.ui Lwd.t
55+val area : ?reset_on_content_change:bool -> ?focus:Nottui_main.Focus.status -> Nottui_main.ui Lwd.t -> Nottui_main.ui Lwd.t
6677(** A scroll area that allows keyboard scrolling in both x and y directions and has no limits.
88 This might be useful if you have some very dynamic content and the usual scroll area doesn't know how big things are*)