From 951efa362808952d4b48f0e4c3766f6d25ef194d Mon Sep 17 00:00:00 2001 From: maha-sachin Date: Thu, 4 Apr 2024 12:02:42 -0400 Subject: [PATCH] Updated the implementation for hscroll area --- lib/interactive_viewer.ml | 23 +++++++++++-- vendor/lwd/lib/nottui/nottui_widgets.ml | 42 ++++++++++++++++++++++++ vendor/lwd/lib/nottui/nottui_widgets.mli | 4 +++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/lib/interactive_viewer.ml b/lib/interactive_viewer.ml index 029f0c9..472e573 100644 --- a/lib/interactive_viewer.ml +++ b/lib/interactive_viewer.ml @@ -122,12 +122,19 @@ let view (patches : Patch.t list) = | None -> failwith "zipper_of_list: empty list" in let curr_scroll_state = Lwd.var W.default_scroll_state in + let curr_scroll_state_h = Lwd.var W.default_scroll_state in let change_scroll_state _action state = let off_screen = state.W.position > state.W.bound in if off_screen then Lwd.set curr_scroll_state { state with position = state.W.bound } else Lwd.set curr_scroll_state state in + let change_scroll_state_h _action state = + let off_screen = state.W.position > state.W.bound in + if off_screen then + Lwd.set curr_scroll_state_h { state with position = state.W.bound } + else Lwd.set curr_scroll_state_h state + in let ui = let$* help_visible = Lwd.get help in if help_visible then @@ -149,9 +156,19 @@ let view (patches : Patch.t list) = operation_info z_patches; change_summary z_patches; current_operation z_patches; - W.vscroll_area - ~state:(Lwd.get curr_scroll_state) - ~change:change_scroll_state + (* W.vscroll_area + ~state:(Lwd.get curr_scroll_state) + ~change:change_scroll_state + @@ W.hscroll_area + ~state:(Lwd.get curr_scroll_state_h) + ~change:change_scroll_state_h + @@ current_hunks z_patches; *) + W.hscroll_area + ~state:(Lwd.get curr_scroll_state_h) + ~change:change_scroll_state_h + @@ W.vscroll_area + ~state:(Lwd.get curr_scroll_state) + ~change:change_scroll_state @@ current_hunks z_patches; Lwd.pure @@ Ui.keyboard_area diff --git a/vendor/lwd/lib/nottui/nottui_widgets.ml b/vendor/lwd/lib/nottui/nottui_widgets.ml index c67e9c1..3b0356a 100644 --- a/vendor/lwd/lib/nottui/nottui_widgets.ml +++ b/vendor/lwd/lib/nottui/nottui_widgets.ml @@ -196,6 +196,48 @@ let vscroll_area ~state ~change t = |> Ui.mouse_area (scroll_handler state) |> Ui.keyboard_area (focus_handler state) end +let hscroll_area ~state ~change t = + let visible = ref (-1) in + let total = ref (-1) in + let scroll state delta = + let position = state.position + delta in + let position = clampi position ~min:0 ~max:state.bound in + if position <> state.position then + change `Action {state with position}; + `Handled + in + let focus_handler state = function + | `Arrow `Left , [] -> scroll state (-scroll_step) + | `Arrow `Right, [] -> scroll state (+scroll_step) + | _ -> `Unhandled + in + (* let scroll_handler state ~x:_ ~y:_ = function + | `Scroll `Up -> scroll state (0) + | `Scroll `Down -> scroll state (0) + | _ -> `Unhandled + in *) + Lwd.map2 t state ~f:begin fun t state -> + t + |> Ui.shift_area state.position 0 + |> Ui.resize ~w:0 ~sw:1 + |> Ui.size_sensor (fun ~w ~h:_ -> + let tchange = + if !total <> (Ui.layout_spec t).Ui.w + then (total := (Ui.layout_spec t).Ui.w; true) + else false + in + let vchange = + if !visible <> w + then (visible := w; true) + else false + in + if tchange || vchange then + change `Content {state with visible = !visible; total = !total; + bound = maxi 0 (!total - !visible); } + ) + (* |> Ui.mouse_area (scroll_handler state) *) + |> Ui.keyboard_area (focus_handler state) + end let scroll_area ?(offset=0,0) t = let offset = Lwd.var offset in diff --git a/vendor/lwd/lib/nottui/nottui_widgets.mli b/vendor/lwd/lib/nottui/nottui_widgets.mli index 071a764..22af24a 100644 --- a/vendor/lwd/lib/nottui/nottui_widgets.mli +++ b/vendor/lwd/lib/nottui/nottui_widgets.mli @@ -37,6 +37,10 @@ val vscroll_area : state:scroll_state Lwd.t -> change:([> `Action | `Content ] -> scroll_state -> unit) -> ui Lwd.t -> ui Lwd.t +val hscroll_area : + state:scroll_state Lwd.t -> + change:([> `Action | `Content ] -> scroll_state -> unit) -> + ui Lwd.t -> ui Lwd.t val scroll_area : ?offset:int * int -> ui Lwd.t -> ui Lwd.t