package miaou-core
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Miaou core/widgets (no drivers, no SDL)
Install
dune-project
Dependency
Authors
Maintainers
Sources
v0.5.2.tar.gz
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/src/miaou_widgets_layout/progress_widget_sdl.ml.html
Source file progress_widget_sdl.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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127(*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) (* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com> *) (* Copyright (c) 2026 Mathias Bourgoin <mathias.bourgoin@atacama.tech> *) (* *) (*****************************************************************************) (* SDL-specific rendering for the progress bar: smooth turquoise gradient with a bright leading edge. *) module W = Miaou_widgets_display.Widgets module Palette = Miaou_widgets_display.Palette (* Smooth turquoise gradient using continuous RGB blended and mapped to 38;5. *) let rgb_of_code code = if code < 16 then let ansi_palette = [| (0, 0, 0); (128, 0, 0); (0, 128, 0); (128, 128, 0); (0, 0, 128); (128, 0, 128); (0, 128, 128); (192, 192, 192); (128, 128, 128); (255, 0, 0); (0, 255, 0); (255, 255, 0); (0, 0, 255); (255, 0, 255); (0, 255, 255); (255, 255, 255); |] in ansi_palette.(code) else if code >= 16 && code < 232 then let idx = code - 16 in let r = idx / 36 in let g = idx / 6 mod 6 in let b = idx mod 6 in let to_int c = if c = 0 then 0 else 55 + (c * 40) in (to_int r, to_int g, to_int b) else let level = 8 + ((code - 232) * 10) in (level, level, level) let nearest_code r g b = let best = ref 0 in let best_d = ref max_int in for code = 0 to 255 do let cr, cg, cb = rgb_of_code code in let dr = cr - r in let dg = cg - g in let db = cb - b in let d = (dr * dr) + (dg * dg) + (db * db) in if d < !best_d then ( best := code ; best_d := d) done ; !best let lerp a b t = int_of_float (float a +. (float (b - a) *. t)) let color_rgb i total = let t = if total <= 1 then 0. else float_of_int i /. float_of_int (total - 1) in let start = (20, 170, 180) in let finish = (110, 255, 235) in let r0, g0, b0 = start in let r1, g1, b1 = finish in (lerp r0 r1 t, lerp g0 g1 t, lerp b0 b1 t) let render_bar ~inner_w ~progress = let buf = Buffer.create (inner_w * 4) in let exact = progress *. float_of_int inner_w in for i = 0 to inner_w - 1 do let cr, cg, cb = color_rgb i inner_w in let base_r, base_g, base_b = (10, 20, 24) in let x = float i +. 0.5 in let p = exact in let strength = if p <= x -. 0.5 then 0.12 else if p >= x +. 0.5 then 1.0 else let t = (p -. (x -. 0.5)) /. 1.0 in 0.12 +. (0.88 *. t) in let mix c_active c_base = int_of_float ((float c_active *. strength) +. (float c_base *. (1. -. strength))) in let r' = mix cr base_r in let g' = mix cg base_g in let b' = mix cb base_b in let code = nearest_code r' g' b' in let ansi = if strength > 0.15 then W.bg code " " else W.bg (nearest_code base_r base_g base_b) " " in Buffer.add_string buf ansi done ; Buffer.contents buf let render ~width ~progress ~label ~title ~cols:_ = let bar_w = max 6 (width - 2) in let pct = int_of_float (floor ((100. *. progress) +. 0.5)) in let bar = render_bar ~inner_w:bar_w ~progress in let pct_s = Palette.fg_secondary (Printf.sprintf "%3d%%" pct) in let line = bar ^ " " ^ pct_s in let two_lines a b = let buf = Buffer.create (String.length a + String.length b + 1) in Buffer.add_string buf a ; Buffer.add_char buf '\n' ; Buffer.add_string buf b ; Buffer.contents buf in match (label, title) with | Some lbl, _ -> Palette.fg_steel lbl ^ " " ^ line | None, Some t -> two_lines (W.titleize t) line | None, None -> line [@@@enforce_exempt] (* non-widget module *)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>