Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreffs committed May 7, 2020
2 parents f4fc09e + 9412a82 commit a7b7fad
Show file tree
Hide file tree
Showing 28 changed files with 10,345 additions and 11,872 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: swift:5.0
image: swift:5.1.3

#variables:
# GIT_SUBMODULE_STRATEGY: recursive
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Christian Treffs
Copyright (c) 2019-2020 Christian Treffs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ copyLibImGui:
cp $(imgui_src)/generator/output/cimgui.cpp $(c_imgui_src)

generateCInterface:
cd $(imgui_src)/generator && luajit ./generator.lua clang sdl glfw glut metal
cd $(imgui_src)/generator && luajit ./generator.lua gcc true sdl glfw glut metal

buildCImGui: updateCLibImGui generateCInterface copyLibImGui

Expand Down
21 changes: 5 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import PackageDescription
var package = Package(
name: "ImGui",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(name: "ImGui", targets: ["ImGui"]),
.library(name: "CImGui", targets: ["CImGui"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
.target(name: "ImGui", dependencies: ["CImGui"]),
.target(name: "CImGui", path: "Sources/CImGui", cxxSettings: [.define("CIMGUI_DEFINE_ENUMS_AND_STRUCTS")]),
Expand All @@ -21,16 +16,10 @@ var package = Package(
cxxLanguageStandard: .cxx11
)

package.products.append(.executable(name: "DemoMinimal", targets: ["DemoMinimal"]))
package.targets.append(.target(name: "DemoMinimal", dependencies: ["ImGui"], path: "Sources/Demos/Minimal"))

#if canImport(Metal) && os(macOS)
let metalDemo: (Product, Target) =
(.executable(name: "DemoMetal-macOS", targets: ["DemoMetal"]),
.target(name: "DemoMetal", dependencies: ["ImGui"], path: "Sources/Demos/Metal"))
package.products.append(metalDemo.0)
package.targets.append(metalDemo.1)
package.products.append(.executable(name: "DemoMetal-macOS", targets: ["DemoMetal"]))
package.targets.append(.target(name: "DemoMetal", dependencies: ["ImGui"], path: "Sources/Demos/Metal"))
#endif

let minimumDemo: (Product, Target) =
(.executable(name: "DemoMinimal", targets: ["DemoMinimal"]),
.target(name: "DemoMinimal", dependencies: ["ImGui"], path: "Sources/Demos/Minimal"))
package.products.append(minimumDemo.0)
package.targets.append(minimumDemo.1)
40 changes: 17 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Swift ImGui
[![Build Status](https://travis-ci.com/ctreffs/SwiftImGui.svg?branch=master)](https://travis-ci.com/ctreffs/SwiftImGui)
[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
[![swift version](https://img.shields.io/badge/swift-5.0+-brightgreen.svg)](https://swift.org/download)
[![swift version](https://img.shields.io/badge/swift-5.1+-brightgreen.svg)](https://swift.org/download)
[![platforms](https://img.shields.io/badge/platforms-%20macOS%20|%20iOS%20|%20tvOS-brightgreen.svg)](#)
[![platforms](https://img.shields.io/badge/platforms-linux-brightgreen.svg)](#)

<p align="center">
<img src="docs/swiftimgui.gif" height="300" alt="swiftimgui-gif"/>
<img src="docs/swiftimgui.gif" width="100%" alt="swiftimgui-gif"/>
</p>

This is a **lightweight**, **auto-generated** and **thin** Swift wrapper around the popular and excellent [**dear imgui**](https://github.com/ocornut/imgui) library.
Expand All @@ -26,19 +26,19 @@ These instructions will get your copy of the project up and running on your loca

### 💻 Installing

Swift ImGui is available for all platforms that support [Swift 5.0](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager).
Swift ImGui is available for all platforms that support [Swift 5.1](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager).

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

```swift
// swift-tools-version:5.0
// swift-tools-version:5.1

import PackageDescription

let package = Package(
name: "YourPackageName",
dependencies: [
.package(url: "https://github.com/ctreffs/SwiftImGui.git", from: "1.1.1")
.package(url: "https://github.com/ctreffs/SwiftImGui.git", from: "1.2.0")
],
targets: [
.target(
Expand Down Expand Up @@ -73,8 +73,10 @@ 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)
ImGuiSliderFloat("float", &f, 0.0, 1.0, "", 1)
ImGuiTextV("Application average %.3f ms/frame (%.1f FPS)", 1000.0 / io.pointee.Framerate, io.pointee.Framerate)
ImGuiShowDemoWindow(nil)
ImGuiRender()
}
Expand All @@ -84,37 +86,29 @@ ImGuiDestroyContext(ctx)

## 🆕 Update SwiftImGui

SwiftImGui uses a multi-stage process to update to the latest imgui version.
All necessary steps are provided in an automated fashion via a [`Makefile`](Makefile).
Run the following commands in the repository's root directory:

1. `make buildCImGui` - Update cimgui submodule && generate C interface
2. `make wrapLibImGui` - Update SwiftImGui && auto-wrap C interface

SwiftImGui uses a mutli-stage process to update to the latest imgui version. See [HOWTO.md](docs/HOWTO.md) for details.

## 💁 Help needed

This project is in an early stage and needs a lot of love.
If you are interested in contributing, please feel free to do so!
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 are, among others:
Things that need to be done among others are:

- [ ] Extend the AutoWrapper to wrap more cimgui functions (currently there are 55 'invalid' functions that will not be wrapped; 543 will be wrapped properly)
- [ ] Extend the AutoWrapper to wrap more cimgui functions (currently there are 81 'invalid' functions that will not be wrapped. 799 will be wrapped properly.)
- [ ] Some vector functions are not available via the c interface - see `Sources/AutoWrapper/Exceptions.swift`
- [ ] Find a way to automate the remaining necessary manual adjustments in the cimgui generator template
- [ ] Support for [Cocoapods](https://cocoapods.org) packaging
- [ ] Support for [Carthage](https://github.com/Carthage/Carthage) packaging
- [ ] Write some additional tests to improve coverage
- [ ] Find a solution for manual adjustments in cimgui generator template
- [ ] Write some more tests

## 🏷️ Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](/releases).
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [releases on this repository](https://github.com/ctreffs/SwiftImGui/releases).

## ✍️ Authors

* [Christian Treffs](https://github.com/ctreffs)

See also the list of [contributors](https://github.com/ctreffs/SwiftImGui/contributors) who participated in this project.
See also the list of [contributors](https://github.com/ctreffs/SwiftImGui/graphs/contributors) who participated in this project.

## 🔏 Licenses

Expand Down
7 changes: 5 additions & 2 deletions Sources/AutoWrapper/DataType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ public struct DataType: Decodable {
// const char* -> String
return toWrap

case .pointer where isConst == false && type == .char:
// char* -> String
case .pointer where isConst == false && type == .char && context != .ret:
// char* -> inout String
return "inout \(toWrap)"
case .pointer where isConst == false && type == .char && context == .ret:
// char* -> String
return "\(toWrap)"
case .pointer where isConst == true && type == .void:
return "UnsafeRawPointer!"
case .pointer where isConst == false && type == .void:
Expand Down
20 changes: 9 additions & 11 deletions Sources/AutoWrapper/Definitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,26 @@ public struct FunctionDef: Decodable {
}

public var encodedFuncname: String {
guard let range = ov_cimguiname.range(of: funcname) else {
guard let range = ov_cimguiname.range(of: funcname), !range.isEmpty else {
assertionFailure("Original name should contain funcname")
return funcname
}

let name: String = funcname.components(separatedBy: "_")
.map {
// uppercase first character
$0.replacingCharacters(in: $0.startIndex..<$0.index(after: $0.startIndex), with: $0.prefix(1).uppercased())
}
.joined()

let prefix: String
let suffix = String(ov_cimguiname[range.upperBound..<ov_cimguiname.endIndex])
let name: String = funcname

var prefix: String
if let namespace = self.namespace, !namespace.isEmpty {
prefix = namespace
} else {
prefix = String(ov_cimguiname[ov_cimguiname.startIndex..<range.lowerBound])
}

let combinedName = prefix + name + suffix
if Exceptions.stripPrefix.contains(prefix) {
prefix = ""
}

//let suffix = String(ov_cimguiname[range.upperBound..<ov_cimguiname.endIndex])
let combinedName = prefix + name
return combinedName.replacingOccurrences(of: "_", with: "")
}

Expand Down
25 changes: 20 additions & 5 deletions Sources/AutoWrapper/Exceptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,37 @@ public enum Exceptions {
///
/// causes "Use of unresolved identifier '...'" compiler error.
public static let unresolvedIdentifier: Set<String> = [
"ImChunkStream_clear",
"ImChunkStream_empty",
"ImChunkStream_size",
"ImPool_Clear",
"ImPool_GetSize",
"ImPool_RemovePoolIdx",
"ImPool_Reserve",
"ImVector__grow_capacity",
"ImVector_capacity",
"ImVector_clear",
"ImVector_empty",
"ImVector__grow_capacity",
"ImVector_pop_back",
"ImVector_reserve",
"ImVector_resize",
"ImVector_resizeNil",
"ImVector_shrink",
"ImVector_size",
"ImVector_size_in_bytes",
"ImVector_swap"
"ImVector_swap",
"igImFontAtlasBuildMultiplyRectAlpha8",
"igImFontAtlasBuildMultiplyCalcLookupTable",
"igImTriangleBarycentricCoords"
]

/// causes "Use of undeclared type '...'" compiler error.
public static let undeclardTypes: [String: Declaration] = [
"ImGuiContext": Declaration(name: "ImGuiContext", typealiasType: "OpaquePointer"),
"ImDrawListSharedData": Declaration(name: "ImDrawListSharedData", typealiasType: "OpaquePointer")
"ImChunkStream": Declaration(name: "ImChunkStream", typealiasType: "OpaquePointer"),
"ImPool": Declaration(name: "ImPool", typealiasType: "OpaquePointer")
]

public static let stripPrefix: Set<String> = [
"ig"
]
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/AutoWrapper/FunctionBodyRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct FunctionBodyRenderer {
return [.line("&\(arg.escapedName)")]

case let .arrayFixedSize(count) where arg.type.isConst == false:
if arg.type.type.isNumber && count < 5 {
if arg.type.type.isNumber && count < 5 || arg.type.type == .custom("ImVec2") {
// SIMD vector
return [
.preLine("withUnsafeMutablePointer(to: &\(arg.escapedName)) { \(arg.name)MutPtr in"),
Expand Down
Loading

0 comments on commit a7b7fad

Please sign in to comment.