moonbit-libyue

    libyue 的 MoonBit 封装:统一跨平台 GUI API,平台差异由库内部吸收,消费方无感

    gui
    desktop
    native
    cross-platform
    libyue
    Download zip
    Author
    Version
    0.4.0
    License
    MIT
    Last updated
    54 minutes ago
    Downloads
    19

    #moonbit-libyue

    CI

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

    English | 简体中文

    Component showcase

    #Highlights

    🎨 Modern theme — An Element-Plus-style themed component library (50+ widgets: buttons / forms / navigation / data display / feedback), fully self-drawn and visually consistent across all three platforms; reskin with one theme_apply call, light/dark follows the system:

    @yue.theme_apply({ ..@yue.default_theme(), primary: "#1E4FA3" })

    📝 Declarative — Describe the UI as a node tree; no new + set_content plumbing:

    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() },
    )

    ⚡ Reactive signals — State lives in Signal / Store; bound views refresh automatically, no "on click update that label" glue:

    let clicks = @yue.Signal::new(0)
    @yue.button("Click me", on_click=fn() { clicks.update(fn(n) { n + 1 }) }),
    @yue.bind(clicks, fn(n) { "Clicked \{n} times" }), // derived text, updates on click

    The three compose freely: the themed library is the recommended front door (unified look), while libyue native widgets and the imperative style remain fully available.

    #Quick start

    # Ubuntu 24.04: one-time system dependencies (GTK/WebKit dev packages) sudo apt install build-essential cmake pkg-config \ libgtk-3-dev libpango1.0-dev libfontconfig1-dev libx11-dev libwebkit2gtk-4.1-dev # As a dependency: prebuilt native libraries ship with the package — zero C++ compilation moon add NoahLiu/moonbit-libyue moon run src # Run the demo board git clone https://github.com/lb091188/moonbit-libyue && cd moonbit-libyue moon run examples/showcase

    Requires Python 3, MoonBit, CMake and the MSVC C++ toolchain (with ATL). moon locates cl via PATH when compiling native code, so run from "x64 Native Tools Command Prompt for VS 2022" or call vcvars64.bat first:

    irm https://cli.moonbitlang.com/install/powershell.ps1 | iex # MoonBit winget install Kitware.CMake winget install Microsoft.VisualStudio.2022.BuildTools -e --override "--quiet --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended" # 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

    Projects must target native: the moon new template defaults to preferred_target = "wasm" and fails with ffi_* is unbound; change preferred_target to "native" in moon.mod.

    #Three ways to build a UI

    LayerStyleBest for
    1Themed library + declarative + reactive: button_t / side_menu / tag … nodes + Store bindingsModern app shells, recommended
    2libyue native widgets + declarative + reactive: button / entry / slider … nodes + Store bindingsNative look with declarative code
    3libyue native widgets + imperative: Window::new + set_content + settersClosest to raw libyue

    #Demo

    moon run examples/hello # minimal native-widget window moon run examples/hello-themed # themed minimal example (theme_apply + button_t/input_t/label_t) moon run examples/showcase # full demo board: 15 pages, 3 collapsible side-menu groups

    The showcase covers Basic / Icons / Form / Navigation / Data / Feedback / Code & Docs / Events & Layout / Store comparison + Native widgets / Canvas & rich text + System / Window / Browser / Environment, with a collapsible grouped side menu and the package version pinned at the bottom (kept in sync with moon.mod). More screenshots in docs/components-ui.md.

    Navigation page

    Prebuilt binaries: push a bin-* tag and the Releases page carries executables for all three platforms (Linux needs the GTK3 runtime / Windows ships WebView2Loader.dll / macOS Apple Silicon).

    #Documentation

    DocContent
    components-ui.mdThemed component library API + theme customization
    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.

    #Platform support

    Ubuntu 24.04 (XFCE / GNOME / KDE) ✅ · Deepin 25 ✅ · Windows 10/11 ✅ · macOS builds on CI (no device)

    #Contributing

    • Build & test: moon check && moon test (gate: zero errors, zero warnings)
    • Adding a widget: mechanical translation in shim/yue_mbt.cpp → declaration in shim/include/yue_mbt.hextern in yue/ffi.mbt → type & methods in a new yue/*.mbt (FFI guide in .agents/skills/moonbit-c-binding/)
    • Real-machine findings go to docs/adaptation.md; push bin-* tags for binary releases, vendor-* tags for native-layer updates

    #Reference