moonbit-libyue

    libyue 的 MoonBit 封装:统一跨平台 GUI 库,👏Windows - win 32、👏Linux - GTK、‼️Mac - Cocoa

    gui
    desktop
    native
    cross-platform
    libyue
    跨平台
    原生 GUI
    Linux
    Windows
    Mac
    Download zip
    Author
    Version
    0.2.0
    License
    MIT
    Last updated
    1 hour ago
    Downloads
    7

    #moonbit-libyue

    CI

    MoonBit bindings for libyue — build native cross-platform desktop apps (Windows / macOS / Linux) in pure MoonBit.

    #Platform support

    English | 简体中文

    #Yue

    A library for creating native cross-platform GUI apps.

    #Three ways to build UI

    #StackTypical codeFor
    1Themed component library + declarative + reactivebutton_t / side_menu / tag / alert … nodes bound to StoreModern app shells — recommended
    2Native libyue widgets + declarative + reactivebutton / entry / slider … nodes + Store bindingsNative look with declarative code
    3Native libyue widgets + imperativeWindow::new + set_content + settersClose to the raw libyue API

    The themed layer keeps native rendering while providing a modern Element-Plus-style look, declarative node trees and reactive data binding — native, and pleasant to use.

    #Demos

    #Modern — themed component library

    moon run examples/components — a four-page demo board covering the full themed library, every component and state; API reference in docs/components-ui.md:

    Basic

    Navigation

    Data display

    Feedback

    #Classic — native widgets

    moon run examples/showcase — a 12-page demo covering the full native widget set (widgets / inputs / canvas / browser / table / dialogs / menus / tray / clipboard / events …):

    Showcase widgets page

    More examples in examples/.

    #Usage

    #Quick start

    #Ubuntu 24.04

    System dependencies:

    sudo apt install build-essential cmake pkg-config \ libgtk-3-dev libpango1.0-dev libfontconfig1-dev libx11-dev \ libwebkit2gtk-4.1-dev

    Build the native library and run an example: Note: the first build downloads libyue from GitHub.

    moon run examples/hello

    #Windows (10/11, x64)

    Requires Python 3, MoonBit, CMake, the MSVC C++ toolchain (with ATL), etc.

    1. Install the MoonBit toolchain:

    irm https://cli.moonbitlang.com/install/powershell.ps1 | iex

    1. Install CMake and the MSVC C++ toolchain:

    winget install Kitware.CMake winget install Microsoft.VisualStudio.2022.BuildTools -e --override "--quiet --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

    1. Add the ATL component:

    Start-Process -FilePath 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe' -ArgumentList 'modify','--installPath','"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"','--add','Microsoft.VisualStudio.Component.VC.ATL','--quiet','--norestart' -Verb RunAs -Wait

    1. Build and run. On Windows moon looks for cl on PATH when compiling native code, so run it from the "x64 Native Tools Command Prompt for VS 2022", or call vcvars64.bat first:

    call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" python3 scripts\prepare.py moon run examples/hello

    #Use as a dependency

    moon add NoahLiu/moonbit-libyue moon run src

    #Declarative UI

    Windows can be described as declarative node trees (@yue.mount_window) instead of imperative new + set_content calls.

    1. Hello window — nodes for a label and a button, mounted straight into a window:

    fn main {
    if !@yue.initialize() {
    return
    }
    let window = @yue.mount_window(
    [
    @yue.label("Hello, MoonBit + libyue!", style=[("margin", 20.0)]),
    @yue.button("Quit", on_click=fn() { @yue.quit() }),
    ],
    title="Hello",
    size=Some((420.0, 160.0)),
    center=true,
    on_close=fn(_w) { @yue.quit() },
    )
    window.activate()
    @yue.run()
    }

    Hello window

    2. Reactive counter — a Store holds the state; bind_label re-renders the label on every update. No manual "set text after click" wiring:

    let clicks : @yue.Store[Int] = @yue.Store::new(0)
    let window = @yue.mount_window(
    [
    @yue.vbox(
    [
    @yue.button("Click me", on_click=fn() { clicks.update(fn(n) { n + 1 }) }),
    @yue.bind_label(clicks, fn(n) { "Clicked \{n} times" }),
    ],
    style=[("padding", 24.0)],
    ),
    ],
    title="Counter",
    size=Some((320.0, 160.0)),
    center=true,
    on_close=fn(_w) { @yue.quit() },
    )

    Counter window

    More node types are covered in docs/declarative.md.

    #Documentation

    DocumentContent
    components-ui.mdThemed component library API with demo screenshots
    declarative.mdDeclarative Node/mount trees + Store reactive bindings
    components.mdWidget API quick reference: classic setters and X::make props styles
    layout.mdLayout style keys (Yoga flexbox)
    adaptation.mdPlatform pitfalls, root causes and verification conclusions
    tray.mdLinux tray: SNI protocol stack design and backend fallback
    relink.mdForcing a relink after native-layer changes

    Full index: docs/README.md.

    #Development

    • Build & test: moon check && moon test
    • Adding a widget: mechanical translation in shim/yue_mbt.cpp → declaration in shim/include/yue_mbt.hextern "c" in yue/ffi.mbt → type & methods in a new yue/*.mbt (FFI conventions in .agents/skills/moonbit-c-binding/).
    • Current binding surface: ~320 ABI functions (324 extern "c" declarations in yue/ffi.mbt).
    • Real-world pitfalls and platform lessons go to docs/adaptation.md; usage docs and code comments stay content-only.
    • After shim/vendor changes, force a relink: moon clean or delete the executable — see docs/relink.md.

    #References