From 2d40d7f96758afa93586be850af4ab454aca8912 Mon Sep 17 00:00:00 2001 From: maha-sachin Date: Mon, 11 Mar 2024 18:48:49 -0400 Subject: [PATCH 01/19] for testing actions in main --- .github/workflows/ocaml-ci-setup.yml | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/ocaml-ci-setup.yml diff --git a/.github/workflows/ocaml-ci-setup.yml b/.github/workflows/ocaml-ci-setup.yml new file mode 100644 index 0000000..fa67c1e --- /dev/null +++ b/.github/workflows/ocaml-ci-setup.yml @@ -0,0 +1,50 @@ +name: CI Run test + +on: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + +jobs: +# See: https://github.com/ocaml/setup-ocaml + setup-ocaml: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup OCaml environment + run: setup-ocaml + + install-dependencies: + runs-on: ubuntu-latest + needs: setup-ocaml + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install project dependencies + run: opam install --deps-only -t -y + + run-tests: + runs-on: ubuntu-latest + needs: install-dependencies + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Run tests + run: dune runtest + + check-formatting: + runs-on: ubuntu-latest + needs: install-dependencies + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Check formatting + env: + OCAMLFORMAT: "0.26.1" + run: dune build @fmt + + From 903425d5ec9db0072d7a634f449c696a50a4631e Mon Sep 17 00:00:00 2001 From: maha-sachin Date: Mon, 11 Mar 2024 18:53:35 -0400 Subject: [PATCH 02/19] fix the yaml file --- .github/workflows/ocaml-ci-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ocaml-ci-setup.yml b/.github/workflows/ocaml-ci-setup.yml index fa67c1e..95966f4 100644 --- a/.github/workflows/ocaml-ci-setup.yml +++ b/.github/workflows/ocaml-ci-setup.yml @@ -34,7 +34,7 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Run tests - run: dune runtest + run: dune runtest check-formatting: runs-on: ubuntu-latest From 99957ddc8f2dda8c252cce58f41a49f87a444426 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 21:56:17 -0400 Subject: [PATCH 03/19] test-setup.yml --- .github/workflows/main.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ec7120e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,40 @@ +name: Builds, tests & co + +on: + push: + branches: + - "main" + pull_request: + branches: + - "main" + +permissions: read-all + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + ocaml-compiler: + - "5.1" + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout tree + uses: actions/checkout@v4 + + - name: Set-up OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v2 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + + - run: opam install . --deps-only --with-test + + - run: opam exec -- dune build + + - run: opam exec -- dune runtest From 08b5d256d5407a979d42c57afc33e9ef108ba7c1 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 21:59:57 -0400 Subject: [PATCH 04/19] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ec7120e..ce69763 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - ubuntu-latest - windows-latest ocaml-compiler: - - "5.1" + - "5.0" runs-on: ${{ matrix.os }} From 06650c00e20311fe88eb7ddd53ea3f5e384971cb Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 22:03:04 -0400 Subject: [PATCH 05/19] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce69763..145649d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,8 +30,8 @@ jobs: - name: Set-up OCaml ${{ matrix.ocaml-compiler }} uses: ocaml/setup-ocaml@v2 - with: - ocaml-compiler: ${{ matrix.ocaml-compiler }} + # with: + # ocaml-compiler: ${{ matrix.ocaml-compiler }} - run: opam install . --deps-only --with-test From f895e7666b36c8e405504361fd5363b9f74c2c38 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 22:06:53 -0400 Subject: [PATCH 06/19] Update main.yml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 145649d..9e6723f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - ubuntu-latest - windows-latest ocaml-compiler: - - "5.0" + - "5.1.0" runs-on: ${{ matrix.os }} @@ -30,8 +30,8 @@ jobs: - name: Set-up OCaml ${{ matrix.ocaml-compiler }} uses: ocaml/setup-ocaml@v2 - # with: - # ocaml-compiler: ${{ matrix.ocaml-compiler }} + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} - run: opam install . --deps-only --with-test From f8fd9bd175cccb407bd18100d470df51d3dc40d9 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 22:12:34 -0400 Subject: [PATCH 07/19] Update main.yml --- .github/workflows/main.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e6723f..1c0a0b1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,9 +18,9 @@ jobs: os: - macos-latest - ubuntu-latest - - windows-latest + # - windows-latest ocaml-compiler: - - "5.1.0" + - "5.1" runs-on: ${{ matrix.os }} @@ -33,8 +33,11 @@ jobs: with: ocaml-compiler: ${{ matrix.ocaml-compiler }} - - run: opam install . --deps-only --with-test + - name: Install Dependencies + run: opam install . --deps-only --with-test - - run: opam exec -- dune build + - name: Test + run: dune runtest - - run: opam exec -- dune runtest + - name: Format + run: dune fmt From 00713fb90e58c3f4a4f0e7e6c68f8c341fae273b Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 22:14:49 -0400 Subject: [PATCH 08/19] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c0a0b1..08730c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,10 +34,10 @@ jobs: ocaml-compiler: ${{ matrix.ocaml-compiler }} - name: Install Dependencies - run: opam install . --deps-only --with-test + run: opam install --deps-only -t -y . - name: Test run: dune runtest - name: Format - run: dune fmt + run: dune build @fmt From 66cc5b0e94ac6ad759166c598eddb0438f3319fc Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 22:28:38 -0400 Subject: [PATCH 09/19] Update main.yml --- .github/workflows/main.yml | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08730c7..8959df4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,36 @@ jobs: run: opam install --deps-only -t -y . - name: Test - run: dune runtest + run: opam exec -- dune runtest - name: Format - run: dune build @fmt + run: opam exec -- dune build @fmt + + # install-dependencies: + # runs-on: ubuntu-latest + # needs: setup-ocaml + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 + # - name: Install project dependencies + # run: opam install --deps-only -t -y + + # run-tests: + # runs-on: ubuntu-latest + # needs: install-dependencies + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 + # - name: Run tests + # run: dune runtest + + # check-formatting: + # runs-on: ubuntu-latest + # needs: install-dependencies + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 + # - name: Check formatting + # env: + # OCAMLFORMAT: "0.26.1" + # run: dune build @fmt From 57e4c8a4c7b37b10ad6bb1757d36e151b517d55e Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Mon, 11 Mar 2024 23:42:43 -0400 Subject: [PATCH 10/19] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8959df4..9828176 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,7 +40,7 @@ jobs: run: opam exec -- dune runtest - name: Format - run: opam exec -- dune build @fmt + run: opam install ocamlformat && opam exec -- dune build @fmt # install-dependencies: # runs-on: ubuntu-latest From cbc383140f934dd96f8a75b411f902f00143131a Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 00:01:42 -0400 Subject: [PATCH 11/19] Update main.yml --- .github/workflows/main.yml | 40 ++++++++------------------------------ 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9828176..2787481 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,9 +18,14 @@ jobs: os: - macos-latest - ubuntu-latest - # - windows-latest + - windows-latest ocaml-compiler: - "5.1" + include: + - os: windows-latest + ocaml-compiler: + - "4.14.0" + runs-on: ${{ matrix.os }} @@ -34,39 +39,10 @@ jobs: ocaml-compiler: ${{ matrix.ocaml-compiler }} - name: Install Dependencies - run: opam install --deps-only -t -y . + run: opam install ocamlformat@0.26.1 && opam install --deps-only -t -y . - name: Test run: opam exec -- dune runtest - name: Format - run: opam install ocamlformat && opam exec -- dune build @fmt - - # install-dependencies: - # runs-on: ubuntu-latest - # needs: setup-ocaml - # steps: - # - name: Checkout code - # uses: actions/checkout@v2 - # - name: Install project dependencies - # run: opam install --deps-only -t -y - - # run-tests: - # runs-on: ubuntu-latest - # needs: install-dependencies - # steps: - # - name: Checkout code - # uses: actions/checkout@v2 - # - name: Run tests - # run: dune runtest - - # check-formatting: - # runs-on: ubuntu-latest - # needs: install-dependencies - # steps: - # - name: Checkout code - # uses: actions/checkout@v2 - # - name: Check formatting - # env: - # OCAMLFORMAT: "0.26.1" - # run: dune build @fmt + run: opam exec -- dune build @fmt From e20dda5f575c7042845a8cfc4e37f2a42cf29708 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 00:07:01 -0400 Subject: [PATCH 12/19] Update main.yml --- .github/workflows/main.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2787481..6d21a1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,17 +15,13 @@ jobs: strategy: fail-fast: false matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest - ocaml-compiler: - - "5.1" include: + - os: macos-latest + ocaml-compiler: "5.1" + - os: ubuntu-latest + ocaml-compiler: "5.1" - os: windows-latest - ocaml-compiler: - - "4.14.0" - + ocaml-compiler: "4.14.0" runs-on: ${{ matrix.os }} From 7e2b2a375e130c1e7fea3b9314d6855a31fd4ae1 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 00:12:17 -0400 Subject: [PATCH 13/19] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d21a1b..774fd39 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: ocaml-compiler: ${{ matrix.ocaml-compiler }} - name: Install Dependencies - run: opam install ocamlformat@0.26.1 && opam install --deps-only -t -y . + run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . - name: Test run: opam exec -- dune runtest From 0161c902bc295ace25249db698804522206a10d5 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 00:35:28 -0400 Subject: [PATCH 14/19] Update main.yml --- .github/workflows/main.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 774fd39..53e0827 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,13 @@ jobs: ocaml-compiler: ${{ matrix.ocaml-compiler }} - name: Install Dependencies - run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . + run: | + opam install ocamlformat.0.26.1 + if [ "${{ runner.os }}" = "Windows" ]; then + opam depext diffcessible + fi + opam install --deps-only -t -y . + # run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . - name: Test run: opam exec -- dune runtest From 2489d15dfa777f8e657e0a9d15f8d49f90cfea94 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 01:00:06 -0400 Subject: [PATCH 15/19] Update main.yml --- .github/workflows/main.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53e0827..a97200c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,10 +38,16 @@ jobs: run: | opam install ocamlformat.0.26.1 if [ "${{ runner.os }}" = "Windows" ]; then - opam depext diffcessible + choco install diffutils + choco install diffstat fi - opam install --deps-only -t -y . - # run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . + opam install dune.3.11 --deps-only -t -y . + + # - name: Install Dependencies + # run: | + # opam install ocamlformat.0.26.1 + # opam install --deps-only -t -y . + # # run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . - name: Test run: opam exec -- dune runtest From d5675d091740d1ce0686ac4b6fc30e8aea85a311 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 01:09:00 -0400 Subject: [PATCH 16/19] Update main.yml --- .github/workflows/main.yml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a97200c..eea47b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,18 +36,9 @@ jobs: - name: Install Dependencies run: | - opam install ocamlformat.0.26.1 - if [ "${{ runner.os }}" = "Windows" ]; then - choco install diffutils - choco install diffstat - fi - opam install dune.3.11 --deps-only -t -y . - - # - name: Install Dependencies - # run: | - # opam install ocamlformat.0.26.1 - # opam install --deps-only -t -y . - # # run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . + opam install ocamlformat.0.26.1 + opam install --deps-only -t -y . + # run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . - name: Test run: opam exec -- dune runtest From 24605fd04fd109bdf69a4a21236ccea6d5283c10 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 09:36:21 -0400 Subject: [PATCH 17/19] Update main.yml --- .github/workflows/main.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eea47b7..529abe3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Builds, tests & co +name: CI on: push: @@ -15,18 +15,16 @@ jobs: strategy: fail-fast: false matrix: - include: - - os: macos-latest - ocaml-compiler: "5.1" - - os: ubuntu-latest - ocaml-compiler: "5.1" - - os: windows-latest - ocaml-compiler: "4.14.0" + os: + - macos-latest + - ubuntu-latest + ocaml-compiler: + - "5.1" runs-on: ${{ matrix.os }} steps: - - name: Checkout tree + - name: Checkout code uses: actions/checkout@v4 - name: Set-up OCaml ${{ matrix.ocaml-compiler }} @@ -38,7 +36,6 @@ jobs: run: | opam install ocamlformat.0.26.1 opam install --deps-only -t -y . - # run: opam install ocamlformat.0.26.1 && opam install --deps-only -t -y . - name: Test run: opam exec -- dune runtest From 024c620e42047624b5a17ec8e84dad90f0488e83 Mon Sep 17 00:00:00 2001 From: Mahalakshmi Date: Tue, 12 Mar 2024 10:06:34 -0400 Subject: [PATCH 18/19] Update main.yml --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 529abe3..9b9682b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: CI +name: Install, test and format on: push: @@ -15,10 +15,10 @@ jobs: strategy: fail-fast: false matrix: - os: + os: - macos-latest - ubuntu-latest - ocaml-compiler: + ocaml-compiler: - "5.1" runs-on: ${{ matrix.os }} @@ -27,15 +27,15 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set-up OCaml ${{ matrix.ocaml-compiler }} + - name: Set-up OCaml version:${{ matrix.ocaml-compiler }} in os:${{ matrix.os }} uses: ocaml/setup-ocaml@v2 with: ocaml-compiler: ${{ matrix.ocaml-compiler }} - name: Install Dependencies run: | - opam install ocamlformat.0.26.1 - opam install --deps-only -t -y . + opam install --deps-only -t -y . + opam install ocamlformat.0.26.1 - name: Test run: opam exec -- dune runtest From 589eea77509ffc0b426ebf6e5af44bef2cf743f5 Mon Sep 17 00:00:00 2001 From: maha-sachin Date: Thu, 28 Mar 2024 16:25:28 -0400 Subject: [PATCH 19/19] implemeted horizondal scroll area --- lib/interactive_viewer.ml | 15 ++- vendor/lwd/lib/nottui/nottui_widgets.ml | 114 +++++++++++++++++------ vendor/lwd/lib/nottui/nottui_widgets.mli | 9 +- 3 files changed, 107 insertions(+), 31 deletions(-) diff --git a/lib/interactive_viewer.ml b/lib/interactive_viewer.ml index 1c58750..b33f1e2 100644 --- a/lib/interactive_viewer.ml +++ b/lib/interactive_viewer.ml @@ -110,12 +110,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_1 = 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 + let y_off_screen = state.W.position > state.W.bound in + if y_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_1 _action state = + let x_off_screen = state.W.position > state.W.bound in + if x_off_screen then + Lwd.set curr_scroll_state_1 { state with position = state.W.bound } + else Lwd.set curr_scroll_state_1 state + in W.vbox [ operation_info z_patches; @@ -125,6 +132,10 @@ let view (patches : Patch.t list) = ~state:(Lwd.get curr_scroll_state) ~change:change_scroll_state @@ current_hunks z_patches; + W.hscroll_area + ~state:(Lwd.get curr_scroll_state_1) + ~change:change_scroll_state_1 + @@ current_hunks z_patches; Lwd.pure @@ Ui.keyboard_area (function diff --git a/vendor/lwd/lib/nottui/nottui_widgets.ml b/vendor/lwd/lib/nottui/nottui_widgets.ml index c67e9c1..ad29c07 100644 --- a/vendor/lwd/lib/nottui/nottui_widgets.ml +++ b/vendor/lwd/lib/nottui/nottui_widgets.ml @@ -141,6 +141,16 @@ let menu_overlay wm g ?(dx=0) ?(dy=0) body around = let scroll_step = 1 +(* type scroll_state = { + y_position: int; + x_position: int; + y_bound : int; + x_bound : int; + y_visible : int; + x_visible : int; + y_total : int; + x_total : int; +} *) type scroll_state = { position: int; bound : int; @@ -148,50 +158,100 @@ type scroll_state = { total : int; } -let default_scroll_state = { position = 0; bound = 0; visible = 0; total = 0 } + +(* let default_scroll_state = { y_position = 0; y_bound = 0; y_visible = 0; y_total = 0; x_position = 0; x_bound = 0; x_visible = 0; x_total = 0; } *) +let default_scroll_state = { position = 0; bound = 0; visible = 0; total = 0; } let vscroll_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 + let y_visible = ref (-1) in + let y_total = ref (-1) in + let scroll state delta del = + let y_position = state.position + delta in + let position = clampi y_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 (-scroll_step) 0*) - (*| `Arrow `Right, _ -> scroll (+scroll_step) 0*) - | `Arrow `Up , [] -> scroll state (-scroll_step) - | `Arrow `Down , [] -> scroll state (+scroll_step) - | `Page `Up, [] -> scroll state ((-scroll_step) * 8) - | `Page `Down, [] -> scroll state ((+scroll_step) * 8) + | `Arrow `Left , [] -> scroll state (0) (-scroll_step) + | `Arrow `Right, [] -> scroll state (0) (+scroll_step) + | `Arrow `Up , [] -> scroll state (-scroll_step) (0) + | `Arrow `Down , [] -> scroll state (+scroll_step) (0) + | `Page `Up, [] -> scroll state ((-scroll_step) * 8) (0) + | `Page `Down, [] -> scroll state ((+scroll_step) * 8) (0) | _ -> `Unhandled in let scroll_handler state ~x:_ ~y:_ = function - | `Scroll `Up -> scroll state (-scroll_step) - | `Scroll `Down -> scroll state (+scroll_step) + | `Scroll `Up -> scroll state (-scroll_step) (0) + | `Scroll `Down -> scroll state (+scroll_step) (0) + | _ -> `Unhandled in Lwd.map2 t state ~f:begin fun t state -> t |> Ui.shift_area 0 state.position |> Ui.resize ~h:0 ~sh:1 - |> Ui.size_sensor (fun ~w:_ ~h -> - let tchange = - if !total <> (Ui.layout_spec t).Ui.h - then (total := (Ui.layout_spec t).Ui.h; true) + |> Ui.size_sensor (fun ~w ~h -> + let tychange = + if !y_total <> (Ui.layout_spec t).Ui.h + then (y_total := (Ui.layout_spec t).Ui.h; true) + else false + in + let vychange = + if !y_visible <> h + then (y_visible := h; true) + else false + in + if tychange || vychange then + change `Content {state with visible = !y_visible; total = !y_total; + bound = maxi 0 (!y_total - !y_visible);} + ) + |> Ui.mouse_area (scroll_handler state) + |> Ui.keyboard_area (focus_handler state) + end +let hscroll_area ~state ~change t = + let x_visible = ref (-1) in + let x_total = ref (-1) in + let scroll state delta del = + let x_position = state.position + del in + let position = clampi x_position ~min:0 ~max:state.bound in + if x_position <> state.position then + change `Action {state with position}; + `Handled + in + let focus_handler state = function + | `Arrow `Left , [] -> scroll state (0) (-scroll_step) + | `Arrow `Right, [] -> scroll state (0) (+scroll_step) + | `Arrow `Up , [] -> scroll state (-scroll_step) (0) + | `Arrow `Down , [] -> scroll state (+scroll_step) (0) + | `Page `Up, [] -> scroll state ((-scroll_step) * 8) (0) + | `Page `Down, [] -> scroll state ((+scroll_step) * 8) (0) + | _ -> `Unhandled + in + let scroll_handler state ~x:_ ~y:_ = function + | `Scroll `Up -> scroll state (-scroll_step) (0) + | `Scroll `Down -> scroll state (+scroll_step) (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 txchange = + if !x_total <> (Ui.layout_spec t).Ui.w + then (x_total := (Ui.layout_spec t).Ui.w; true) else false in - let vchange = - if !visible <> h - then (visible := h; true) + let vxchange = + if !x_visible <> w + then (x_visible := w; true) else false in - if tchange || vchange then - change `Content {state with visible = !visible; total = !total; - bound = maxi 0 (!total - !visible); } + if txchange || vxchange then + change `Content {state with visible = !x_visible; total = !x_total; + bound = maxi 0 (!x_total - !x_visible); } ) |> Ui.mouse_area (scroll_handler state) |> Ui.keyboard_area (focus_handler state) diff --git a/vendor/lwd/lib/nottui/nottui_widgets.mli b/vendor/lwd/lib/nottui/nottui_widgets.mli index 071a764..8165a89 100644 --- a/vendor/lwd/lib/nottui/nottui_widgets.mli +++ b/vendor/lwd/lib/nottui/nottui_widgets.mli @@ -31,14 +31,19 @@ val sub_entry : string -> (unit -> unit) -> ui (* FIXME Explain how scrolling works *) val scroll_step : int -type scroll_state = { position : int; bound : int; visible : int; total : int } +type scroll_state = { position : int; bound : int; visible : int; total : int; } val default_scroll_state : scroll_state val vscroll_area : state:scroll_state Lwd.t -> change:([> `Action | `Content ] -> scroll_state -> unit) -> ui Lwd.t -> ui Lwd.t -val scroll_area : +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 val scrollbox: ui Lwd.t -> ui Lwd.t