package miaou-core

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file sidebar_widget.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com>                *)
(* Copyright (c) 2026 Mathias Bourgoin <mathias.bourgoin@atacama.tech>       *)
(*                                                                           *)
(*****************************************************************************)

[@@@warning "-32-34-37-69"]

type t = {
  sidebar : string;
  main : string;
  sidebar_open : bool;
  sidebar_width : int option;
}

let create ?sidebar_width ~sidebar ~main ~sidebar_open () =
  {sidebar; main; sidebar_open; sidebar_width}

let toggle t = {t with sidebar_open = not t.sidebar_open}

let with_main t main = {t with main}

let with_sidebar t sidebar = {t with sidebar}

let render t ~cols =
  let min_cols_for_split = 40 in
  if (not t.sidebar_open) || cols < min_cols_for_split then t.main
  else
    let left_width =
      match t.sidebar_width with
      | Some w -> max 10 (min w (cols / 2))
      | None -> max 16 (cols / 3)
    in
    Pane.split_vertical_with_left_width
      ~width:cols
      ~left_pad:1
      ~right_pad:1
      ~border:true
      ~wrap:false
      ~sep:""
      ~left:t.sidebar
      ~right:t.main
      ~left_width

[@@@enforce_exempt] (* non-widget module *)