ImGui

master

Swift wrapper around Dear imgui for macOS, iOS, Linux and Windows
forkercat/SwiftImGui

Swift ImGui

macOS Linux Windows platform-compatibility
swift-version-compatibility license

swiftimgui-gif

This is a lightweight, auto-generated and thin Swift wrapper around the popular and excellent dear imgui library.
It provides a swifty and -especially - typesafe API. It is easily maintainable and updatable, as well, since it relies heavily on automated code generation.

There are working demo examples, too, provided as part of the library.

🚀 Getting Started

These instructions will get your copy of the project up and running on your local machine and provide a code example.

📋 Prerequisites

💻 Installing

Swift ImGui is available for all platforms that support Swift 5.3 and higher and the Swift Package Manager (SPM).

Extend the following lines in your Package.swift file or use it to create a new project.

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "YourPackageName",
    dependencies: [
        .package(url: "https://github.com/ctreffs/SwiftImGui.git", from: "1.82.0")
    ],
    targets: [
        .target(
            name: "YourTargetName",
            dependencies: ["ImGui"])
    ]
)

📝 Code Example

A minimal example is located at Sources/Demos/Minimal/main.swift.
This is an excerpt:

import ImGui

IMGUI_CHECKVERSION()
let ctx = ImGuiCreateContext(nil)
let io = ImGuiGetIO()!

/// Build font atlas
var pixels: UnsafeMutablePointer<UInt8>?
var width: Int32 = 0
var height: Int32 = 0
var bytesPerPixel: Int32 = 0
ImFontAtlas_GetTexDataAsRGBA32(io.pointee.Fonts, &pixels, &width, &height, &bytesPerPixel)

for n in 0..<20 {
    io.pointee.DisplaySize = ImVec2(x: 1920, y: 1080)
    io.pointee.DeltaTime = 1.0 / 60.0
    ImGuiNewFrame()
    var f: Float = 0.0
    ImGuiTextV("Hello, world!")
    ImGuiSliderFloat("float", &f, 0.0, 1.0, nil, 1)
    ImGuiTextV("Application average %.3f ms/frame (%.1f FPS)", 1000.0 / io.pointee.Framerate, io.pointee.Framerate)
    ImGuiShowDemoWindow(nil)
    ImGuiRender()
}

ImGuiDestroyContext(ctx)

🆕 Update SwiftImGui

SwiftImGui uses a mutli-stage process to update to the latest imgui version. See HOWTO.md for details.

💁 Help needed

This project needs a lot of love. If you are interested in contributing please feel free to do so!

Things that need to be done among others are:

  • Extend the AutoWrapper to wrap more cimgui functions (currently there are 105 'invalid' functions that will not be wrapped. 927 will be wrapped properly.)
  • Some functions are not available via the c interface - see Sources/AutoWrapper/Exceptions.swift
  • Find a solution for manual adjustments in cimgui generator template
  • Write some more tests

🏷️ Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

✍️ Authors

See also the list of contributors who participated in this project.

🔏 Licenses

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Original code

Since SwiftImGui is merely a wrapper around imgui it obviously depends on it.
It also makes use of the excellent c-api wrapper cimgui.
Support them if you can!

imgui

(This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.)

Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  E-mail: contact @ dearimgui dot org

Individuals/hobbyists: support continued maintenance and development via the monthly Patreon:
  Patreon

Individuals/hobbyists: support continued maintenance and development via PayPal:
  PayPal


Dear ImGui is a bloat-free graphical user interface library for C++. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies).

Dear ImGui is designed to enable fast iterations and to empower programmers to create content creation tools and visualization / debug tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and lacks certain features normally found in more high-level libraries.

Dear ImGui is particularly suited to integration in games engine (for tooling), real-time 3D applications, fullscreen applications, embedded applications, or any applications on consoles platforms where operating system features are non-standard.

cimgui

CImGui is a thin c-api wrapper programmatically generated for the excellent C++ immediate mode gui Dear ImGui. All imgui.h functions are programmatically wrapped. Generated files are: cimgui.cpp, cimgui.h for C compilation. Also for helping in bindings creation, definitions.lua with function definition information and structs_and_enums.lua. This library is intended as a intermediate layer to be able to use Dear ImGui from other languages that can interface with C (like D - see D-binding)

☮️ Alternatives

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Mar 28 2024 09:40:49 GMT-0900 (Hawaii-Aleutian Daylight Time)