From 198fd6245b8e544058fecdeadfe20f94ed6dcd7d Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Mon, 13 Jan 2020 16:09:49 +0100 Subject: [PATCH 1/3] Update to new cimgui --- 3rdparty/cimgui | 2 +- Sources/CImGui/cimgui.cpp | 3 +- Sources/CImGui/include/cimgui.h | 133 +++++++++++++------------------- 3 files changed, 57 insertions(+), 81 deletions(-) diff --git a/3rdparty/cimgui b/3rdparty/cimgui index 78ebaaf..548716f 160000 --- a/3rdparty/cimgui +++ b/3rdparty/cimgui @@ -1 +1 @@ -Subproject commit 78ebaaf81da4bb34c81edef8e32ef11bdab4300b +Subproject commit 548716fab7abdf6732a69afa578b38f7158db858 diff --git a/Sources/CImGui/cimgui.cpp b/Sources/CImGui/cimgui.cpp index 6e5e779..600fa92 100644 --- a/Sources/CImGui/cimgui.cpp +++ b/Sources/CImGui/cimgui.cpp @@ -2,9 +2,10 @@ //based on imgui.h file version "1.74 WIP" from Dear ImGui https://github.com/ocornut/imgui #include "./imgui/imgui.h" +#include "./imgui/imgui_internal.h" #include "cimgui.h" -#include "./imgui/imgui_internal.h" + CIMGUI_API ImVec2* ImVec2_ImVec2(void) { diff --git a/Sources/CImGui/include/cimgui.h b/Sources/CImGui/include/cimgui.h index d3d9790..7e24825 100644 --- a/Sources/CImGui/include/cimgui.h +++ b/Sources/CImGui/include/cimgui.h @@ -144,7 +144,8 @@ typedef unsigned int ImU32; typedef int64_t ImS64; typedef uint64_t ImU64; typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd); -typedef unsigned short ImDrawIdx;typedef struct ImVector{int Size;int Capacity;void* Data;} ImVector; +typedef unsigned short ImDrawIdx; +typedef struct ImVector{int Size;int Capacity;void* Data;} ImVector; typedef struct ImVector_float {int Size;int Capacity;float* Data;} ImVector_float; typedef struct ImVector_ImWchar {int Size;int Capacity;ImWchar* Data;} ImVector_ImWchar; typedef struct ImVector_ImDrawVert {int Size;int Capacity;ImDrawVert* Data;} ImVector_ImDrawVert; @@ -173,8 +174,7 @@ struct ImVec4 { float x, y, z, w; }; -enum ImGuiWindowFlags_ -{ +typedef enum { ImGuiWindowFlags_None = 0, ImGuiWindowFlags_NoTitleBar = 1 << 0, ImGuiWindowFlags_NoResize = 1 << 1, @@ -207,9 +207,8 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_Modal = 1 << 27, ImGuiWindowFlags_ChildMenu = 1 << 28, ImGuiWindowFlags_DockNodeHost = 1 << 29 -}; -enum ImGuiInputTextFlags_ -{ +}ImGuiWindowFlags_; +typedef enum { ImGuiInputTextFlags_None = 0, ImGuiInputTextFlags_CharsDecimal = 1 << 0, ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, @@ -232,9 +231,8 @@ enum ImGuiInputTextFlags_ ImGuiInputTextFlags_CallbackResize = 1 << 18, ImGuiInputTextFlags_Multiline = 1 << 20, ImGuiInputTextFlags_NoMarkEdited = 1 << 21 -}; -enum ImGuiTreeNodeFlags_ -{ +}ImGuiInputTextFlags_; +typedef enum { ImGuiTreeNodeFlags_None = 0, ImGuiTreeNodeFlags_Selected = 1 << 0, ImGuiTreeNodeFlags_Framed = 1 << 1, @@ -251,18 +249,16 @@ enum ImGuiTreeNodeFlags_ ImGuiTreeNodeFlags_SpanFullWidth = 1 << 12, ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog -}; -enum ImGuiSelectableFlags_ -{ +}ImGuiTreeNodeFlags_; +typedef enum { ImGuiSelectableFlags_None = 0, ImGuiSelectableFlags_DontClosePopups = 1 << 0, ImGuiSelectableFlags_SpanAllColumns = 1 << 1, ImGuiSelectableFlags_AllowDoubleClick = 1 << 2, ImGuiSelectableFlags_Disabled = 1 << 3, ImGuiSelectableFlags_AllowItemOverlap = 1 << 4 -}; -enum ImGuiComboFlags_ -{ +}ImGuiSelectableFlags_; +typedef enum { ImGuiComboFlags_None = 0, ImGuiComboFlags_PopupAlignLeft = 1 << 0, ImGuiComboFlags_HeightSmall = 1 << 1, @@ -272,9 +268,8 @@ enum ImGuiComboFlags_ ImGuiComboFlags_NoArrowButton = 1 << 5, ImGuiComboFlags_NoPreview = 1 << 6, ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest -}; -enum ImGuiTabBarFlags_ -{ +}ImGuiComboFlags_; +typedef enum { ImGuiTabBarFlags_None = 0, ImGuiTabBarFlags_Reorderable = 1 << 0, ImGuiTabBarFlags_AutoSelectNewTabs = 1 << 1, @@ -286,25 +281,22 @@ enum ImGuiTabBarFlags_ ImGuiTabBarFlags_FittingPolicyScroll = 1 << 7, ImGuiTabBarFlags_FittingPolicyMask_ = ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll, ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown -}; -enum ImGuiTabItemFlags_ -{ +}ImGuiTabBarFlags_; +typedef enum { ImGuiTabItemFlags_None = 0, ImGuiTabItemFlags_UnsavedDocument = 1 << 0, ImGuiTabItemFlags_SetSelected = 1 << 1, ImGuiTabItemFlags_NoCloseWithMiddleMouseButton = 1 << 2, ImGuiTabItemFlags_NoPushId = 1 << 3 -}; -enum ImGuiFocusedFlags_ -{ +}ImGuiTabItemFlags_; +typedef enum { ImGuiFocusedFlags_None = 0, ImGuiFocusedFlags_ChildWindows = 1 << 0, ImGuiFocusedFlags_RootWindow = 1 << 1, ImGuiFocusedFlags_AnyWindow = 1 << 2, ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows -}; -enum ImGuiHoveredFlags_ -{ +}ImGuiFocusedFlags_; +typedef enum { ImGuiHoveredFlags_None = 0, ImGuiHoveredFlags_ChildWindows = 1 << 0, ImGuiHoveredFlags_RootWindow = 1 << 1, @@ -315,9 +307,8 @@ enum ImGuiHoveredFlags_ ImGuiHoveredFlags_AllowWhenDisabled = 1 << 7, ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows -}; -enum ImGuiDockNodeFlags_ -{ +}ImGuiHoveredFlags_; +typedef enum { ImGuiDockNodeFlags_None = 0, ImGuiDockNodeFlags_KeepAliveOnly = 1 << 0, ImGuiDockNodeFlags_NoDockingInCentralNode = 1 << 2, @@ -325,9 +316,8 @@ enum ImGuiDockNodeFlags_ ImGuiDockNodeFlags_NoSplit = 1 << 4, ImGuiDockNodeFlags_NoResize = 1 << 5, ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6 -}; -enum ImGuiDragDropFlags_ -{ +}ImGuiDockNodeFlags_; +typedef enum { ImGuiDragDropFlags_None = 0, ImGuiDragDropFlags_SourceNoPreviewTooltip = 1 << 0, ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, @@ -339,9 +329,8 @@ enum ImGuiDragDropFlags_ ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, ImGuiDragDropFlags_AcceptNoPreviewTooltip = 1 << 12, ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect -}; -enum ImGuiDataType_ -{ +}ImGuiDragDropFlags_; +typedef enum { ImGuiDataType_S8, ImGuiDataType_U8, ImGuiDataType_S16, @@ -353,18 +342,16 @@ enum ImGuiDataType_ ImGuiDataType_Float, ImGuiDataType_Double, ImGuiDataType_COUNT -}; -enum ImGuiDir_ -{ +}ImGuiDataType_; +typedef enum { ImGuiDir_None = -1, ImGuiDir_Left = 0, ImGuiDir_Right = 1, ImGuiDir_Up = 2, ImGuiDir_Down = 3, ImGuiDir_COUNT -}; -enum ImGuiKey_ -{ +}ImGuiDir_; +typedef enum { ImGuiKey_Tab, ImGuiKey_LeftArrow, ImGuiKey_RightArrow, @@ -388,9 +375,8 @@ enum ImGuiKey_ ImGuiKey_Y, ImGuiKey_Z, ImGuiKey_COUNT -}; -enum ImGuiNavInput_ -{ +}ImGuiKey_; +typedef enum { ImGuiNavInput_Activate, ImGuiNavInput_Cancel, ImGuiNavInput_Input, @@ -414,9 +400,8 @@ enum ImGuiNavInput_ ImGuiNavInput_KeyDown_, ImGuiNavInput_COUNT, ImGuiNavInput_InternalStart_ = ImGuiNavInput_KeyMenu_ -}; -enum ImGuiConfigFlags_ -{ +}ImGuiNavInput_; +typedef enum { ImGuiConfigFlags_None = 0, ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, ImGuiConfigFlags_NavEnableGamepad = 1 << 1, @@ -430,9 +415,8 @@ enum ImGuiConfigFlags_ ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, ImGuiConfigFlags_IsSRGB = 1 << 20, ImGuiConfigFlags_IsTouchScreen = 1 << 21 -}; -enum ImGuiBackendFlags_ -{ +}ImGuiConfigFlags_; +typedef enum { ImGuiBackendFlags_None = 0, ImGuiBackendFlags_HasGamepad = 1 << 0, ImGuiBackendFlags_HasMouseCursors = 1 << 1, @@ -441,9 +425,8 @@ enum ImGuiBackendFlags_ ImGuiBackendFlags_PlatformHasViewports = 1 << 10, ImGuiBackendFlags_HasMouseHoveredViewport=1 << 11, ImGuiBackendFlags_RendererHasViewports = 1 << 12 -}; -enum ImGuiCol_ -{ +}ImGuiBackendFlags_; +typedef enum { ImGuiCol_Text, ImGuiCol_TextDisabled, ImGuiCol_WindowBg, @@ -495,9 +478,8 @@ enum ImGuiCol_ ImGuiCol_NavWindowingDimBg, ImGuiCol_ModalWindowDimBg, ImGuiCol_COUNT -}; -enum ImGuiStyleVar_ -{ +}ImGuiCol_; +typedef enum { ImGuiStyleVar_Alpha, ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, @@ -522,9 +504,8 @@ enum ImGuiStyleVar_ ImGuiStyleVar_ButtonTextAlign, ImGuiStyleVar_SelectableTextAlign, ImGuiStyleVar_COUNT -}; -enum ImGuiColorEditFlags_ -{ +}ImGuiStyleVar_; +typedef enum { ImGuiColorEditFlags_None = 0, ImGuiColorEditFlags_NoAlpha = 1 << 1, ImGuiColorEditFlags_NoPicker = 1 << 2, @@ -553,9 +534,8 @@ enum ImGuiColorEditFlags_ ImGuiColorEditFlags__DataTypeMask = ImGuiColorEditFlags_Uint8|ImGuiColorEditFlags_Float, ImGuiColorEditFlags__PickerMask = ImGuiColorEditFlags_PickerHueWheel|ImGuiColorEditFlags_PickerHueBar, ImGuiColorEditFlags__InputMask = ImGuiColorEditFlags_InputRGB|ImGuiColorEditFlags_InputHSV -}; -enum ImGuiMouseCursor_ -{ +}ImGuiColorEditFlags_; +typedef enum { ImGuiMouseCursor_None = -1, ImGuiMouseCursor_Arrow = 0, ImGuiMouseCursor_TextInput, @@ -566,14 +546,13 @@ enum ImGuiMouseCursor_ ImGuiMouseCursor_ResizeNWSE, ImGuiMouseCursor_Hand, ImGuiMouseCursor_COUNT -}; -enum ImGuiCond_ -{ +}ImGuiMouseCursor_; +typedef enum { ImGuiCond_Always = 1 << 0, ImGuiCond_Once = 1 << 1, ImGuiCond_FirstUseEver = 1 << 2, ImGuiCond_Appearing = 1 << 3 -}; +}ImGuiCond_; struct ImGuiStyle { float Alpha; @@ -796,8 +775,7 @@ struct ImDrawListSplitter int _Count; ImVector_ImDrawChannel _Channels; }; -enum ImDrawCornerFlags_ -{ +typedef enum { ImDrawCornerFlags_None = 0, ImDrawCornerFlags_TopLeft = 1 << 0, ImDrawCornerFlags_TopRight = 1 << 1, @@ -808,14 +786,13 @@ enum ImDrawCornerFlags_ ImDrawCornerFlags_Left = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft, ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight, ImDrawCornerFlags_All = 0xF -}; -enum ImDrawListFlags_ -{ +}ImDrawCornerFlags_; +typedef enum { ImDrawListFlags_None = 0, ImDrawListFlags_AntiAliasedLines = 1 << 0, ImDrawListFlags_AntiAliasedFill = 1 << 1, ImDrawListFlags_AllowVtxOffset = 1 << 2 -}; +}ImDrawListFlags_; struct ImDrawList { ImVector_ImDrawCmd CmdBuffer; @@ -887,12 +864,11 @@ struct ImFontAtlasCustomRect ImVec2 GlyphOffset; ImFont* Font; }; -enum ImFontAtlasFlags_ -{ +typedef enum { ImFontAtlasFlags_None = 0, ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0, ImFontAtlasFlags_NoMouseCursors = 1 << 1 -}; +}ImFontAtlasFlags_; struct ImFontAtlas { bool Locked; @@ -966,8 +942,7 @@ struct ImGuiPlatformIO ImGuiViewport* MainViewport; ImVector_ImGuiViewportPtr Viewports; }; -enum ImGuiViewportFlags_ -{ +typedef enum { ImGuiViewportFlags_None = 0, ImGuiViewportFlags_NoDecoration = 1 << 0, ImGuiViewportFlags_NoTaskBarIcon = 1 << 1, @@ -979,7 +954,7 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_Minimized = 1 << 7, ImGuiViewportFlags_NoAutoMerge = 1 << 8, ImGuiViewportFlags_CanHostOtherWindows = 1 << 9 -}; +}ImGuiViewportFlags_; struct ImGuiViewport { ImGuiID ID; From 5d70f1f0035b97786db21fd84c28f04ecd76cab8 Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Mon, 13 Jan 2020 16:33:01 +0100 Subject: [PATCH 2/3] Extend auto wrapper to handle multiple input and output files --- Makefile | 3 ++- Sources/AutoWrapper/Definitions.swift | 18 +++++++++++++--- Sources/AutoWrapper/main.swift | 30 +++++++++++++++------------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 88949bb..a040940 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ copyLibImGui: cp $(imgui_src)/generator/output/cimgui.cpp $(c_imgui_src) generateCInterface: - cd $(imgui_src)/generator && luajit ./generator.lua gcc glfw opengl3 opengl2 sdl + cd $(imgui_src)/generator && luajit ./generator.lua clang sdl glfw glut metal buildCImGui: updateCLibImGui generateCInterface copyLibImGui @@ -47,6 +47,7 @@ runCI: wrapLibImGui: buildAutoWrapper $(release_dir)/AutoWrapper $(imgui_src)/generator/output/definitions.json $(swift_imgui_src)/ImGui+Definitions.swift + #$(release_dir)/AutoWrapper $(imgui_src)/generator/output/impl_definitions.json $(swift_imgui_src)/ImGui+ImplDefinitions.swift clean: swift package reset diff --git a/Sources/AutoWrapper/Definitions.swift b/Sources/AutoWrapper/Definitions.swift index 096a633..bd4df3a 100644 --- a/Sources/AutoWrapper/Definitions.swift +++ b/Sources/AutoWrapper/Definitions.swift @@ -150,11 +150,23 @@ public struct Definition: Decodable { var constructors: [ConstructorDef] = [] if container.contains(.funcname) && !container.contains(.destructor) && !container.contains(.constructor) { - functions.insert(try FunctionDef(from: decoder)) + do { + functions.insert(try FunctionDef(from: decoder)) + } catch { + print("DECODING ERROR FunctionDef", decoder.codingPath, error.localizedDescription) + } } else if container.contains(.destructor) { - destructors.append(try DestructorDef(from: decoder)) + do { + destructors.append(try DestructorDef(from: decoder)) + } catch { + print("DECODING ERROR DestructorDef", decoder.codingPath, error.localizedDescription) + } } else if container.contains(.constructor) { - constructors.append(try ConstructorDef(from: decoder)) + do { + constructors.append(try ConstructorDef(from: decoder)) + } catch { + print("DECODING ERROR ConstructorDef", decoder.codingPath, error.localizedDescription) + } } self.functions = functions diff --git a/Sources/AutoWrapper/main.swift b/Sources/AutoWrapper/main.swift index 0a78c02..d851a0b 100644 --- a/Sources/AutoWrapper/main.swift +++ b/Sources/AutoWrapper/main.swift @@ -22,16 +22,18 @@ public func getDirectory(ofFile filePath: String = #file) -> String { } // Input: /3rdparty/cimgui/generator/output/definitions.json -public let kInputFile: String +public let kInputFiles: [String] // Output /Sources/ImGui/ImGui+Definitions.swift -public let kOutputFile: String +public let kOutputFiles: [String] if CommandLine.arguments.count == 3 { - kInputFile = CommandLine.arguments[1] - kOutputFile = CommandLine.arguments[2] + kInputFiles = [CommandLine.arguments[1]] + kOutputFiles = [CommandLine.arguments[2]] } else { - kInputFile = getDirectory() + "/../../3rdparty/cimgui/generator/output/definitions.json" - kOutputFile = getDirectory() + "/../ImGui/ImGui+Definitions.swift" + let src = getDirectory() + "/../../3rdparty/cimgui/generator/output/" + let dest = getDirectory() + "/../ImGui/" + kInputFiles = ["definitions.json"].map { "\(src)\($0)" } + kOutputFiles = ["ImGui+Definitions.swift"].map { "\(dest)\($0)" } } public let kHeader = """ @@ -52,14 +54,16 @@ import CImGui public let kFooter = """ """ -try convert(filePath: kInputFile, validOnly: true) { body in - let out: String = [kHeader, body, kFooter].joined(separator: "\n\n") +for (inputFile, outputFile) in zip(kInputFiles, kOutputFiles) { + try convert(filePath: inputFile, validOnly: true) { body in + let out: String = [kHeader, body, kFooter].joined(separator: "\n\n") - guard let data: Data = out.data(using: .utf8) else { - throw ConversionError(localizedDescription: "Could not generate data from output string \(out)") - } + guard let data: Data = out.data(using: .utf8) else { + throw ConversionError(localizedDescription: "Could not generate data from output string \(out)") + } - let outURL = URL(fileURLWithPath: kOutputFile) + let outURL = URL(fileURLWithPath: outputFile) - try data.write(to: outURL) + try data.write(to: outURL) + } } From 2c7985a443e65214f4b695f9351b9517bd60fd5e Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Mon, 13 Jan 2020 16:42:46 +0100 Subject: [PATCH 3/3] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d91890..4b45b17 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ import PackageDescription let package = Package( name: "YourPackageName", dependencies: [ - .package(url: "https://github.com/ctreffs/SwiftImGui.git", from: "1.1.0") + .package(url: "https://github.com/ctreffs/SwiftImGui.git", from: "1.1.1") ], targets: [ .target(