package miaou-core
Source file link_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(*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) (* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (*****************************************************************************) type target = Internal of string | External of string type t = {label : string; target : target; on_navigate : target -> unit} let create ~label ~target ~ = {label; target; on_navigate} let render t ~focus = let open Miaou_widgets_display.Widgets in let base = t.label |> blue in if focus then bold base else base let handle_event ?(bubble_unhandled = false) t ~key = match key with | "Enter" | " " -> t.on_navigate t.target ; (t, `Handled) | key -> (* Mouse click triggers navigation *) if Miaou_helpers.Mouse.is_click key then ( t.on_navigate t.target ; (t, `Handled)) else (t, if bubble_unhandled then `Bubble else `Handled) let handle_key t ~key = let t, status = handle_event t ~key in (t, status = `Handled)