wcl_wdoc 0.11.0-alpha

WCL documentation format — build structured docs with WCL, render to HTML
    export let terminal_menubar_item_shape = (b, item, i, row, col, item_col, item_cols, foreground_fill, background_fill, hover_foreground_fill, hover_background_fill, sibling_targets, default_close_targets) => {
        let target = item.target
        let item_id = to_string(b.id) + "_item_" + to_string(i)
        let item_class = item.disabled ? "wdoc-terminal-menu-item wdoc-terminal-menu-item-disabled" : "wdoc-terminal-menu-item"
        let close_targets = item.close_targets != "" ? wdoc::terminal_target_list(item.close_targets) : (len(default_close_targets) > 0 ? default_close_targets : sibling_targets)
        let hover_close_targets = filter(close_targets, close_target => trim(close_target) != target)
        let open_event = target != "" ? [{ trigger = "hover", target = target, state = "shown", mode = "add" }] : []
        let events = item.disabled ? [] : concat(concat([{ trigger = "hover", state = "hovered", mode = "while" }], wdoc::terminal_remove_events(hover_close_targets, "hover")), open_event)
        let label = substr(item.label, 0, item_cols - 2)
        let text = " " + label + " "
        {
            kind = "group",
            id = item_id,
            row = row,
            col = item_col,
            rows = 1,
            cols = item_cols,
            class = item_class,
            cursor = item.disabled ? "default" : "pointer",
            pointer_events = item.disabled ? "none" : "all",
            _wdoc_runtime = "true",
            _wdoc_terminal_grid_group = "true",
            events = events,
            children = [
                { kind = "terminal_surface", id = item_id + "_bg", row = row, col = item_col, cols = item_cols, background_fill = background_fill, _wdoc_runtime = "true" },
                { kind = "terminal_surface", id = item_id + "_hover_bg", row = row, col = item_col, cols = item_cols, background_fill = hover_background_fill, class = "wdoc-terminal-menu-item-bg", _wdoc_runtime = "true" },
                { kind = "terminal_text", id = item_id + "_label", row = row, col = item_col, cols = item_cols, content = text, foreground_fill = foreground_fill, _wdoc_runtime = "true", pointer_events = "none" },
                { kind = "terminal_text", id = item_id + "_label_hover", row = row, col = item_col, cols = item_cols, content = text, foreground_fill = hover_foreground_fill, class = "wdoc-terminal-menu-item-label-hover", _wdoc_runtime = "true", pointer_events = "none" }
            ]
        }
    }

    export let terminal_widget_menubar = b => {
        let row = attr_or(b, "row", 0)
        let col = attr_or(b, "col", 0)
        let item_blocks = children(b, "wdoc::draw::menu_item")
        let items = map(item_blocks, item => wdoc::terminal_menu_item_data(item))
        let item_widths = map(items, item => length(item.label) + 2)
        let natural_cols = sum(item_widths)
        let cols = attr_or(b, "cols", natural_cols)
        let foreground_fill = attr_or(b, "foreground_fill", attr_or(b, "fill", "#d7e0ff"))
        let background_fill = attr_or(b, "background_fill", "#08111f")
        let hover_foreground_fill = attr_or(b, "hover_foreground_fill", attr_or(b, "selected_foreground_fill", "#08111f"))
        let hover_background_fill = attr_or(b, "hover_background_fill", attr_or(b, "selected_background_fill", "#d7e0ff"))
        let default_close_targets = wdoc::terminal_target_list(attr_or(b, "close_targets", ""))
        let sibling_targets = filter(map(items, item => item.target), target => target != "")
        let base_class = attr_or(b, "class", "")
        let menu_class = trim(base_class + " wdoc-terminal-menu")
        let item_shapes = map(range(0, len(items)), i => {
            let item_col = col + sum(map(range(0, i), j => item_widths[j]))
            wdoc::terminal_menubar_item_shape(b, items[i], i, row, col, item_col, item_widths[i], foreground_fill, background_fill, hover_foreground_fill, hover_background_fill, sibling_targets, default_close_targets)
        })
        [
            {
                kind = "group",
                id = to_string(b.id),
                row = row,
                col = col,
                rows = 1,
                cols = cols,
                class = menu_class,
                _wdoc_runtime = "true",
                _wdoc_terminal_grid_group = "true",
                children = concat([
                    { kind = "terminal_surface", id = to_string(b.id) + "_surface", row = row, col = col, cols = cols, background_fill = background_fill, _wdoc_runtime = "true" }
                ], item_shapes)
            }
        ]
    }