Skip to main content

A lightweight, cross-platform C GUI framework with Python bindings

Project description

Baba

A lightweight, cross-platform C GUI framework using Vulkan for rendering.

Features

  • Minimal Dependencies: Only requires Vulkan SDK
  • Cross-Platform: macOS, Linux (X11/Wayland), Windows
  • Native Window: Uses platform-native APIs
  • Vulkan Rendering: Modern GPU-accelerated rendering
  • Complete Widgets: Buttons, Labels, TextBoxes, etc.
  • Flexible Layout: Flexbox-like and Grid layouts
  • Python Bindings: pip install baba-gui

Documentation

中文文档

Installation

Python (Recommended)

pip install baba-gui

From Source

Prerequisites:

  • CMake 3.20+
  • C11 compiler
  • Vulkan SDK

Build Steps:

mkdir build && cd build
cmake ..
make

Platform-Specific:

macOS:

brew install vulkan-loader vulkan-headers molten-vk
cmake -DCMAKE_PREFIX_PATH=$(brew --prefix) ..
make

Linux:

# Ubuntu/Debian
sudo apt install libvulkan-dev xorg-dev wayland-protocols

# Arch
sudo pacman -S vulkan-headers vulkan-tools libx11 libwayland

cmake ..
make

Windows:

Recommended: MinGW-w64 via MSYS2:

# Install dependencies via winget
winget install MSYS2.MSYS2
winget install KhronosGroup.VulkanSDK

# Open MSYS2 MINGW64 terminal:
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja

# Build
cmake -B build -G Ninja
cmake --build build

If you must use Visual Studio:

cmake -B build -G "Visual Studio 17 2022"
cmake --build build --config Release

Quick Start

Python

import baba

def on_click(button):
    print("Button clicked!")

with baba.create_app() as app:
    window = app.create_window("Baba Demo", 800, 600)
    
    button = baba.Button("Click Me")
    button.on_click(on_click)
    window.root.add_child(button)
    
    label = baba.Label("Hello, Baba GUI!")
    label.font_size = 24.0
    label.color = baba.Color.from_hex("#333333")
    window.root.add_child(label)
    
    window.show()
    app.run()

C

#include <baba.h>
#include <widgets/button.h>
#include <widgets/label.h>

void on_click(BabaWidget* button, void* data) {
    printf("Button clicked!\n");
}

int main() {
    BabaApp* app = baba_app_create();
    BabaWindow* win = baba_window_create(app, "Baba Demo", 800, 600);
    
    BabaWidget* root = baba_window_get_root(win);
    BabaWidget* button = baba_button_create("Click Me");
    baba_button_set_on_click(button, on_click, NULL);
    baba_widget_add_child(root, button);
    
    baba_window_show(win);
    baba_app_run(app);
    
    baba_window_destroy(win);
    baba_app_destroy(app);
    return 0;
}

Architecture

Baba/
├── src/
│   ├── baba.h              # Main public API
│   ├── core/               # Core utilities
│   ├── platform/           # Platform abstraction (macOS/Linux/Windows)
│   ├── render/             # Vulkan renderer + Painter API
│   ├── widgets/            # UI widgets (Button, Label, TextBox)
│   ├── layout/             # Flex/Grid layouts
│   └── theme/              # Theming system
├── python/                 # Python bindings (cffi)
├── examples/               # Example applications
└── docs/                   # Documentation

API Overview

Application

// C
BabaApp* app = baba_app_create();
int result = baba_app_run(app);
void baba_app_quit(BabaApp* app);
# Python
app = baba.App()
result = app.run()
app.quit()

Window

BabaWindow* win = baba_window_create(app, "Title", 800, 600);
baba_window_set_title(win, "New Title");
baba_window_show(win);
window = app.create_window("Title", 800, 600)
window.title = "New Title"
window.show()

Widgets

// Button
BabaWidget* btn = baba_button_create("Button");
baba_button_set_on_click(btn, callback, NULL);

// Label
BabaWidget* label = baba_label_create("Text");
baba_label_set_font_size(label, 16.0f);

// TextBox
BabaWidget* input = baba_textbox_create("Placeholder");
const char* text = baba_textbox_get_text(input);
# Button
btn = baba.Button("Button")
btn.on_click(lambda b: print("clicked"))

# Label
label = baba.Label("Text")
label.font_size = 16.0

# TextBox
input = baba.TextBox("Placeholder")
text = input.text

Layout

// Flex layout
BabaWidget* flex = baba_flex_layout_create(BABA_LAYOUT_DIRECTION_ROW);
baba_flex_layout_set_gap(flex, 10.0f);

// Grid layout
BabaWidget* grid = baba_grid_layout_create(3, 2);

Publishing to PyPI

Build Wheels

# Install build tools
pip install build cibuildwheel

# Build source distribution
python -m build --sdist

