GoVCL (Go Language Visual Component Library)

repository·master·Indexed 25 days ago

https://github.com/ying32/govcl

A cross-platform native GUI library for Go built upon the liblcl core. It enables the creation of desktop applications using a component-based model similar to Lazarus/FreePascal. GoVCL supports Windows, Linux, and macOS, providing tools for automatic macOS .app packaging, Windows resource compilation via windres, and UI synchronization using vcl.ThreadSync for non-thread-safe components.

Tokens
6.9K
Snippets
15
Records
36
Agent score
81%

What's inside GoVCL

  1. GoVCL Project Overview

    master

    GoVCL is a Go wrapper for the LCL (LCL Library) to provide GUI capabilities. The project is organized into several functional modules:

    • api: Provides the function imports for the underlying lcl library.
    • i18n: Manages multi-language settings for applications.
    • rtl: Contains non-component classes and runtime library logic.
    • types: Contains all type definitions used across the library.
    • win: Provides Windows-specific interfaces, constants, and WinAPI bindings.
    • bitmap: Provides utilities to convert Go's native image.Image objects into LCL image objects.
  2. Thread safety in GoVCL

    master
    All UI components in GoVCL are non-threaded/non-coroutine safe. You must not update UI components directly from a goroutine. To safely update the UI from a background goroutine, use vcl.ThreadSync to synchronize the update with the main UI thread.
  3. Use localized dialog button text in GoVCL

    master

    GoVCL provides a package for default dialog button text. Because the primary development tools are in English, the default text is English. This package allows you to handle localization for dialog buttons.

    Important Note: If your project is already using the i18n package, do not use the packages found in this directory to avoid conflicts.

  4. Thread safety and UI synchronization

    master

    ⚠️ Critical: UI Thread Safety

    All UI components in GoVCL are NOT thread-safe.

    If you need to update a UI component from within a goroutine, you must use vcl.ThreadSync to synchronize the update back to the main UI thread. Failure to do so will result in undefined behavior or crashes.

  5. Understand string encoding in the win package

    master
    The win package uses UNICODE as the standard for all WinAPI calls. When interacting with Windows APIs that expect Unicode strings, you must ensure your Go strings (which are UTF-8) are converted to the appropriate format. The package provides internal conversion functions to handle these transitions between Go's UTF-8 strings and the Unicode/ANSI formats required by the Windows API.
  6. Configure UAC privileges in the .manifest file

    master

    The .manifest file controls the User Account Control (UAC) behavior of your application. To change the privilege level, modify the level attribute within the requestedExecutionLevel tag.

    • Use level="asInvoker" for standard privileges.
    • Use level="requireAdministrator" to request administrator privileges.
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
        <requestedPrivileges>
          <requestedExecutionLevel
            level="asInvoker"
            uiAccess="false"
          />
        </requestedPrivileges>
      </security>
    </trustInfo>
  7. Explore GoVCL sample projects

    master

    The samples directory contains various demonstration projects showcasing GoVCL's capabilities. Note that while many basic components are cross-platform, not all sample projects are. Projects are categorized by their platform support (All, macOS, or Windows).

    Key Capabilities Demonstrated:

    • Basic UI: Windows, layouts, menus, status bars, and standard controls.
    • Advanced Controls: TreeViews, ListViews (including virtual data for large datasets), StringGrids, and CheckListBox.
    • Graphics & Drawing: Canvas self-drawing, integration with Charts for Go, Go Image Filtering Toolkit (gift), and Go Graphics - 2D (gg).
    • Web & Browser: Cross-platform miniwebview, and Windows-specific miniblinkWebview or wkeWebBrowser.
    • System Integration: File drag-and-drop, INI configuration, JSON parsing, multi-language support, and system dialogs.
    • Specialized Tools: Markdown editor, Redis viewer, audio player (via bass.dll), and reverse proxy.
  8. Deploy and link binary libraries

    master

    GoVCL requires specific platform-dependent binary libraries (liblcl) to be present in the same directory as your executable or in the system library path.

    PlatformLibrary FileGo Environment Requirements
    Windowsliblcl.dllGOARCH (amd64 or 386), GOOS=windows, CGO_ENABLED=0
    Linuxliblcl.soGOARCH=amd64, GOOS=linux, CGO_ENABLED=1
    macOSliblcl.dylibGOARCH=amd64, GOOS=darwin, CGO_ENABLED=1

    Notes:

    • For Linux, you can place liblcl.so in /usr/lib/ (32-bit) or /usr/lib/x86_64-linux-gnu/ (64-bit) to use it as a global library.
    • For macOS, you must manually create an info.plist file for your application bundle.
  9. Install GoVCL

    master

    To add GoVCL to your project, use the go get command. You can also use Go module mode by adding the dependency to your go.mod file.

    Using go get:

    go get -u github.com/ying32/govcl

    Using go module mode: Add the following to your go.mod: github.com/ying32/govcl v2.2.3+incompatible

    go get -u github.com/ying32/govcl