# Build wheels for all platforms
cibuildwheel --platform macos
cibuildwheel --platform linux
cibuildwheel --platform windows

Upload to PyPI

pip install twine
twine upload dist/*

GitHub Actions (CI/CD)

The project includes cibuildwheel configuration in pyproject.toml for automated wheel building:

# .github/workflows/publish.yml
name: Publish to PyPI
on:
  release:
    types: [published]
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, ubuntu-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
      - run: pip install cibuildwheel
      - run: cibuildwheel --output-dir dist
      - uses: actions/upload-artifact@v4
        with:
          name: wheels-${{ matrix.os }}
          path: dist
  publish:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
      - run: pip install twine
      - run: twine upload wheels-*/*
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

Dependencies

Platform Dependencies
Rendering Vulkan SDK
macOS Cocoa, Metal, QuartzCore
Linux X11 or Wayland
Windows Win32 API (user32, gdi32)
Python cffi >= 1.16.0

Platform Support

Platform Window System Status
macOS Cocoa + Metal ✅ Full Support
Linux X11 ✅ Full Support
Linux Wayland ✅ Full Support
Windows Win32 ✅ Full Support

C Development

After pip install baba-gui, you can use Baba for C GUI development:

# Get development paths
python -c "import baba; print(baba.get_include_dir())"  # Headers
python -c "import baba; print(baba.get_lib_path())"     # Library
# Compile your C app (macOS example)
INCLUDE=$(python -c "import baba; print(baba.get_include_dir())")
LIB=$(python -c "import baba; import os; print(os.path.dirname(baba.get_lib_path()))")

clang main.c -I"$INCLUDE" -L"$LIB" -lbaba \
    -framework Cocoa -framework Metal -lvulkan -o myapp

See C Development Guide for details.

Building & Publishing

Build Native Library (Current Platform)

# Unix (macOS/Linux)
./build_all.sh

# Windows (MSYS2 MinGW)
./build_all.sh

This builds the library for the current platform only.

Cross-Platform Builds

For production releases, use GitHub Actions to build on all platforms:

  1. Push to main branch or create a release
  2. GitHub Actions builds macOS, Linux, and Windows versions
  3. Artifacts are combined and published to PyPI

To trigger a PyPI release:

  1. Go to GitHub → Releases → Draft a new release
  2. Tag the release (e.g., v0.1.2)
  3. Publish - GitHub Actions will build and upload to PyPI

Manual Multi-Platform Build

If you need to build all platforms locally:

  1. macOS: Run on macOS machine
  2. Linux: Run on Linux machine or use Docker
  3. Windows: Run on Windows with MSYS2 MinGW

Then manually copy libraries to python/baba/lib/:

python/baba/lib/
├── libbaba_macos.a
├── libbaba_linux.a
└── libbaba_windows.a

Build & Upload to PyPI (Manual)

# Build native library
./build_all.sh

# Build Python package
pip install build twine
python -m build

# Upload to PyPI
twine upload dist/*

GitHub Actions (Recommended for Multi-Platform)

For production releases, use GitHub Actions to build on native platforms:

# .github/workflows/build.yml
jobs:
  build-macos:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./build_all.sh
      - uses: actions/upload-artifact@v4
        with:
          name: lib-macos
          path: dist/lib/macos/*.a

  build-linux:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./build_all.sh
      - uses: actions/upload-artifact@v4
        with:
          name: lib-linux
          path: dist/lib/linux-x64/*.a

  build-windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - run: build_all.bat
      - uses: actions/upload-artifact@v4
        with:
          name: lib-windows
          path: dist/lib/windows-x64/*.a

License

MIT License - see LICENSE file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

baba_gui-0.1.2.tar.gz (167.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

baba_gui-0.1.2-py3-none-any.whl (83.1 kB view details)

Uploaded Python 3

File details

Details for the file baba_gui-0.1.2.tar.gz.

File metadata

  • Download URL: baba_gui-0.1.2.tar.gz
  • Upload date:
  • Size: 167.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for baba_gui-0.1.2.tar.gz
Algorithm Hash digest
SHA256 53516308bd7977cca84253552ca85c1369653db3291a8051e0adcaa0bc338cee
MD5 1a2dbfff91a59f9edfba2e3e0d078ce0
BLAKE2b-256 311419c7d0a8f7b4dd41ef748fba324f5b08ff3995e32e5a951cb8a5a9b3f1ed

See more details on using hashes here.

File details

Details for the file baba_gui-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: baba_gui-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 83.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for baba_gui-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7de7c9bcddf39be4f5a97e2a54d985aca74b8b442e091bcec5ecd5549301b120
MD5 7c9feac67005e997df5117309eecc8bd
BLAKE2b-256 6ccc2e1dede9d7119ac56ab02624259e21e18d641427e7ac569eede9b284389b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page