├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── Docs
├── hellow_world.png
├── sample01-ios.jpg
├── sample01-osx.gif
├── sample02-osx.gif
├── sample02-osx_code_editor.png
└── swiftgui.png
├── LICENSE
├── README.md
├── Source
├── .swiftlint.yml
├── Sample01Mac
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ ├── Contents.json
│ │ └── swiftgui.imageset
│ │ │ ├── Contents.json
│ │ │ └── swiftgui.png
│ ├── Base.lproj
│ │ └── Main.storyboard
│ ├── Info.plist
│ ├── Sample01Mac.entitlements
│ └── ViewController.swift
├── Sample01iOS
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ ├── Contents.json
│ │ └── swiftgui.imageset
│ │ │ ├── Contents.json
│ │ │ └── swiftgui.png
│ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ ├── Info.plist
│ ├── SceneDelegate.swift
│ └── ViewController.swift
├── Sample02Mac
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ └── Contents.json
│ ├── Base.lproj
│ │ └── Main.storyboard
│ ├── Info.plist
│ ├── MTKViewController.swift
│ ├── Sample02Mac.entitlements
│ └── ViewController.swift
├── SwiftGui.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── SwiftGuiMac.xcscheme
│ │ └── SwiftGuiiOS.xcscheme
├── SwiftGui
│ ├── Attributes
│ │ ├── GuiColorProperty.swift
│ │ ├── GuiCondition.swift
│ │ ├── GuiConfig.swift
│ │ ├── GuiDirection.swift
│ │ ├── GuiDockConfig.swift
│ │ ├── GuiEdge.swift
│ │ ├── GuiInputTextConfig.swift
│ │ ├── GuiSelectable.swift
│ │ ├── GuiStyleProperty.swift
│ │ ├── GuiTabBarConfig.swift
│ │ ├── GuiTabItemConfig.swift
│ │ ├── GuiTreeConfig.swift
│ │ └── GuiWindowConfig.swift
│ ├── Components
│ │ ├── Event
│ │ │ └── HoverEvent.swift
│ │ ├── Modifiers
│ │ │ ├── Color
│ │ │ │ ├── ActiveColorModifier.swift
│ │ │ │ ├── BackgroundColorModifier.swift
│ │ │ │ ├── BorderColorModifier.swift
│ │ │ │ ├── HoveredColorModifier.swift
│ │ │ │ ├── SelectionColorModifier.swift
│ │ │ │ ├── TextColorModifier.swift
│ │ │ │ └── TintColorModifier.swift
│ │ │ ├── FontModifier.swift
│ │ │ ├── PaddingModifier.swift
│ │ │ ├── SizeModifier.swift
│ │ │ ├── SnapModifier.swift
│ │ │ ├── WindowPositionModifier.swift
│ │ │ └── WindowSizeModifier.swift
│ │ ├── Values
│ │ │ └── IdentifierValue.swift
│ │ └── Views
│ │ │ ├── Form
│ │ │ ├── Button.swift
│ │ │ ├── CheckBox.swift
│ │ │ ├── ColorEdit.swift
│ │ │ ├── ComboBox.swift
│ │ │ ├── Drag.swift
│ │ │ ├── Image.swift
│ │ │ ├── ListBox.swift
│ │ │ ├── Plot.swift
│ │ │ ├── RadioButton
│ │ │ │ ├── RadioButton.swift
│ │ │ │ └── RadioButtonGroup.swift
│ │ │ ├── Slider.swift
│ │ │ ├── TabBar
│ │ │ │ ├── TabBar.swift
│ │ │ │ └── TabItem.swift
│ │ │ ├── Text.swift
│ │ │ ├── TextEditor.swift
│ │ │ ├── TextField.swift
│ │ │ ├── TextLabel.swift
│ │ │ └── Tree
│ │ │ │ ├── CollapsingHeader.swift
│ │ │ │ └── Tree.swift
│ │ │ ├── Generic
│ │ │ ├── Empty.swift
│ │ │ ├── ForEach.swift
│ │ │ ├── Group.swift
│ │ │ ├── Perform.swift
│ │ │ ├── Popup.swift
│ │ │ ├── SubWindow.swift
│ │ │ ├── ToolTip.swift
│ │ │ └── Window.swift
│ │ │ ├── Layout
│ │ │ ├── Column
│ │ │ │ ├── Column.swift
│ │ │ │ ├── ColumnNext.swift
│ │ │ │ └── ColumnWidth.swift
│ │ │ ├── Divider.swift
│ │ │ ├── HStack.swift
│ │ │ ├── List.swift
│ │ │ ├── NewLine.swift
│ │ │ ├── SameLine.swift
│ │ │ └── Spacing.swift
│ │ │ └── Menu
│ │ │ ├── MenuBar.swift
│ │ │ ├── MenuGroup.swift
│ │ │ └── MenuItem.swift
│ ├── Core
│ │ ├── GuiRenderer.h
│ │ ├── GuiRenderer.mm
│ │ ├── ImGuiStyleWrapper.h
│ │ ├── ImGuiStyleWrapper.mm
│ │ ├── ImGuiWrapper.h
│ │ ├── ImGuiWrapper.mm
│ │ ├── TextEditorWrapper.h
│ │ ├── TextEditorWrapper.mm
│ │ ├── imgui
│ │ │ ├── imconfig.h
│ │ │ ├── imgui.cpp
│ │ │ ├── imgui.h
│ │ │ ├── imgui_demo.cpp
│ │ │ ├── imgui_draw.cpp
│ │ │ ├── imgui_internal.h
│ │ │ ├── imgui_widgets.cpp
│ │ │ ├── imstb_rectpack.h
│ │ │ ├── imstb_textedit.h
│ │ │ ├── imstb_truetype.h
│ │ │ └── render
│ │ │ │ ├── imgui_impl_metal.h
│ │ │ │ └── imgui_impl_metal.mm
│ │ └── thirdparty
│ │ │ └── ImGuiColorTextEdit
│ │ │ ├── CONTRIBUTING
│ │ │ ├── LICENSE
│ │ │ ├── README.md
│ │ │ ├── TextEditor.cpp
│ │ │ └── TextEditor.h
│ ├── GuiBuilder.swift
│ ├── GuiNode.swift
│ ├── GuiNodeList.swift
│ ├── GuiView.swift
│ ├── Info.plist
│ ├── Resources
│ │ └── Font
│ │ │ └── FiraCodeRegular.ttf
│ ├── SwiftGui.h
│ ├── Theme
│ │ ├── Color
│ │ │ ├── DarculaTheme.swift
│ │ │ └── LightTheme.swift
│ │ ├── Font
│ │ │ └── DefaultFontGroup.swift
│ │ ├── FontGroup.swift
│ │ └── Theme.swift
│ └── Utils
│ │ └── Extensions.swift
├── SwiftGuiMac
│ ├── Info.plist
│ ├── SwiftGui.h
│ ├── imgui_impl_osx.h
│ └── imgui_impl_osx.mm
└── SwiftGuiiOS
│ ├── Info.plist
│ └── SwiftGui.h
└── SwiftGui.podspec
/.gitattributes:
--------------------------------------------------------------------------------
1 | Source/SwiftGui/Core/* linguist-vendored=true
2 | Source/SwiftGui/SwiftGuiiOS/* linguist-vendored=true
3 | Source/SwiftGui/SwiftGuiMac/* linguist-vendored=true
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #########################
2 | # .gitignore file for Xcode4 and Xcode5 Source projects
3 | #
4 | # Apple bugs, waiting for Apple to fix/respond:
5 | #
6 | # 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
7 | #
8 | # Version 2.6
9 | # For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
10 | #
11 | # 2015 updates:
12 | # - Fixed typo in "xccheckout" line - thanks to @lyck for pointing it out!
13 | # - Fixed the .idea optional ignore. Thanks to @hashier for pointing this out
14 | # - Finally added "xccheckout" to the ignore. Apple still refuses to answer support requests about this, but in practice it seems you should ignore it.
15 | # - minor tweaks from Jona and Coeur (slightly more precise xc* filtering/names)
16 | # 2014 updates:
17 | # - appended non-standard items DISABLED by default (uncomment if you use those tools)
18 | # - removed the edit that an SO.com moderator made without bothering to ask me
19 | # - researched CocoaPods .lock more carefully, thanks to Gokhan Celiker
20 | # 2013 updates:
21 | # - fixed the broken "save personal Schemes"
22 | # - added line-by-line explanations for EVERYTHING (some were missing)
23 | #
24 | # NB: if you are storing "built" products, this WILL NOT WORK,
25 | # and you should use a different .gitignore (or none at all)
26 | # This file is for SOURCE projects, where there are many extra
27 | # files that we want to exclude
28 | #
29 | #########################
30 |
31 | #####
32 | # OS X temporary files that should never be committed
33 | #
34 | # c.f. http://www.westwind.com/reference/os-x/invisibles.html
35 |
36 | .DS_Store
37 |
38 | # c.f. http://www.westwind.com/reference/os-x/invisibles.html
39 |
40 | .Trashes
41 |
42 | # c.f. http://www.westwind.com/reference/os-x/invisibles.html
43 |
44 | *.swp
45 |
46 | #
47 | # *.lock - this is used and abused by many editors for many different things.
48 | # For the main ones I use (e.g. Eclipse), it should be excluded
49 | # from source-control, but YMMV.
50 | # (lock files are usually local-only file-synchronization on the local FS that should NOT go in git)
51 | # c.f. the "OPTIONAL" section at bottom though, for tool-specific variations!
52 | #
53 | # In particular, if you're using CocoaPods, you'll want to comment-out this line:
54 | *.lock
55 |
56 |
57 | #
58 | # profile - REMOVED temporarily (on double-checking, I can't find it in OS X docs?)
59 | #profile
60 |
61 |
62 | ####
63 | # Xcode temporary files that should never be committed
64 | #
65 | # NB: NIB/XIB files still exist even on Storyboard projects, so we want this...
66 |
67 | *~.nib
68 |
69 |
70 | ####
71 | # Xcode build files -
72 | #
73 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData"
74 |
75 | DerivedData/
76 |
77 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build"
78 |
79 | build/
80 |
81 |
82 | #####
83 | # Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
84 | #
85 | # This is complicated:
86 | #
87 | # SOMETIMES you need to put this file in version control.
88 | # Apple designed it poorly - if you use "custom executables", they are
89 | # saved in this file.
90 | # 99% of projects do NOT use those, so they do NOT want to version control this file.
91 | # ..but if you're in the 1%, comment out the line "*.pbxuser"
92 |
93 | # .pbxuser: http://lists.apple.com/archives/xcode-users/2004/Jan/msg00193.html
94 |
95 | *.pbxuser
96 |
97 | # .mode1v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html
98 |
99 | *.mode1v3
100 |
101 | # .mode2v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html
102 |
103 | *.mode2v3
104 |
105 | # .perspectivev3: http://stackoverflow.com/questions/5223297/xcode-projects-what-is-a-perspectivev3-file
106 |
107 | *.perspectivev3
108 |
109 | # NB: also, whitelist the default ones, some projects need to use these
110 | !default.pbxuser
111 | !default.mode1v3
112 | !default.mode2v3
113 | !default.perspectivev3
114 |
115 |
116 | ####
117 | # Xcode 4 - semi-personal settings
118 | #
119 | # Apple Shared data that Apple put in the wrong folder
120 | # c.f. http://stackoverflow.com/a/19260712/153422
121 | # FROM ANSWER: Apple says "don't ignore it"
122 | # FROM COMMENTS: Apple is wrong; Apple code is too buggy to trust; there are no known negative side-effects to ignoring Apple's unofficial advice and instead doing the thing that actively fixes bugs in Xcode
123 | # Up to you, but ... current advice: ignore it.
124 | *.xccheckout
125 |
126 | #
127 | #
128 | # OPTION 1: ---------------------------------
129 | # throw away ALL personal settings (including custom schemes!
130 | # - unless they are "shared")
131 | # As per build/ and DerivedData/, this ought to have a trailing slash
132 | #
133 | # NB: this is exclusive with OPTION 2 below
134 | xcuserdata/
135 |
136 | # OPTION 2: ---------------------------------
137 | # get rid of ALL personal settings, but KEEP SOME OF THEM
138 | # - NB: you must manually uncomment the bits you want to keep
139 | #
140 | # NB: this *requires* git v1.8.2 or above; you may need to upgrade to latest OS X,
141 | # or manually install git over the top of the OS X version
142 | # NB: this is exclusive with OPTION 1 above
143 | #
144 | #xcuserdata/**/*
145 |
146 | # (requires option 2 above): Personal Schemes
147 | #
148 | #!xcuserdata/**/xcschemes/*
149 |
150 | ####
151 | # XCode 4 workspaces - more detailed
152 | #
153 | # Workspaces are important! They are a core feature of Xcode - don't exclude them :)
154 | #
155 | # Workspace layout is quite spammy. For reference:
156 | #
157 | # /(root)/
158 | # /(project-name).xcodeproj/
159 | # project.pbxproj
160 | # /project.xcworkspace/
161 | # contents.xcworkspacedata
162 | # /xcuserdata/
163 | # /(your name)/xcuserdatad/
164 | # UserInterfaceState.xcuserstate
165 | # /xcshareddata/
166 | # /xcschemes/
167 | # (shared scheme name).xcscheme
168 | # /xcuserdata/
169 | # /(your name)/xcuserdatad/
170 | # (private scheme).xcscheme
171 | # xcschememanagement.plist
172 | #
173 | #
174 |
175 | ####
176 | # Xcode 4 - Deprecated classes
177 | #
178 | # Allegedly, if you manually "deprecate" your classes, they get moved here.
179 | #
180 | # We're using source-control, so this is a "feature" that we do not want!
181 |
182 | *.moved-aside
183 |
184 | ####
185 | # OPTIONAL: Some well-known tools that people use side-by-side with Xcode / iOS development
186 | #
187 | # NB: I'd rather not include these here, but gitignore's design is weak and doesn't allow
188 | # modular gitignore: you have to put EVERYTHING in one file.
189 | #
190 | # COCOAPODS:
191 | #
192 | # c.f. http://guides.cocoapods.org/using/using-cocoapods.html#what-is-a-podfilelock
193 | # c.f. http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
194 | #
195 | #!Podfile.lock
196 | #
197 | # RUBY:
198 | #
199 | # c.f. http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
200 | #
201 | #!Gemfile.lock
202 | #
203 | # IDEA:
204 | #
205 | # c.f. https://www.jetbrains.com/objc/help/managing-projects-under-version-control.html?search=workspace.xml
206 | #
207 | #.idea/workspace.xml
208 | #
209 | # TEXTMATE:
210 | #
211 | # -- UNVERIFIED: c.f. http://stackoverflow.com/a/50283/153422
212 | #
213 | #tm_build_errors
214 |
215 | ####
216 | # UNKNOWN: recommended by others, but I can't discover what these files are
217 | #
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | [fork]: https://github.com/ORG/REPO/fork
4 | [pr]: https://github.com/ORG/REPO/compare
5 | [code-of-conduct]: CODE_OF_CONDUCT.md
6 |
7 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
8 |
9 | ## Submitting a pull request
10 |
11 | 1. Check the issues or open a new one
12 | 2. Fork this repository
13 | 3. Create your feature branch: `git checkout -b my-new-feature`
14 | 4. Commit your changes: `git commit -am 'Add some feature'`
15 | 5. Push to the branch: `git push origin my-new-feature`
16 | 6. Submit a pull request linked to the issue 1. :D
17 |
18 | Here are a few things you can do that will increase the likelihood of your pull request being accepted:
19 |
20 | - Follow the overall style of the project.
21 | - Write tests.
22 | - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, submit them as separate pull requests.
23 | - Write [good commit messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
24 | - Follow semantic versioning
25 |
26 | ## Resources
27 |
28 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
29 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
30 | - [GitHub Help](https://help.github.com)
--------------------------------------------------------------------------------
/Docs/hellow_world.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Docs/hellow_world.png
--------------------------------------------------------------------------------
/Docs/sample01-ios.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Docs/sample01-ios.jpg
--------------------------------------------------------------------------------
/Docs/sample01-osx.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Docs/sample01-osx.gif
--------------------------------------------------------------------------------
/Docs/sample02-osx.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Docs/sample02-osx.gif
--------------------------------------------------------------------------------
/Docs/sample02-osx_code_editor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Docs/sample02-osx_code_editor.png
--------------------------------------------------------------------------------
/Docs/swiftgui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Docs/swiftgui.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2019, Erick Jung. All rights reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 
4 |
5 | [](LICENSE)
6 | [](https://swift.org/download)
7 | [](https://github.com/Carthage/Carthage)
8 |
9 | SwiftGUI is an experimental API inspired by SwiftUI DSL, using Dear ImGui as renderer and running on OSX and iOS.
10 |
11 |
12 |
13 |
14 |
15 |
16 | ```swift
17 | Window("SwiftGUI") {
18 |
19 | Text("Hello world!")
20 |
21 | HStack {
22 | ForEach(1...2) { val in
23 | Button("Click \(val)")
24 | }
25 |
26 | ForEach(1...2) { val in
27 | CheckBox("Check \(val)", selectedState: true)
28 | }
29 |
30 | ForEach(1...2) { val in
31 | RadioButton("Radio \(val)", activeState: true)
32 | }
33 | }
34 | }
35 | ```
36 |
37 | ## Highlights
38 |
39 | * Easy to use abstraction for Dear ImGui
40 | * Multi-platform support (iOS 11+ and macOS 10.13+)
41 | * Huge list of UI components already available
42 |
43 | ### Theme support
44 | - Color scheme (embedded Darcula and Light)
45 | - Custom Fonts (embedded FiraCode)
46 |
47 | ### Components
48 | - Buttons
49 | - CheckBox
50 | - Color Selection
51 | - ComboBox
52 | - Drag
53 | - Dock
54 | - Image
55 | - TextField
56 | - Lists
57 | - Menu
58 | - Plotting
59 | - Popup
60 | - RadioButton
61 | - SelectableFields
62 | - Sliders
63 | - TabBar
64 | - Texts
65 | - Text Editor (Code editor)
66 | - Tooltips
67 | - Tree
68 | - Window
69 | - General
70 | - Group
71 | - HStack
72 | - Separator/NewLine/Spacing/Indent
73 | - ForEach
74 | - Perform
75 |
76 |
77 | ## Installation
78 |
79 | ### Carthage
80 |
81 | To integrate `SwiftGui` into your Xcode project using Carthage, specify it in your `Cartfile`:
82 |
83 | ```ogdl
84 | github "erickjung/SwiftGUI" "0.9.3"
85 | ```
86 |
87 | For `OSX` project, run:
88 |
89 | ```ogdl
90 | carthage update --platform macOS
91 | ```
92 |
93 | For `iOS` project, run:
94 |
95 | ```ogdl
96 | carthage update --platform iOS
97 | ```
98 |
99 | ### Cocoapods
100 |
101 | To integrate `SwiftGui` into your Xcode project using Cocoapods, specify it in your `Podfile`:
102 |
103 | ```ogdl
104 | pod 'SwiftGui', '~> 0.9.3'
105 | ```
106 |
107 | run:
108 |
109 | ```ogdl
110 | pod install
111 | ```
112 |
113 | ## Using SwiftGUI
114 |
115 |
116 |
117 |
118 |
119 | |
120 |
121 |
122 |
123 | Mockingbird
124 | |
125 |
126 |
127 |
128 | ## Samples
129 |
130 |
154 |
155 | ## Contributing
156 |
157 | Read the [Contributing guidelines](CONTRIBUTING.md)
158 |
159 | ## License
160 |
161 | [MIT](LICENSE)
162 |
163 | ## Using
164 |
165 | * [Dear ImGui](https://github.com/ocornut/imgui) (1.77)
166 | * [ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit)
167 |
168 |
--------------------------------------------------------------------------------
/Source/.swiftlint.yml:
--------------------------------------------------------------------------------
1 | disabled_rules: # rule identifiers to exclude from running
2 | - colon
3 | - line_length
4 | - cyclomatic_complexity
5 | - identifier_name
6 | - vertical_parameter_alignment
7 | - large_tuple
8 | excluded:
9 | - Carthage
10 | - Pods
11 | - Mockingbird/Thirdparty
12 | opt_in_rules:
13 | - closure_spacing
14 |
15 | file_length:
16 | warning: 600
17 | error: 1000
18 |
19 | function_parameter_count:
20 | warning: 8
21 | error: 10
22 |
23 | function_body_length:
24 | warning: 120
25 | error: 200
26 |
27 | number_separator:
28 | minimum_length: 5
29 |
30 | identifier_name:
31 | min_length: 3 # only min_length
32 | error: 3 # only error
33 | excluded: # excluded via string array
34 | - id
35 | - in
36 | - URL
37 |
38 | type_name:
39 | max_length: 50
40 |
--------------------------------------------------------------------------------
/Source/Sample01Mac/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Cocoa
10 |
11 | @NSApplicationMain
12 | class AppDelegate: NSObject, NSApplicationDelegate {
13 |
14 | func applicationDidFinishLaunching(_ aNotification: Notification) {
15 | // Insert code here to initialize your application
16 | }
17 |
18 | func applicationWillTerminate(_ aNotification: Notification) {
19 | // Insert code here to tear down your application
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Source/Sample01Mac/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "mac",
5 | "size" : "16x16",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "mac",
10 | "size" : "16x16",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "mac",
15 | "size" : "32x32",
16 | "scale" : "1x"
17 | },
18 | {
19 | "idiom" : "mac",
20 | "size" : "32x32",
21 | "scale" : "2x"
22 | },
23 | {
24 | "idiom" : "mac",
25 | "size" : "128x128",
26 | "scale" : "1x"
27 | },
28 | {
29 | "idiom" : "mac",
30 | "size" : "128x128",
31 | "scale" : "2x"
32 | },
33 | {
34 | "idiom" : "mac",
35 | "size" : "256x256",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "mac",
40 | "size" : "256x256",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "mac",
45 | "size" : "512x512",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "mac",
50 | "size" : "512x512",
51 | "scale" : "2x"
52 | }
53 | ],
54 | "info" : {
55 | "version" : 1,
56 | "author" : "xcode"
57 | }
58 | }
--------------------------------------------------------------------------------
/Source/Sample01Mac/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/Source/Sample01Mac/Assets.xcassets/swiftgui.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "swiftgui.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/Source/Sample01Mac/Assets.xcassets/swiftgui.imageset/swiftgui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Source/Sample01Mac/Assets.xcassets/swiftgui.imageset/swiftgui.png
--------------------------------------------------------------------------------
/Source/Sample01Mac/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
19 | CFBundleShortVersionString
20 | $(MARKETING_VERSION)
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | Copyright © 2020 Erick Jung. All rights reserved.
27 | NSMainStoryboardFile
28 | Main
29 | NSPrincipalClass
30 | NSApplication
31 | NSSupportsAutomaticTermination
32 |
33 | NSSupportsSuddenTermination
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Source/Sample01Mac/Sample01Mac.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.files.user-selected.read-only
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Source/Sample01iOS/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
15 | // Override point for customization after application launch.
16 | return true
17 | }
18 |
19 | // MARK: UISceneSession Lifecycle
20 |
21 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
22 | // Called when a new scene session is being created.
23 | // Use this method to select a configuration to create the new scene with.
24 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
25 | }
26 |
27 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) {
28 | // Called when the user discards a scene session.
29 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
30 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Source/Sample01iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/Source/Sample01iOS/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/Source/Sample01iOS/Assets.xcassets/swiftgui.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "filename" : "swiftgui.png",
5 | "idiom" : "universal",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "author" : "xcode",
19 | "version" : 1
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Source/Sample01iOS/Assets.xcassets/swiftgui.imageset/swiftgui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Source/Sample01iOS/Assets.xcassets/swiftgui.imageset/swiftgui.png
--------------------------------------------------------------------------------
/Source/Sample01iOS/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Source/Sample01iOS/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Source/Sample01iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | $(MARKETING_VERSION)
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | LSRequiresIPhoneOS
22 |
23 | UIApplicationSceneManifest
24 |
25 | UIApplicationSupportsMultipleScenes
26 |
27 | UISceneConfigurations
28 |
29 | UIWindowSceneSessionRoleApplication
30 |
31 |
32 | UISceneConfigurationName
33 | Default Configuration
34 | UISceneDelegateClassName
35 | $(PRODUCT_MODULE_NAME).SceneDelegate
36 | UISceneStoryboardFile
37 | Main
38 |
39 |
40 |
41 |
42 | UILaunchStoryboardName
43 | LaunchScreen
44 | UIMainStoryboardFile
45 | Main
46 | UIRequiredDeviceCapabilities
47 |
48 | armv7
49 |
50 | UISupportedInterfaceOrientations
51 |
52 | UIInterfaceOrientationPortrait
53 | UIInterfaceOrientationLandscapeLeft
54 | UIInterfaceOrientationLandscapeRight
55 |
56 | UISupportedInterfaceOrientations~ipad
57 |
58 | UIInterfaceOrientationPortrait
59 | UIInterfaceOrientationPortraitUpsideDown
60 | UIInterfaceOrientationLandscapeLeft
61 | UIInterfaceOrientationLandscapeRight
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/Source/Sample01iOS/SceneDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import UIKit
10 |
11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate {
12 |
13 | var window: UIWindow?
14 |
15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
19 | // guard let _ = (scene as? UIWindowScene) else { return }
20 | }
21 |
22 | func sceneDidDisconnect(_ scene: UIScene) {
23 | // Called as the scene is being released by the system.
24 | // This occurs shortly after the scene enters the background, or when its session is discarded.
25 | // Release any resources associated with this scene that can be re-created the next time the scene connects.
26 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
27 | }
28 |
29 | func sceneDidBecomeActive(_ scene: UIScene) {
30 | // Called when the scene has moved from an inactive state to an active state.
31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
32 | }
33 |
34 | func sceneWillResignActive(_ scene: UIScene) {
35 | // Called when the scene will move from an active state to an inactive state.
36 | // This may occur due to temporary interruptions (ex. an incoming phone call).
37 | }
38 |
39 | func sceneWillEnterForeground(_ scene: UIScene) {
40 | // Called as the scene transitions from the background to the foreground.
41 | // Use this method to undo the changes made on entering the background.
42 | }
43 |
44 | func sceneDidEnterBackground(_ scene: UIScene) {
45 | // Called as the scene transitions from the foreground to the background.
46 | // Use this method to save data, release shared resources, and store enough scene-specific state information
47 | // to restore the scene back to its current state.
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Source/Sample02Mac/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Cocoa
10 |
11 | @NSApplicationMain
12 | class AppDelegate: NSObject, NSApplicationDelegate {
13 |
14 | func applicationDidFinishLaunching(_ aNotification: Notification) {
15 | // Insert code here to initialize your application
16 | }
17 |
18 | func applicationWillTerminate(_ aNotification: Notification) {
19 | // Insert code here to tear down your application
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Source/Sample02Mac/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "mac",
5 | "size" : "16x16",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "mac",
10 | "size" : "16x16",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "mac",
15 | "size" : "32x32",
16 | "scale" : "1x"
17 | },
18 | {
19 | "idiom" : "mac",
20 | "size" : "32x32",
21 | "scale" : "2x"
22 | },
23 | {
24 | "idiom" : "mac",
25 | "size" : "128x128",
26 | "scale" : "1x"
27 | },
28 | {
29 | "idiom" : "mac",
30 | "size" : "128x128",
31 | "scale" : "2x"
32 | },
33 | {
34 | "idiom" : "mac",
35 | "size" : "256x256",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "mac",
40 | "size" : "256x256",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "mac",
45 | "size" : "512x512",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "mac",
50 | "size" : "512x512",
51 | "scale" : "2x"
52 | }
53 | ],
54 | "info" : {
55 | "version" : 1,
56 | "author" : "xcode"
57 | }
58 | }
--------------------------------------------------------------------------------
/Source/Sample02Mac/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/Source/Sample02Mac/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
19 | CFBundleShortVersionString
20 | $(MARKETING_VERSION)
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | Copyright © 2020 Erick Jung. All rights reserved.
27 | NSMainStoryboardFile
28 | Main
29 | NSPrincipalClass
30 | NSApplication
31 | NSSupportsAutomaticTermination
32 |
33 | NSSupportsSuddenTermination
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Source/Sample02Mac/MTKViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Cocoa
10 | import Metal
11 | import MetalKit
12 | import SwiftGui
13 |
14 | class MTKViewController: NSViewController {
15 |
16 | var renderer: GuiRenderer?
17 |
18 | override func viewDidLoad() {
19 | super.viewDidLoad()
20 |
21 | if let mtkView = self.view as? MTKView {
22 |
23 | mtkView.device = MTLCreateSystemDefaultDevice()
24 |
25 | self.renderer = GuiRenderer(view: mtkView)
26 | mtkView.delegate = self.renderer
27 | }
28 |
29 | let trackingArea = NSTrackingArea(rect: .zero,
30 | options: [.mouseMoved, .inVisibleRect, .activeAlways ],
31 | owner: self, userInfo: nil)
32 | self.view.addTrackingArea(trackingArea)
33 |
34 | NSEvent.addLocalMonitorForEvents(matching: [ .keyDown, .keyUp, .flagsChanged, .scrollWheel ]) { event -> NSEvent? in
35 |
36 | if let renderer = self.renderer,
37 | renderer.handle(event, view: self.view) {
38 |
39 | return nil
40 | }
41 |
42 | return event
43 | }
44 | }
45 |
46 | override func mouseMoved(with event: NSEvent) {
47 | self.renderer?.handle(event, view: self.view)
48 | }
49 |
50 | override func mouseDown(with event: NSEvent) {
51 | self.renderer?.handle(event, view: self.view)
52 | }
53 |
54 | override func mouseUp(with event: NSEvent) {
55 | self.renderer?.handle(event, view: self.view)
56 | }
57 |
58 | override func mouseDragged(with event: NSEvent) {
59 | self.renderer?.handle(event, view: self.view)
60 | }
61 |
62 | override func scrollWheel(with event: NSEvent) {
63 | self.renderer?.handle(event, view: self.view)
64 | }
65 |
66 | override var representedObject: Any? {
67 | didSet {
68 | // Update the view, if already loaded.
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Source/Sample02Mac/Sample02Mac.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.files.user-selected.read-only
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Source/Sample02Mac/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Cocoa
10 | import Metal
11 | import MetalKit
12 | import SwiftGui
13 |
14 | class ViewController: MTKViewController {
15 |
16 | enum States {
17 |
18 | static var inputTask: String = ""
19 | }
20 |
21 | var items = [ "Test todo app": false ]
22 |
23 | override func viewDidLoad() {
24 | super.viewDidLoad()
25 |
26 | self.renderer?.delegate = self
27 | self.renderer?.initializePlatform()
28 | }
29 |
30 | override var representedObject: Any? {
31 | didSet {
32 | // Update the view, if already loaded.
33 | }
34 | }
35 | }
36 |
37 | // data
38 | extension ViewController {
39 |
40 | func insertItem(key: String) {
41 | self.items[key] = false
42 | }
43 |
44 | func updateItem(key: String, value: Bool) {
45 | self.items[key] = value
46 | }
47 |
48 | func removeItem(key: String) {
49 | self.items.removeValue(forKey: key)
50 | }
51 | }
52 |
53 | extension ViewController: GuiRendererDelegate {
54 |
55 | func setup() {
56 | DefaultFontGroup().load()
57 | DarculaTheme().apply()
58 | }
59 |
60 | func todoInput() -> GuiView {
61 |
62 | Group {
63 |
64 | Text("Task Description:")
65 |
66 | TextField(textState: States.inputTask, placeHolder: "ex. buy milk") {
67 | States.inputTask = $0
68 | }
69 | .snap()
70 |
71 | Button("Create") {
72 |
73 | if States.inputTask.count > 0 {
74 |
75 | self.insertItem(key: States.inputTask)
76 | States.inputTask = ""
77 | }
78 | }
79 |
80 | NewLine()
81 | }
82 | .padding(.top, value: 10)
83 | }
84 |
85 | func confirmationPopup(name: String) -> GuiView {
86 |
87 | Popup {
88 |
89 | Text("Remove this task?")
90 |
91 | HStack {
92 |
93 | Button("No") {
94 |
95 | Popup.close()
96 | }
97 |
98 | Button("Yes") {
99 |
100 | self.removeItem(key: name)
101 | }
102 | }
103 | }
104 | .identifier(name)
105 | }
106 |
107 | func cell(name: String, value: Bool, color: GuiColor) -> GuiView {
108 |
109 | Group {
110 |
111 | HStack {
112 |
113 | CheckBox(selectedState: value) {
114 |
115 | self.updateItem(key: name, value: $0)
116 | }
117 |
118 | if !value {
119 |
120 | Text(name)
121 |
122 | } else {
123 |
124 | Text(name)
125 | .textColor(.gray)
126 | }
127 | }
128 |
129 | Button("remove") {
130 |
131 | Popup.open(name)
132 | }
133 | .backgroundColor(color)
134 |
135 | confirmationPopup(name: name)
136 |
137 | Divider()
138 | }
139 | .identifier(name)
140 | }
141 |
142 | func todoList() -> GuiView {
143 |
144 | CollapsingHeader("TODO", options: .defaultOpen) {
145 |
146 | SubWindow {
147 |
148 | ForEach(items) { val in
149 |
150 | if !val.1 {
151 |
152 | return self.cell(name: val.0, value: val.1, color: .orange)
153 | }
154 | return nil
155 | }
156 | }
157 | .size(GuiSize(width: 0, height: 150))
158 | .identifier("##todo")
159 | }
160 | }
161 |
162 | func doneList() -> GuiView {
163 |
164 | CollapsingHeader("DONE", options: .defaultOpen) {
165 |
166 | SubWindow {
167 |
168 | ForEach(items) { val in
169 |
170 | if val.1 {
171 |
172 | return self.cell(name: val.0, value: val.1, color: .gray)
173 | }
174 | return nil
175 | }
176 | }
177 | .identifier("##done")
178 | }
179 | }
180 |
181 | func mainView() -> GuiView {
182 |
183 | Window("TODO", options: .noTitleBar) {
184 |
185 | todoInput()
186 | todoList()
187 | doneList()
188 | }
189 | .position(CGPoint(x: 0, y: 0), condition: .always)
190 | .size(CGSize(width: self.view.frame.width,
191 | height: self.view.frame.height), condition: .always)
192 | .font(DefaultFontGroup.Types.FiraCode_18)
193 | }
194 |
195 | func draw() {
196 | mainView().render()
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/Source/SwiftGui.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Source/SwiftGui.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Source/SwiftGui.xcodeproj/xcshareddata/xcschemes/SwiftGuiMac.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
62 |
63 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/Source/SwiftGui.xcodeproj/xcshareddata/xcschemes/SwiftGuiiOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
62 |
63 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiColorProperty.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// A color identifier for styling.
12 | /// Represents: `ImGuiCol`.
13 | public enum GuiColorProperty: Int32 {
14 |
15 | case text
16 | case textDisabled
17 |
18 | /// Background of normal windows
19 | case windowBg
20 |
21 | /// Background of child windows
22 | case childBg
23 |
24 | /// Background of popups menus tooltips windows
25 | case popupBg
26 | case border
27 | case borderShadow
28 |
29 | /// Background of checkbox radio button plot slider text input
30 | case frameBg
31 | case frameBgHovered
32 | case frameBgActive
33 | case titleBg
34 | case titleBgActive
35 | case titleBgCollapsed
36 | case menuBarBg
37 | case scrollbarBg
38 | case scrollbarGrab
39 | case scrollbarGrabHovered
40 | case scrollbarGrabActive
41 | case checkMark
42 | case sliderGrab
43 | case sliderGrabActive
44 | case button
45 | case buttonHovered
46 | case buttonActive
47 |
48 | /// Header* colors are used for CollapsingHeader TreeNode Selectable MenuItem
49 | case header
50 | case headerHovered
51 | case headerActive
52 | case separator
53 | case separatorHovered
54 | case separatorActive
55 | case resizeGrip
56 | case resizeGripHovered
57 | case resizeGripActive
58 | case tab
59 | case tabHovered
60 | case tabActive
61 | case tabUnfocused
62 | case tabUnfocusedActive
63 | case dockingPreview
64 |
65 | /// Background color for empty node (eg CentralNode with no window docked into it)
66 | case dockingEmptyBg
67 | case plotLines
68 | case plotLinesHovered
69 | case plotHistogram
70 | case plotHistogramHovered
71 | case textSelectedBg
72 | case dragDropTarget
73 |
74 | /// Gamepad/keyboard: current highlighted item
75 | case navHighlight
76 |
77 | /// Highlight window when using CTRL+TAB
78 | case navWindowingHighlight
79 |
80 | /// Darken/colorize entire screen behind the CTRL+TAB window list when active
81 | case navWindowingDimBg
82 |
83 | /// Darken/colorize entire screen behind a modal window when one is active
84 | case modalWindowDimBg
85 | }
86 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiCondition.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for condition flags.
12 | /// Represents: `ImGuiCond`.
13 | public struct GuiCondition: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | /// Set the variable always
22 | public static let always = GuiCondition(rawValue: 1 << 0)
23 |
24 | /// Set the variable once per runtime session (only the first call with succeed)
25 | public static let once = GuiCondition(rawValue: 1 << 1)
26 |
27 | /// Set the variable if the object/window has no persistently saved data (no entry in .ini file)
28 | public static let firstUseEver = GuiCondition(rawValue: 1 << 2)
29 |
30 | /// Set the variable if the object/window is appearing after being hidden/inactive (or the first time)
31 | public static let appearing = GuiCondition(rawValue: 1 << 3)
32 | }
33 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for global configuration.
12 | /// Represents: `ImGuiConfigFlags`.
13 | public struct GuiConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiConfig([])
22 |
23 | /// Master keyboard navigation enable flag.
24 | public static let navEnableKeyboard = GuiConfig(rawValue: 1 << 0)
25 |
26 | /// Master gamepad navigation enable flag.
27 | public static let navEnableGamepad = GuiConfig(rawValue: 1 << 1)
28 |
29 | /// Instruct navigation to move the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is awkward.
30 | public static let navEnableSetMousePos = GuiConfig(rawValue: 1 << 2)
31 |
32 | /// Instruct navigation to not set the want_capture_keyboard flag when nav_active is set.
33 | public static let navNoCaptureKeyboard = GuiConfig(rawValue: 1 << 3)
34 |
35 | /// Instruct imgui to clear mouse position/buttons on a new frame. This allows ignoring the mouse information set by the back-end.
36 | public static let noMouse = GuiConfig(rawValue: 1 << 4)
37 |
38 | /// Instruct back-end to not alter mouse cursor shape and visibility.
39 | public static let noMouseCursorChange = GuiConfig(rawValue: 1 << 5)
40 |
41 | public static let dockingEnable = GuiConfig(rawValue: 1 << 6)
42 | public static let viewportsEnable = GuiConfig(rawValue: 1 << 10)
43 | public static let dpiEnableScaleViewports = GuiConfig(rawValue: 1 << 14)
44 | public static let dpiEnableScaleFonts = GuiConfig(rawValue: 1 << 15)
45 |
46 | /// Application is SRGB-aware.
47 | public static let isSRGB = GuiConfig(rawValue: 1 << 20)
48 |
49 | /// Application is using a touch screen instead of a mouse.
50 | public static let isTouchScreen = GuiConfig(rawValue: 1 << 21)
51 | }
52 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiDirection.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// A cardinal direction.
12 | /// Represents: `ImGuiDir`.
13 | public enum GuiDirection: Int32 {
14 |
15 | case none = -1
16 | case left = 0
17 | case right = 1
18 | case up = 2
19 | case down = 3
20 | }
21 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiDockConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for dock configuration.
12 | /// Represents: `ImGuiDockNodeFlags`.
13 | public struct GuiDockConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiDockConfig([])
22 | public static let keepAliveOnly = GuiDockConfig(rawValue: 1 << 0)
23 | public static let noDockingInCentralNode = GuiDockConfig(rawValue: 1 << 2)
24 | public static let passthruCentralNode = GuiDockConfig(rawValue: 1 << 3)
25 | public static let noSplit = GuiDockConfig(rawValue: 1 << 4)
26 | public static let noResize = GuiDockConfig(rawValue: 1 << 5)
27 | public static let autoHideTabBar = GuiDockConfig(rawValue: 1 << 6)
28 | }
29 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiEdge.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// A screen edges.
12 | public enum GuiEdge {
13 |
14 | case all
15 | case top
16 | case leading
17 | case bottom
18 | case trailing
19 | }
20 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiInputTextConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with flags for text inputs.
12 | /// Represents: `ImGuiInputTextFlags`.
13 | public struct GuiInputTextConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiInputTextConfig([])
22 |
23 | /// Allow 0123456789.+-*/
24 | public static let charsDecimal = GuiInputTextConfig(rawValue: 1 << 0)
25 |
26 | /// Allow 0123456789ABCDEFabcdef
27 | public static let charsHexadecimal = GuiInputTextConfig(rawValue: 1 << 1)
28 |
29 | /// Turn a..z into A..Z
30 | public static let charsUppercase = GuiInputTextConfig(rawValue: 1 << 2)
31 |
32 | /// Filter out spaces, tabs
33 | public static let charsNoBlank = GuiInputTextConfig(rawValue: 1 << 3)
34 |
35 | /// Select entire text when first taking mouse focus
36 | public static let autoSelectAll = GuiInputTextConfig(rawValue: 1 << 4)
37 |
38 | /// Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function.
39 | public static let enterReturnsTrue = GuiInputTextConfig(rawValue: 1 << 5)
40 |
41 | /// Callback on pressing TAB (for completion handling)
42 | public static let callbackCompletion = GuiInputTextConfig(rawValue: 1 << 6)
43 |
44 | /// Callback on pressing Up/Down arrows (for history handling)
45 | public static let callbackHistory = GuiInputTextConfig(rawValue: 1 << 7)
46 |
47 | /// Callback on each iteration. User code may query cursor position, modify text buffer.
48 | public static let callbackAlways = GuiInputTextConfig(rawValue: 1 << 8)
49 |
50 | /// Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
51 | public static let callbackCharFilter = GuiInputTextConfig(rawValue: 1 << 9)
52 |
53 | /// Pressing TAB input a '\t' character into the text field
54 | public static let allowTabInput = GuiInputTextConfig(rawValue: 1 << 10)
55 |
56 | /// In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite: unfocus with Ctrl+Enter, add line with Enter).
57 | public static let ctrlEnterForNewLine = GuiInputTextConfig(rawValue: 1 << 11)
58 |
59 | /// Disable following the cursor horizontally
60 | public static let noHorizontalScroll = GuiInputTextConfig(rawValue: 1 << 12)
61 |
62 | /// Insert modes
63 | public static let alwaysInsertMode = GuiInputTextConfig(rawValue: 1 << 13)
64 |
65 | /// Read-only mode
66 | public static let readOnly = GuiInputTextConfig(rawValue: 1 << 14)
67 |
68 | /// Password mode, display all characters as '*'
69 | public static let password = GuiInputTextConfig(rawValue: 1 << 15)
70 |
71 | /// Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID().
72 | public static let noUndoRedo = GuiInputTextConfig(rawValue: 1 << 16)
73 |
74 | /// Allow 0123456789.+-*/eE (Scientific notation input)
75 | public static let charsScientific = GuiInputTextConfig(rawValue: 1 << 17)
76 |
77 | /// Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow.
78 | /// Notify when the string wants to be resized (for string types which hold a cache of their Size).
79 | /// You will be provided a new BufSize in the callback and NEED to honor it.
80 | public static let callbackResize = GuiInputTextConfig(rawValue: 1 << 18)
81 | }
82 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiSelectable.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with flags for selectables.
12 | /// Represents: `ImGuiSelectableFlags`.
13 | public struct GuiSelectable: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiSelectable([])
22 |
23 | /// Clicking this don't close parent popup window
24 | public static let dontClosePopups = GuiSelectable(rawValue: 1 << 0)
25 |
26 | /// Selectable frame can span all columns (text will still fit in current column)
27 | public static let spanAllColumns = GuiSelectable(rawValue: 1 << 1)
28 |
29 | /// Generate press events on double clicks too
30 | public static let allowDoubleClick = GuiSelectable(rawValue: 1 << 2)
31 |
32 | /// Cannot be selected, display greyed out text
33 | public static let disabled = GuiSelectable(rawValue: 1 << 3)
34 | public static let allowItemOverlap = GuiSelectable(rawValue: 1 << 4)
35 | }
36 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiStyleProperty.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// A variable identifier for styling.
12 | /// Represents: `ImGuiStyleVar`.
13 | public enum GuiStyleProperty: Int32 {
14 |
15 | /// Expected float
16 | case alpha
17 |
18 | /// Expected ImVec2
19 | case windowPadding
20 |
21 | /// Expected float
22 | case windowRounding
23 |
24 | /// Expected float
25 | case windowBorderSize
26 |
27 | /// Expected ImVec2
28 | case windowMinSize
29 |
30 | /// Expected ImVec2
31 | case windowTitleAlign
32 |
33 | /// Expected float
34 | case childRounding
35 |
36 | /// Expected float
37 | case childBorderSize
38 |
39 | /// Expected float
40 | case popupRounding
41 |
42 | /// Expected float
43 | case popupBorderSize
44 |
45 | /// Expected ImVec2
46 | case framePadding
47 |
48 | /// Expected float
49 | case frameRounding
50 |
51 | /// Expected float
52 | case frameBorderSize
53 |
54 | /// Expected ImVec2
55 | case itemSpacing
56 |
57 | /// Expected ImVec2
58 | case itemInnerSpacing
59 |
60 | /// Expected float
61 | case indentSpacing
62 |
63 | /// Expected float
64 | case scrollbarSize
65 |
66 | /// Expected float
67 | case scrollbarRounding
68 |
69 | /// Expected float
70 | case grabMinSize
71 |
72 | /// Expected float
73 | case grabRounding
74 |
75 | /// Expected float
76 | case tabRounding
77 |
78 | /// Expected ImVec2
79 | case buttonTextAlign
80 |
81 | /// Expected ImVec2
82 | case selectableTextAlign
83 | }
84 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiTabBarConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for tabbar configuration.
12 | /// Represents: `ImGuiTabBarFlags`.
13 | public struct GuiTabBarConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiTabBarConfig([])
22 | public static let reorderable = GuiTabBarConfig(rawValue: 1 << 0)
23 | public static let autoSelectNewTabs = GuiTabBarConfig(rawValue: 1 << 1)
24 | public static let tabListPopupButton = GuiTabBarConfig(rawValue: 1 << 2)
25 | public static let noCloseWithMiddleMouseButton = GuiTabBarConfig(rawValue: 1 << 3)
26 | public static let noTabListScrollingButtons = GuiTabBarConfig(rawValue: 1 << 4)
27 | public static let noTooltip = GuiTabBarConfig(rawValue: 1 << 5)
28 | public static let fittingPolicyResizeDown = GuiTabBarConfig(rawValue: 1 << 6)
29 | public static let fittingPolicyScroll = GuiTabBarConfig(rawValue: 1 << 7)
30 | public static let fittingPolicyMask = [fittingPolicyResizeDown, fittingPolicyResizeDown]
31 | public static let fittingPolicyDefault = fittingPolicyResizeDown
32 | }
33 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiTabItemConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for tab item configuration.
12 | /// Represents: `ImGuiTabItemFlags`.
13 | public struct GuiTabItemConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiTabItemConfig([])
22 | public static let unsavedDocument = GuiTabItemConfig(rawValue: 1 << 0)
23 | public static let setSelected = GuiTabItemConfig(rawValue: 1 << 1)
24 | public static let noCloseWithMiddleMouseButton = GuiTabItemConfig(rawValue: 1 << 2)
25 | public static let noPushId = GuiTabItemConfig(rawValue: 1 << 3)
26 | }
27 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiTreeConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for tree node configuration.
12 | /// Represents: `ImGuiTreeNodeFlags`.
13 | public struct GuiTreeConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiTreeConfig([])
22 |
23 | /// Draw as selected
24 | public static let selected = GuiTreeConfig(rawValue: 1 << 0)
25 |
26 | /// Full colored frame (e.g. for CollapsingHeader)
27 | public static let framed = GuiTreeConfig(rawValue: 1 << 1)
28 |
29 | /// Hit testing to allow subsequent widgets to overlap this one
30 | public static let allowItemOverlap = GuiTreeConfig(rawValue: 1 << 2)
31 |
32 | /// Don't do a TreePush() when open (e.g. for CollapsingHeader) = no extra indent nor pushing on ID stack
33 | public static let noTreePushOnOpen = GuiTreeConfig(rawValue: 1 << 3)
34 |
35 | /// Don't automatically and temporarily open node when Logging is active (by default logging will automatically open tree nodes)
36 | public static let noAutoOpenOnLog = GuiTreeConfig(rawValue: 1 << 4)
37 |
38 | /// Default node to be open
39 | public static let defaultOpen = GuiTreeConfig(rawValue: 1 << 5)
40 |
41 | /// Need double-click to open node
42 | public static let openOnDoubleClick = GuiTreeConfig(rawValue: 1 << 6)
43 |
44 | /// Only open when clicking on the arrow part. If public static let OpenOnDoubleClick is also set, single-click arrow or double-click all box to open.
45 | public static let openOnArrow = GuiTreeConfig(rawValue: 1 << 7)
46 |
47 | /// No collapsing, no arrow (use as a convenience for leaf nodes).
48 | public static let leaf = GuiTreeConfig(rawValue: 1 << 8)
49 |
50 | /// Display a bullet instead of arrow
51 | public static let bullet = GuiTreeConfig(rawValue: 1 << 9)
52 |
53 | /// Use FramePadding (even for an unframed text node) to vertically align text baseline to regular widget height.
54 | public static let framePadding = GuiTreeConfig(rawValue: 1 << 10)
55 |
56 | /// Extend hit box to the right-most edge, even if not framed. This is not the default in order to allow adding other items on the same line.
57 | /// In the future we may refactor the hit system to be front-to-back, allowing natural overlaps and then this can become the default.
58 | public static let spanAvailWidth = GuiTreeConfig(rawValue: 1 << 11)
59 |
60 | /// Extend hit box to the left-most and right-most edges (bypass the indented area).
61 | public static let spanFullWidth = GuiTreeConfig(rawValue: 1 << 12)
62 |
63 | /// (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop)
64 | public static let navLeftJumpsBackHere = GuiTreeConfig(rawValue: 1 << 13)
65 |
66 | public static let collapsingHeader = [framed, noTreePushOnOpen, noAutoOpenOnLog]
67 | }
68 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Attributes/GuiWindowConfig.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | /// OptionSet with properties for window configuration.
12 | /// Represents: `ImGuiWindowFlags`.
13 | public struct GuiWindowConfig: OptionSet {
14 |
15 | public let rawValue: Int32
16 |
17 | public init(rawValue: Int32) {
18 | self.rawValue = rawValue
19 | }
20 |
21 | public static let none = GuiWindowConfig([])
22 |
23 | /// Disable title-bar
24 | public static let noTitleBar = GuiWindowConfig(rawValue: 1 << 0)
25 |
26 | /// Disable user resizing with the lower-right grip
27 | public static let noResize = GuiWindowConfig(rawValue: 1 << 1)
28 |
29 | /// Disable user moving the window
30 | public static let noMove = GuiWindowConfig(rawValue: 1 << 2)
31 |
32 | /// Disable scrollbars (window can still scroll with mouse or programatically)
33 | public static let noScrollbar = GuiWindowConfig(rawValue: 1 << 3)
34 |
35 | /// Disable user vertically scrolling with mouse wheel
36 | public static let noScrollWithMouse = GuiWindowConfig(rawValue: 1 << 4)
37 |
38 | /// Disable user collapsing window by double-clicking on it
39 | public static let noCollapse = GuiWindowConfig(rawValue: 1 << 5)
40 |
41 | /// Resize every window to its content every frame
42 | public static let alwaysAutoResize = GuiWindowConfig(rawValue: 1 << 6)
43 |
44 | /// Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f).
45 | public static let noBackground = GuiWindowConfig(rawValue: 1 << 7)
46 |
47 | /// Never load/save settings in .ini file
48 | public static let noSavedSettings = GuiWindowConfig(rawValue: 1 << 8)
49 |
50 | /// Disable catching mouse or keyboard inputs
51 | public static let noMouseInputs = GuiWindowConfig(rawValue: 1 << 9)
52 |
53 | /// Has a menu-bar
54 | public static let menuBar = GuiWindowConfig(rawValue: 1 << 10)
55 |
56 | /// Allow horizontal scrollbar to appear (off by default). You may use SetNextWindowContentSize(ImVec2(width,0.0f));
57 | /// prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section.
58 | public static let horizontalScrollbar = GuiWindowConfig(rawValue: 1 << 11)
59 |
60 | /// Disable taking focus when transitioning from hidden to visible state
61 | public static let noFocusOnAppearing = GuiWindowConfig(rawValue: 1 << 12)
62 |
63 | /// Disable bringing window to front when taking focus (e.g. clicking on it or programatically giving it focus)
64 | public static let noBringToFrontOnFocus = GuiWindowConfig(rawValue: 1 << 13)
65 |
66 | /// Always show vertical scrollbar (even if ContentSize.y < Size.y)
67 | public static let alwaysVerticalScrollbar = GuiWindowConfig(rawValue: 1 << 14)
68 |
69 | /// Always show horizontal scrollbar (even if ContentSize.x < Size.x)
70 | public static let alwaysHorizontalScrollbar = GuiWindowConfig(rawValue: 1 << 15)
71 |
72 | /// Ensure child windows without border uses style.WindowPadding
73 | /// (ignored by default for non-bordered child windows, because more convenient)
74 | public static let alwaysUseWindowPadding = GuiWindowConfig(rawValue: 1 << 16)
75 |
76 | /// No gamepad/keyboard navigation within the window
77 | public static let noNavInputs = GuiWindowConfig(rawValue: 1 << 18)
78 |
79 | /// No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB)
80 | public static let noNavFocus = GuiWindowConfig(rawValue: 1 << 19)
81 |
82 | /// Append '*' to title without affecting the ID, as a convenience to avoid using the ### operator.
83 | /// When used in a tab/docking context, tab is selected on closure and closure is deferred by one
84 | /// frame to allow code to cancel the closure (with a confirmation popup, etc.) without flicker.
85 | public static let unsavedDocument = GuiWindowConfig(rawValue: 1 << 20)
86 |
87 | /// Disable docking of this window
88 | public static let noDocking = GuiWindowConfig(rawValue: 1 << 21)
89 | }
90 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Event/HoverEvent.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol HoverEvent: class {
12 |
13 | var onHover: (() -> GuiView?)? { get set }
14 |
15 | func onHover(_ callback: (() -> GuiView?)?) -> Self
16 | }
17 |
18 | public extension HoverEvent {
19 |
20 | func onHover(_ callback: (() -> GuiView?)?) -> Self {
21 | self.onHover = callback
22 | return self
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/ActiveColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol ActiveColorModifier: class {
12 |
13 | var activeColor: GuiColor? { get set }
14 |
15 | func activeColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension ActiveColorModifier {
19 |
20 | func activeColor(_ color: GuiColor) -> Self {
21 |
22 | self.activeColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/BackgroundColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol BackgroundColorModifier: class {
12 |
13 | var backgroundColor: GuiColor? { get set }
14 |
15 | func backgroundColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension BackgroundColorModifier {
19 |
20 | func backgroundColor(_ color: GuiColor) -> Self {
21 |
22 | self.backgroundColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/BorderColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol BorderColorModifier: class {
12 |
13 | var borderColor: GuiColor? { get set }
14 |
15 | func borderColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension BorderColorModifier {
19 |
20 | func borderColor(_ color: GuiColor) -> Self {
21 |
22 | self.borderColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/HoveredColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol HoveredColorModifier: class {
12 |
13 | var hoveredColor: GuiColor? { get set }
14 |
15 | func hoveredColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension HoveredColorModifier {
19 |
20 | func hoveredColor(_ color: GuiColor) -> Self {
21 |
22 | self.hoveredColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/SelectionColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol SelectionColorModifier: class {
12 |
13 | var selectionColor: GuiColor? { get set }
14 |
15 | func selectionColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension SelectionColorModifier {
19 |
20 | func selectionColor(_ color: GuiColor) -> Self {
21 |
22 | self.selectionColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/TextColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol TextColorModifier: class {
12 |
13 | var textColor: GuiColor? { get set }
14 |
15 | func textColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension TextColorModifier {
19 |
20 | func textColor(_ color: GuiColor) -> Self {
21 |
22 | self.textColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/Color/TintColorModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol TintColorModifier: class {
12 |
13 | var tintColor: GuiColor? { get set }
14 |
15 | func tintColor(_ color: GuiColor) -> Self
16 | }
17 |
18 | public extension TintColorModifier {
19 |
20 | func tintColor(_ color: GuiColor) -> Self {
21 |
22 | self.tintColor = color
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/FontModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol FontModifier: class {
12 |
13 | var fontIndex: Int? { get set }
14 |
15 | func font(_ index: Int) -> Self
16 | }
17 |
18 | public extension FontModifier {
19 |
20 | func font(_ index: Int) -> Self {
21 |
22 | self.fontIndex = index
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/PaddingModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol PaddingModifier: class {
12 |
13 | var padding: GuiEdge? { get set }
14 | var paddingValue: Double? { get set }
15 |
16 | func padding(_ edge: GuiEdge, value: Double) -> Self
17 | }
18 |
19 | public extension PaddingModifier {
20 |
21 | func padding(_ edge: GuiEdge = .all, value: Double) -> Self {
22 |
23 | self.padding = edge
24 | self.paddingValue = value
25 | return self
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/SizeModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol SizeModifier: class {
12 |
13 | var size: GuiSize? { get set }
14 |
15 | func size(_ size: GuiSize) -> Self
16 | }
17 |
18 | public extension SizeModifier {
19 |
20 | func size(_ size: GuiSize) -> Self {
21 |
22 | self.size = size
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/SnapModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SnapModifier.swift
3 | // SwiftGui
4 | //
5 | // Created by Erick Jung on 30/05/2020.
6 | // Copyright © 2020 Erick Jung. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol SnapModifier: class {
12 |
13 | var snapWidth: Bool? { get set }
14 |
15 | func snap() -> Self
16 | }
17 |
18 | public extension SnapModifier {
19 |
20 | func snap() -> Self {
21 |
22 | self.snapWidth = true
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/WindowPositionModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol WindowPositionModifier: class {
12 |
13 | var position: GuiPoint? { get set }
14 | var positionCondition: GuiCondition? { get set }
15 |
16 | func position(_ position: GuiPoint, condition: GuiCondition) -> Self
17 | }
18 |
19 | public extension WindowPositionModifier {
20 |
21 | func position(_ position: GuiPoint, condition: GuiCondition) -> Self {
22 |
23 | self.position = position
24 | self.positionCondition = condition
25 | return self
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Modifiers/WindowSizeModifier.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol WindowSizeModifier: class {
12 |
13 | var size: GuiSize? { get set }
14 | var sizeCondition: GuiCondition? { get set }
15 |
16 | func size(_ size: GuiSize, condition: GuiCondition) -> Self
17 | }
18 |
19 | public extension WindowSizeModifier {
20 |
21 | func size(_ size: GuiSize, condition: GuiCondition) -> Self {
22 |
23 | self.size = size
24 | self.sizeCondition = condition
25 | return self
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Values/IdentifierValue.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol IdentifierValue: class {
12 |
13 | var id: String? { get set }
14 |
15 | func identifier(_ value: String) -> Self
16 | }
17 |
18 | public extension IdentifierValue {
19 |
20 | func identifier(_ value: String) -> Self {
21 |
22 | self.id = value
23 | return self
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Button.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Button: GuiNode,
12 | SizeModifier,
13 | BackgroundColorModifier,
14 | BorderColorModifier,
15 | ActiveColorModifier,
16 | HoveredColorModifier {
17 |
18 | public enum ButtonType {
19 | /// sizeable button
20 | case `default`
21 |
22 | /// small fixed size
23 | case small
24 | }
25 |
26 | public var size: GuiSize?
27 | public var backgroundColor: GuiColor?
28 | public var borderColor: GuiColor?
29 | public var activeColor: GuiColor?
30 | public var hoveredColor: GuiColor?
31 |
32 | public var text: String
33 |
34 | public private(set) var type: ButtonType
35 | private let onTap: (() -> Void)?
36 |
37 | public init(_ text: String,
38 | type: ButtonType = .default,
39 | onTap: (() -> Void)? = nil) {
40 |
41 | self.text = text
42 | self.type = type
43 | self.onTap = onTap
44 | }
45 |
46 | public override func drawComponent() {
47 |
48 | if let color = self.backgroundColor {
49 | ImGuiWrapper.pushStyleColor(GuiColorProperty.button.rawValue, colorRef: color.cgColor)
50 | }
51 |
52 | if let color = self.borderColor {
53 | ImGuiWrapper.pushStyleColor(GuiColorProperty.border.rawValue, colorRef: color.cgColor)
54 | }
55 |
56 | if let color = self.activeColor {
57 | ImGuiWrapper.pushStyleColor(GuiColorProperty.buttonActive.rawValue, colorRef: color.cgColor)
58 | }
59 |
60 | if let color = self.hoveredColor {
61 | ImGuiWrapper.pushStyleColor(GuiColorProperty.buttonHovered.rawValue, colorRef: color.cgColor)
62 | }
63 |
64 | switch self.type {
65 |
66 | case .small:
67 |
68 | if ImGuiWrapper.smallButton(self.text) {
69 | onTap?()
70 | }
71 |
72 | case .default:
73 |
74 | if ImGuiWrapper.button(self.text, size: self.size ?? .zero) {
75 | onTap?()
76 | }
77 | }
78 |
79 | if self.backgroundColor != nil {
80 | ImGuiWrapper.popStyleColor(1)
81 | }
82 |
83 | if self.borderColor != nil {
84 | ImGuiWrapper.popStyleColor(1)
85 | }
86 |
87 | if self.activeColor != nil {
88 | ImGuiWrapper.popStyleColor(1)
89 | }
90 |
91 | if self.hoveredColor != nil {
92 | ImGuiWrapper.popStyleColor(1)
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/CheckBox.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class CheckBox: GuiNode,
12 | ActiveColorModifier {
13 |
14 | public var activeColor: GuiColor?
15 |
16 | public var text: String
17 | public var selectedState: Bool
18 |
19 | private let onChange: ((Bool) -> Void)?
20 |
21 | public init(_ text: String = "",
22 | selectedState: Bool,
23 | onChange: ((Bool) -> Void)? = nil) {
24 |
25 | self.text = text
26 | self.selectedState = selectedState
27 | self.onChange = onChange
28 | }
29 |
30 | public override func drawComponent() {
31 |
32 | if let color = self.activeColor {
33 | ImGuiWrapper.pushStyleColor(GuiColorProperty.checkMark.rawValue, colorRef: color.cgColor)
34 | }
35 |
36 | var _value = self.selectedState
37 |
38 | if ImGuiWrapper.checkbox(self.text, value: &_value) {
39 |
40 | if _value != self.selectedState {
41 |
42 | onChange?(_value)
43 | }
44 | }
45 |
46 | if self.activeColor != nil {
47 | ImGuiWrapper.popStyleColor(1)
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/ColorEdit.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class ColorEdit: GuiNode,
12 | BackgroundColorModifier,
13 | HoveredColorModifier {
14 |
15 | public var backgroundColor: GuiColor?
16 | public var hoveredColor: GuiColor?
17 | public var colorState: GuiColor
18 |
19 | private let onChange: ((GuiColor) -> Void)?
20 |
21 | public init(colorState: GuiColor,
22 | onChange: ((GuiColor) -> Void)? = nil) {
23 |
24 | self.colorState = colorState
25 | self.onChange = onChange
26 | }
27 |
28 | public override func drawComponent() {
29 |
30 | if let color = self.backgroundColor {
31 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
32 | ImGuiWrapper.pushStyleColor(GuiColorProperty.popupBg.rawValue, colorRef: color.cgColor)
33 | }
34 |
35 | if let color = self.hoveredColor {
36 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBgHovered.rawValue, colorRef: color.cgColor)
37 | }
38 |
39 | var _color = self.colorState.convertToFloats()
40 | if ImGuiWrapper.colorEdit3(self.id ?? "##coloredit", color: &_color, flags: 0) {
41 |
42 | if let onChange = onChange {
43 |
44 | onChange(GuiColor(r: _color[0], g: _color[1], b: _color[2], a: 1.0))
45 | }
46 | }
47 |
48 | if self.backgroundColor != nil {
49 | ImGuiWrapper.popStyleColor(2)
50 | }
51 |
52 | if self.hoveredColor != nil {
53 | ImGuiWrapper.popStyleColor(1)
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/ComboBox.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class ComboBox: GuiNode,
12 | BackgroundColorModifier,
13 | ActiveColorModifier,
14 | HoveredColorModifier,
15 | SelectionColorModifier {
16 |
17 | public var backgroundColor: GuiColor?
18 | public var activeColor: GuiColor?
19 | public var hoveredColor: GuiColor?
20 | public var selectionColor: GuiColor?
21 |
22 | public var text: String
23 | public var selectedIndexState: Int
24 | public var items: [String]
25 |
26 | private let onChange: ((Int) -> Void)?
27 |
28 | public init(_ text: String,
29 | selectedIndexState: Int,
30 | items: [String],
31 | onChange: ((Int) -> Void)? = nil) {
32 |
33 | self.text = text
34 | self.selectedIndexState = selectedIndexState
35 | self.items = items
36 | self.onChange = onChange
37 | }
38 |
39 | public override func drawComponent() {
40 |
41 | if let color = self.backgroundColor {
42 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
43 | ImGuiWrapper.pushStyleColor(GuiColorProperty.popupBg.rawValue, colorRef: color.cgColor)
44 | }
45 |
46 | if let color = self.hoveredColor {
47 | ImGuiWrapper.pushStyleColor(GuiColorProperty.buttonHovered.rawValue, colorRef: color.cgColor)
48 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerHovered.rawValue, colorRef: color.cgColor)
49 | }
50 |
51 | if let color = self.activeColor {
52 | ImGuiWrapper.pushStyleColor(GuiColorProperty.buttonActive.rawValue, colorRef: color.cgColor)
53 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerActive.rawValue, colorRef: color.cgColor)
54 | }
55 |
56 | if let color = self.selectionColor {
57 | ImGuiWrapper.pushStyleColor(GuiColorProperty.header.rawValue, colorRef: color.cgColor)
58 | }
59 |
60 | var _currentItem = Int32(self.selectedIndexState)
61 | if ImGuiWrapper.combo(self.text, currentItem: &_currentItem, items: items.map { $0 }, popupMaxHeightItems: -1) {
62 |
63 | if _currentItem != self.selectedIndexState {
64 |
65 | onChange?(Int(_currentItem))
66 | }
67 | }
68 |
69 | if self.backgroundColor != nil {
70 | ImGuiWrapper.popStyleColor(2)
71 | }
72 |
73 | if self.hoveredColor != nil {
74 | ImGuiWrapper.popStyleColor(2)
75 | }
76 |
77 | if self.activeColor != nil {
78 | ImGuiWrapper.popStyleColor(2)
79 | }
80 |
81 | if self.selectionColor != nil {
82 | ImGuiWrapper.popStyleColor(1)
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Drag.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Drag: GuiNode,
12 | BackgroundColorModifier,
13 | HoveredColorModifier {
14 |
15 | public var backgroundColor: GuiColor?
16 | public var hoveredColor: GuiColor?
17 |
18 | public var label: String
19 | public var valueState: Int
20 | public var speed: Float
21 | public var min: Int
22 | public var max: Int
23 | public var format: String
24 |
25 | private let onChange: ((Int) -> Void)?
26 |
27 | public init(label: String = "",
28 | valueState: Int,
29 | speed: Float = 1.0,
30 | min: Int = 0,
31 | max: Int = 0,
32 | format: String = "%d",
33 | onChange: ((Int) -> Void)? = nil) {
34 |
35 | self.label = label
36 | self.valueState = valueState
37 | self.speed = speed
38 | self.min = min
39 | self.max = max
40 | self.format = format
41 | self.onChange = onChange
42 | }
43 |
44 | public override func drawComponent() {
45 |
46 | if let color = self.backgroundColor {
47 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
48 | }
49 |
50 | if let color = self.hoveredColor {
51 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBgHovered.rawValue, colorRef: color.cgColor)
52 | }
53 |
54 | var _value = Int32(self.valueState)
55 | if ImGuiWrapper.dragInt(self.label,
56 | value: &_value,
57 | vSpeed: self.speed,
58 | vMin: Int32(self.min),
59 | vMax: Int32(self.max),
60 | format: self.format) {
61 |
62 | if _value != valueState {
63 |
64 | onChange?(Int(_value))
65 | }
66 | }
67 |
68 | if self.backgroundColor != nil {
69 | ImGuiWrapper.popStyleColor(1)
70 | }
71 |
72 | if self.hoveredColor != nil {
73 | ImGuiWrapper.popStyleColor(1)
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Image.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Image: GuiNode,
12 | SizeModifier,
13 | BorderColorModifier,
14 | TintColorModifier {
15 |
16 | public var size: GuiSize?
17 | public var borderColor: GuiColor?
18 | public var tintColor: GuiColor?
19 |
20 | public var imageId: GuiImage?
21 | public var uv0: GuiSize
22 | public var uv1: GuiSize
23 |
24 | public init(imageId: GuiImage?,
25 | uv0: GuiSize = .zero,
26 | uv1: GuiSize = GuiSize(width: 1, height: 1)) {
27 |
28 | self.imageId = imageId
29 | self.uv0 = uv0
30 | self.uv1 = uv1
31 | self.size = GuiSize(width: 50, height: 50)
32 | self.tintColor = .white
33 | self.borderColor = GuiColor(r: 0, g: 0, b: 0, a: 0)
34 | }
35 |
36 | public override func drawComponent() {
37 |
38 | if let imageId = self.imageId,
39 | let size = self.size,
40 | let tintColor = self.tintColor,
41 | let borderColor = self.borderColor {
42 |
43 | ImGuiWrapper.image(Unmanaged.passUnretained(imageId).toOpaque(),
44 | size: size,
45 | uv0: self.uv0,
46 | uv1: self.uv1,
47 | tintColor: tintColor.cgColor,
48 | borderColor: borderColor.cgColor)
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/ListBox.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class ListBox: GuiNode,
12 | BackgroundColorModifier,
13 | ActiveColorModifier,
14 | HoveredColorModifier,
15 | SelectionColorModifier {
16 |
17 | public var backgroundColor: GuiColor?
18 | public var activeColor: GuiColor?
19 | public var hoveredColor: GuiColor?
20 | public var selectionColor: GuiColor?
21 |
22 | public var label: String
23 | public var currentItemState: Int
24 |
25 | public private(set) var items: [String]
26 | private let onChange: ((Int) -> Void)?
27 |
28 | public init(label: String = "",
29 | currentItemState: Int,
30 | items: [String],
31 | onChange: ((Int) -> Void)? = nil) {
32 |
33 | self.label = label
34 | self.currentItemState = currentItemState
35 | self.items = items
36 | self.onChange = onChange
37 | }
38 |
39 | public override func drawComponent() {
40 |
41 | if let color = self.backgroundColor {
42 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
43 | }
44 |
45 | if let color = self.activeColor {
46 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerActive.rawValue, colorRef: color.cgColor)
47 | }
48 |
49 | if let color = self.hoveredColor {
50 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerHovered.rawValue, colorRef: color.cgColor)
51 | }
52 |
53 | if let color = self.selectionColor {
54 | ImGuiWrapper.pushStyleColor(GuiColorProperty.header.rawValue, colorRef: color.cgColor)
55 | }
56 |
57 | var _currentItem = Int32(self.currentItemState)
58 | if ImGuiWrapper.listBox(self.label, currentItem: &_currentItem, items: items, heightInItems: -1) {
59 |
60 | if _currentItem != self.currentItemState {
61 |
62 | onChange?(Int(_currentItem))
63 | }
64 | }
65 |
66 | if self.backgroundColor != nil {
67 | ImGuiWrapper.popStyleColor(1)
68 | }
69 |
70 | if self.activeColor != nil {
71 | ImGuiWrapper.popStyleColor(1)
72 | }
73 |
74 | if self.hoveredColor != nil {
75 | ImGuiWrapper.popStyleColor(1)
76 | }
77 |
78 | if self.selectionColor != nil {
79 | ImGuiWrapper.popStyleColor(1)
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Plot.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Plot: GuiNode,
12 | SizeModifier,
13 | BackgroundColorModifier,
14 | ActiveColorModifier,
15 | HoveredColorModifier {
16 |
17 | public enum PlotType {
18 | case line
19 | case histogram
20 | }
21 |
22 | public var size: GuiSize?
23 | public var backgroundColor: GuiColor?
24 | public var activeColor: GuiColor?
25 | public var hoveredColor: GuiColor?
26 |
27 | public var label: String
28 | public var values: [Float]
29 | public var valuesOffset: Int
30 | public var overlayText: String
31 | public var minScale: Float
32 | public var maxScale: Float
33 | public var stride: Int
34 |
35 | public private(set) var type: PlotType
36 |
37 | public init(type: PlotType,
38 | label: String,
39 | values: [Float],
40 | valuesOffset: Int = 0,
41 | overlayText: String = "",
42 | minScale: Float = Float.greatestFiniteMagnitude,
43 | maxScale: Float = Float.greatestFiniteMagnitude,
44 | stride: Int = MemoryLayout.size) {
45 |
46 | self.type = type
47 | self.label = label
48 | self.values = values
49 | self.valuesOffset = valuesOffset
50 | self.overlayText = overlayText
51 | self.minScale = minScale
52 | self.maxScale = maxScale
53 | self.stride = stride
54 | }
55 |
56 | public override func drawComponent() {
57 |
58 | if let color = self.backgroundColor {
59 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
60 | }
61 |
62 | if let color = self.activeColor {
63 | let keyColor = self.type == .line ? GuiColorProperty.plotLines.rawValue : GuiColorProperty.plotHistogram.rawValue
64 | ImGuiWrapper.pushStyleColor(keyColor, colorRef: color.cgColor)
65 | }
66 |
67 | if let color = self.hoveredColor {
68 | let keyColor = self.type == .line ? GuiColorProperty.plotLinesHovered.rawValue : GuiColorProperty.plotHistogramHovered.rawValue
69 | ImGuiWrapper.pushStyleColor(keyColor, colorRef: color.cgColor)
70 | }
71 |
72 | switch type {
73 |
74 | case .line:
75 |
76 | ImGuiWrapper.plotLines(self.label,
77 | values: self.values.map({ return $0 }),
78 | valueCount: Int32(self.values.count),
79 | valuesOffset: Int32(self.valuesOffset),
80 | overlayText: self.overlayText,
81 | minScale: self.minScale,
82 | maxScale: self.maxScale,
83 | graphSize: self.size ?? .zero,
84 | stride: Int32(self.stride))
85 |
86 | case .histogram:
87 |
88 | ImGuiWrapper.plotHistogram(self.label,
89 | values: self.values.map({ return $0 }),
90 | valueCount: Int32(self.values.count),
91 | valuesOffset: Int32(self.valuesOffset),
92 | overlayText: self.overlayText,
93 | minScale: self.minScale,
94 | maxScale: self.maxScale,
95 | graphSize: self.size ?? .zero,
96 | stride: Int32(self.stride))
97 | }
98 |
99 | if self.backgroundColor != nil {
100 | ImGuiWrapper.popStyleColor(1)
101 | }
102 |
103 | if self.activeColor != nil {
104 | ImGuiWrapper.popStyleColor(1)
105 | }
106 |
107 | if self.hoveredColor != nil {
108 | ImGuiWrapper.popStyleColor(1)
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/RadioButton/RadioButton.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class RadioButton: GuiNode,
12 | ActiveColorModifier {
13 |
14 | public var activeColor: GuiColor?
15 |
16 | public var text: String
17 | public var activeState: Bool
18 |
19 | private let onChange: (() -> Void)?
20 |
21 | public init(_ text: String = "",
22 | activeState: Bool,
23 | onChange: (() -> Void)? = nil) {
24 |
25 | self.text = text
26 | self.activeState = activeState
27 | self.onChange = onChange
28 | }
29 |
30 | public override func drawComponent() {
31 |
32 | if let color = self.activeColor {
33 | ImGuiWrapper.pushStyleColor(GuiColorProperty.checkMark.rawValue, colorRef: color.cgColor)
34 | }
35 |
36 | if ImGuiWrapper.radioButton(self.text, active: self.activeState) {
37 | self.onChange?()
38 | }
39 |
40 | if self.activeColor != nil {
41 | ImGuiWrapper.popStyleColor(1)
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/RadioButton/RadioButtonGroup.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class RadioButtonGroup: GuiNode,
12 | ActiveColorModifier {
13 |
14 | public var activeColor: GuiColor?
15 |
16 | public var values: [String]
17 | public var selectedIndexState: Int
18 |
19 | private let onChange: ((Int) -> Void)?
20 |
21 | public init(_ values: [String],
22 | selectedIndexState: Int,
23 | onChange: ((Int) -> Void)? = nil) {
24 |
25 | self.values = values
26 | self.selectedIndexState = selectedIndexState
27 | self.onChange = onChange
28 | }
29 |
30 | public override func drawComponent() {
31 |
32 | if let color = self.activeColor {
33 | ImGuiWrapper.pushStyleColor(GuiColorProperty.checkMark.rawValue, colorRef: color.cgColor)
34 | }
35 |
36 | for (index, element) in values.enumerated() {
37 |
38 | self.renderSequential(element, selectedIndexState: index, order: index)
39 | }
40 |
41 | if self.activeColor != nil {
42 | ImGuiWrapper.popStyleColor(1)
43 | }
44 | }
45 |
46 | private func renderSequential(_ text: String,
47 | selectedIndexState: Int,
48 | order: Int) {
49 |
50 | var _value = Int32(self.selectedIndexState)
51 | if ImGuiWrapper.radioButton(text, value: &_value, vButton: Int32(order)) {
52 |
53 | if _value != self.selectedIndexState {
54 |
55 | self.onChange?(Int(_value))
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Slider.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Slider: GuiNode,
12 | BackgroundColorModifier,
13 | ActiveColorModifier,
14 | HoveredColorModifier,
15 | SelectionColorModifier {
16 |
17 | public var backgroundColor: GuiColor?
18 | public var activeColor: GuiColor?
19 | public var hoveredColor: GuiColor?
20 | public var selectionColor: GuiColor?
21 |
22 | public var label: String
23 | public var valueState: Float
24 | public var min: Float
25 | public var max: Float
26 | public var format: String
27 |
28 | private let onChange: ((Float) -> Void)?
29 |
30 | public init(label: String = "",
31 | valueState: Float,
32 | min: Float,
33 | max: Float,
34 | format: String = "%.3f",
35 | onChange: ((Float) -> Void)? = nil) {
36 |
37 | self.label = label
38 | self.valueState = valueState
39 | self.min = min
40 | self.max = max
41 | self.format = format
42 | self.onChange = onChange
43 | }
44 |
45 | public override func drawComponent() {
46 |
47 | if let color = self.backgroundColor {
48 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
49 | }
50 |
51 | if let color = self.hoveredColor {
52 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBgHovered.rawValue, colorRef: color.cgColor)
53 | }
54 |
55 | if let color = self.activeColor {
56 | ImGuiWrapper.pushStyleColor(GuiColorProperty.sliderGrabActive.rawValue, colorRef: color.cgColor)
57 | }
58 |
59 | if let color = self.selectionColor {
60 | ImGuiWrapper.pushStyleColor(GuiColorProperty.sliderGrab.rawValue, colorRef: color.cgColor)
61 | }
62 |
63 | var _value = valueState
64 | if ImGuiWrapper.sliderFloat(self.label,
65 | value: &_value,
66 | min: self.min,
67 | max: self.max,
68 | format: self.format,
69 | power: 1.0) {
70 |
71 | if _value != valueState {
72 |
73 | onChange?(_value)
74 | }
75 | }
76 |
77 | if self.backgroundColor != nil {
78 | ImGuiWrapper.popStyleColor(1)
79 | }
80 |
81 | if self.hoveredColor != nil {
82 | ImGuiWrapper.popStyleColor(1)
83 | }
84 |
85 | if self.activeColor != nil {
86 | ImGuiWrapper.popStyleColor(1)
87 | }
88 |
89 | if self.selectionColor != nil {
90 | ImGuiWrapper.popStyleColor(1)
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/TabBar/TabBar.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class TabBar: GuiNode,
12 | BackgroundColorModifier,
13 | ActiveColorModifier,
14 | HoveredColorModifier {
15 |
16 | public var backgroundColor: GuiColor?
17 | public var activeColor: GuiColor?
18 | public var hoveredColor: GuiColor?
19 |
20 | public var options: GuiTabBarConfig
21 |
22 | private let child: GuiView
23 |
24 | public init(options: GuiTabBarConfig = .none,
25 | @GuiBuilder child: () -> GuiView) {
26 |
27 | self.options = options
28 | self.child = child()
29 | }
30 |
31 | public override func drawComponent() {
32 |
33 | if let color = self.backgroundColor {
34 | ImGuiWrapper.pushStyleColor(GuiColorProperty.tab.rawValue, colorRef: color.cgColor)
35 | }
36 |
37 | if let color = self.activeColor {
38 | ImGuiWrapper.pushStyleColor(GuiColorProperty.tabActive.rawValue, colorRef: color.cgColor)
39 | }
40 |
41 | if let color = self.hoveredColor {
42 | ImGuiWrapper.pushStyleColor(GuiColorProperty.tabHovered.rawValue, colorRef: color.cgColor)
43 | }
44 |
45 | if ImGuiWrapper.beginTabBar(self.id ?? "##tabbar", flags: self.options.rawValue) {
46 |
47 | self.child.render()
48 | ImGuiWrapper.endTabBar()
49 | }
50 |
51 | if self.backgroundColor != nil {
52 | ImGuiWrapper.popStyleColor(1)
53 | }
54 |
55 | if self.activeColor != nil {
56 | ImGuiWrapper.popStyleColor(1)
57 | }
58 |
59 | if self.hoveredColor != nil {
60 | ImGuiWrapper.popStyleColor(1)
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/TabBar/TabItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class TabItem: GuiNode,
12 | BackgroundColorModifier,
13 | ActiveColorModifier,
14 | HoveredColorModifier {
15 |
16 | public var backgroundColor: GuiColor?
17 | public var activeColor: GuiColor?
18 | public var hoveredColor: GuiColor?
19 |
20 | public var text: String
21 | public var options: GuiTabItemConfig
22 |
23 | private let child: GuiView
24 |
25 | public init(_ text: String,
26 | options: GuiTabItemConfig = .none,
27 | @GuiBuilder child: () -> GuiView) {
28 |
29 | self.text = text
30 | self.options = options
31 | self.child = child()
32 | }
33 |
34 | public override func drawComponent() {
35 |
36 | if let color = self.backgroundColor {
37 | ImGuiWrapper.pushStyleColor(GuiColorProperty.tab.rawValue, colorRef: color.cgColor)
38 | }
39 |
40 | if let color = self.activeColor {
41 | ImGuiWrapper.pushStyleColor(GuiColorProperty.tabActive.rawValue, colorRef: color.cgColor)
42 | }
43 |
44 | if let color = self.hoveredColor {
45 | ImGuiWrapper.pushStyleColor(GuiColorProperty.tabHovered.rawValue, colorRef: color.cgColor)
46 | }
47 |
48 | if ImGuiWrapper.beginTabItem(self.text, flags: self.options.rawValue) {
49 |
50 | self.child.render()
51 | ImGuiWrapper.endTabItem()
52 | }
53 |
54 | if self.backgroundColor != nil {
55 | ImGuiWrapper.popStyleColor(1)
56 | }
57 |
58 | if self.activeColor != nil {
59 | ImGuiWrapper.popStyleColor(1)
60 | }
61 |
62 | if self.hoveredColor != nil {
63 | ImGuiWrapper.popStyleColor(1)
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Text.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Text: GuiNode {
12 |
13 | public enum TextType {
14 | case `default`
15 | case wrapped
16 | case bullet
17 | }
18 |
19 | public var text: String
20 |
21 | public private(set) var type: TextType
22 |
23 | public init(_ text: String, type: TextType = .default) {
24 | self.text = text
25 | self.type = type
26 | }
27 |
28 | public override func drawComponent() {
29 |
30 | switch self.type {
31 |
32 | case .wrapped:
33 | ImGuiWrapper.textWrapped(self.text)
34 | case .bullet:
35 | ImGuiWrapper.bulletText(self.text)
36 | default:
37 | ImGuiWrapper.text(self.text)
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/TextEditor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class TextEditor: GuiNode {
12 |
13 | public var text: String
14 |
15 | private let onChange: ((String) -> Void)?
16 |
17 | public init(_ text: String,
18 | onChange: ((String) -> Void)? = nil) {
19 |
20 | self.text = text
21 | self.onChange = onChange
22 | }
23 |
24 | public override func drawComponent() {
25 |
26 | TextEditorWrapper.render(self.text)
27 |
28 | if let onChange = self.onChange,
29 | TextEditorWrapper.isTextChanged() {
30 |
31 | onChange(TextEditorWrapper.getText())
32 | }
33 | }
34 | }
35 |
36 | public extension TextEditor {
37 |
38 | static func setLanguage(_ type: TextEditorWrapperLanguage) {
39 |
40 | TextEditorWrapper.setLanguageDefinition(type)
41 | }
42 |
43 | static func getTotalLines() -> Int {
44 |
45 | Int(TextEditorWrapper.getTotalLines())
46 | }
47 |
48 | static func isOverwrite() -> Bool {
49 |
50 | TextEditorWrapper.isOverwrite()
51 | }
52 |
53 | static func setReadOnly(_ value: Bool) {
54 |
55 | TextEditorWrapper.setReadOnly(value)
56 | }
57 |
58 | static func isReadOnly() -> Bool {
59 |
60 | TextEditorWrapper.isReadOnly()
61 | }
62 |
63 | static func setShowWhitespaces(_ value: Bool) {
64 |
65 | TextEditorWrapper.setShowWhitespaces(value)
66 | }
67 |
68 | static func isShowingWhitespaces() -> Bool {
69 |
70 | TextEditorWrapper.isShowingWhitespaces()
71 | }
72 |
73 | static func setColorizerEnable(_ value: Bool) {
74 |
75 | TextEditorWrapper.setColorizerEnable(value)
76 | }
77 |
78 | static func isColorizerEnabled() -> Bool {
79 |
80 | TextEditorWrapper.isColorizerEnabled()
81 | }
82 |
83 | static func setTabSize(_ value: Int) {
84 |
85 | TextEditorWrapper.setTabSize(Int32(value))
86 | }
87 |
88 | static func getTabSize() -> Int {
89 |
90 | Int(TextEditorWrapper.getTabSize())
91 | }
92 |
93 | static func canUndo() -> Bool {
94 |
95 | TextEditorWrapper.canUndo()
96 | }
97 |
98 | static func undo() {
99 |
100 | TextEditorWrapper.undo()
101 | }
102 |
103 | static func canRedo() -> Bool {
104 |
105 | TextEditorWrapper.canRedo()
106 | }
107 |
108 | static func redo() {
109 |
110 | TextEditorWrapper.redo()
111 | }
112 |
113 | static func hasSelection() -> Bool {
114 |
115 | TextEditorWrapper.hasSelection()
116 | }
117 |
118 | static func copy() {
119 |
120 | TextEditorWrapper.copy()
121 | }
122 |
123 | static func cut() {
124 |
125 | TextEditorWrapper.cut()
126 | }
127 |
128 | static func remove() {
129 |
130 | TextEditorWrapper.remove()
131 | }
132 |
133 | static func paste() {
134 |
135 | TextEditorWrapper.paste()
136 | }
137 |
138 | static func selectAll() {
139 |
140 | TextEditorWrapper.selectAll()
141 | }
142 |
143 | static func setPallete(_ type: TextEditorWrapperPallete) {
144 |
145 | TextEditorWrapper.setPallete(type)
146 | }
147 |
148 | static func setText(_ text: String) {
149 |
150 | TextEditorWrapper.setText(text)
151 | }
152 |
153 | static func getText() -> String {
154 |
155 | TextEditorWrapper.getText()
156 | }
157 |
158 | static func insertText(_ text: String) {
159 |
160 | TextEditorWrapper.insertText(text)
161 | }
162 |
163 | static func clearErrorMarkers() {
164 |
165 | TextEditorWrapper.clearErrorMarkers()
166 | }
167 |
168 | static func insertErrorMarker(_ index: Int, _ text: String) {
169 |
170 | TextEditorWrapper.insertErrorMarker(Int32(index), text: text)
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/TextField.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class TextField: GuiNode,
12 | SizeModifier,
13 | BackgroundColorModifier {
14 |
15 | public enum TextFieldType {
16 | case `default`
17 | case multiline
18 | }
19 |
20 | public var size: GuiSize?
21 | public var backgroundColor: GuiColor?
22 |
23 | public var label: String
24 | public var textState: String
25 | public var placeHolder: String?
26 | public var maxLength: Int
27 | public var options: GuiInputTextConfig
28 |
29 | public private(set) var type: TextFieldType
30 | private let onChange: ((String) -> Void)?
31 |
32 | public init(type: TextFieldType = .default,
33 | label: String = "",
34 | textState: String,
35 | placeHolder: String? = nil,
36 | maxLength: Int = 2048,
37 | options: GuiInputTextConfig = .none,
38 | onChange: ((String) -> Void)? = nil) {
39 |
40 | self.label = label
41 | self.textState = textState
42 | self.placeHolder = placeHolder
43 | self.maxLength = maxLength
44 | self.options = options
45 | self.type = type
46 | self.onChange = onChange
47 | }
48 |
49 | public override func drawComponent() {
50 |
51 | if let color = self.backgroundColor {
52 | ImGuiWrapper.pushStyleColor(GuiColorProperty.frameBg.rawValue, colorRef: color.cgColor)
53 | }
54 |
55 | switch self.type {
56 |
57 | case .default:
58 | self.renderDefaultField()
59 |
60 | case .multiline:
61 | self.renderMultilineField()
62 |
63 | }
64 |
65 | if self.backgroundColor != nil {
66 | ImGuiWrapper.popStyleColor(1)
67 | }
68 | }
69 |
70 | private func renderDefaultField() {
71 |
72 | var _value = textState.cChars(with: self.maxLength)
73 |
74 | if let placeHolder = placeHolder {
75 |
76 | if ImGuiWrapper.inputText(withHint: self.label,
77 | hint: placeHolder,
78 | buffer: &_value,
79 | bufferSize: Int32(self.maxLength),
80 | flags: self.options.rawValue) {
81 |
82 | onChange?(String(cString: _value))
83 | }
84 |
85 | } else {
86 |
87 | if ImGuiWrapper.inputText(self.label,
88 | buffer: &_value,
89 | bufferSize: Int32(self.maxLength),
90 | flags: self.options.rawValue) {
91 |
92 | onChange?(String(cString: _value))
93 | }
94 | }
95 | }
96 |
97 | private func renderMultilineField() {
98 |
99 | var _value = self.textState.cChars(with: self.textState.count + self.maxLength)
100 | if ImGuiWrapper.inputTextMultiline(self.id ?? "##textfield",
101 | buffer: &_value,
102 | bufferSize: Int32(_value.count + self.maxLength),
103 | size: self.size ?? .zero,
104 | flags: self.options.rawValue) {
105 |
106 | onChange?(String(cString: _value))
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/TextLabel.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class TextLabel: GuiNode {
12 |
13 | public var label: String
14 | public var value: String
15 |
16 | public init(label: String, value: String) {
17 | self.label = label
18 | self.value = value
19 | }
20 |
21 | public override func drawComponent() {
22 |
23 | ImGuiWrapper.labelText(self.label, format: self.value)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Tree/CollapsingHeader.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class CollapsingHeader: GuiNode,
12 | BackgroundColorModifier,
13 | ActiveColorModifier,
14 | HoveredColorModifier {
15 |
16 | public var backgroundColor: GuiColor?
17 | public var activeColor: GuiColor?
18 | public var hoveredColor: GuiColor?
19 |
20 | public var text: String
21 | public var options: GuiTreeConfig
22 |
23 | private let child: GuiView
24 |
25 | public init(_ text: String,
26 | options: GuiTreeConfig = .none,
27 | @GuiBuilder child: () -> GuiView) {
28 |
29 | self.text = text
30 | self.options = options
31 | self.child = child()
32 | }
33 |
34 | public override func drawComponent() {
35 |
36 | if let color = self.backgroundColor {
37 | ImGuiWrapper.pushStyleColor(GuiColorProperty.header.rawValue, colorRef: color.cgColor)
38 | }
39 |
40 | if let color = self.activeColor {
41 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerActive.rawValue, colorRef: color.cgColor)
42 | }
43 |
44 | if let color = self.hoveredColor {
45 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerHovered.rawValue, colorRef: color.cgColor)
46 | }
47 |
48 | if ImGuiWrapper.collapsingHeader(self.text, flags: self.options.rawValue) {
49 |
50 | self.child.render()
51 | }
52 |
53 | if self.backgroundColor != nil {
54 | ImGuiWrapper.popStyleColor(1)
55 | }
56 |
57 | if self.activeColor != nil {
58 | ImGuiWrapper.popStyleColor(1)
59 | }
60 |
61 | if self.hoveredColor != nil {
62 | ImGuiWrapper.popStyleColor(1)
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Form/Tree/Tree.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Tree: GuiNode,
12 | ActiveColorModifier,
13 | HoveredColorModifier {
14 |
15 | public var activeColor: GuiColor?
16 | public var hoveredColor: GuiColor?
17 |
18 | public var text: String
19 | public var options: GuiTreeConfig
20 |
21 | private let child: GuiView
22 |
23 | public init(_ text: String,
24 | options: GuiTreeConfig = .none,
25 | @GuiBuilder child: () -> GuiView) {
26 |
27 | self.text = text
28 | self.options = options
29 | self.child = child()
30 | }
31 |
32 | public override func drawComponent() {
33 |
34 | if let color = self.activeColor {
35 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerActive.rawValue, colorRef: color.cgColor)
36 | }
37 |
38 | if let color = self.hoveredColor {
39 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerHovered.rawValue, colorRef: color.cgColor)
40 | }
41 |
42 | if ImGuiWrapper.treeNodeEx(self.text, flags: self.options.rawValue) {
43 |
44 | self.child.render()
45 | ImGuiWrapper.treePop()
46 | }
47 |
48 | if self.activeColor != nil {
49 | ImGuiWrapper.popStyleColor(1)
50 | }
51 |
52 | if self.hoveredColor != nil {
53 | ImGuiWrapper.popStyleColor(1)
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/Empty.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Empty: GuiView {
12 |
13 | public init() {}
14 | public func render() {}
15 | }
16 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/ForEach.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class ForEach: GuiView {
12 |
13 | private var data: T
14 | private var onLoop: (T.Element) -> GuiView?
15 |
16 | public init(_ data: T,
17 | onLoop: @escaping (T.Element) -> GuiView?) {
18 |
19 | self.data = data
20 | self.onLoop = onLoop
21 | }
22 |
23 | public func render() {
24 |
25 | data.forEach {
26 |
27 | onLoop($0)?.render()
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/Group.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Group: GuiNode {
12 |
13 | private let child: GuiView
14 |
15 | public init(@GuiBuilder child: () -> GuiView) {
16 |
17 | self.child = child()
18 | }
19 |
20 | public override func drawComponent() {
21 |
22 | child.render()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/Perform.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Perform: GuiView {
12 |
13 | private let onPerform: (() -> GuiView?)?
14 |
15 | public init(onPerform: (() -> GuiView?)? = nil) {
16 |
17 | self.onPerform = onPerform
18 | }
19 |
20 | public func render() {
21 |
22 | if let child = self.onPerform?() {
23 |
24 | child.render()
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/Popup.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Popup: GuiView, IdentifierValue {
12 |
13 | public enum PopupType {
14 | case `default`
15 | case modal
16 | }
17 |
18 | public var id: String?
19 | public var options: GuiWindowConfig
20 |
21 | public private(set) var type: PopupType
22 | private let child: GuiView
23 |
24 | public init(type: PopupType = .default,
25 | options: GuiWindowConfig = .none,
26 | @GuiBuilder child: () -> GuiView) {
27 |
28 | self.type = type
29 | self.options = options
30 | self.child = child()
31 | }
32 |
33 | public func render() {
34 |
35 | switch self.type {
36 |
37 | case .default:
38 | if ImGuiWrapper.beginPopup(self.id ?? "##popup", flags: self.options.rawValue) {
39 |
40 | self.child.render()
41 |
42 | ImGuiWrapper.endPopup()
43 | }
44 |
45 | case .modal:
46 | var _value = true
47 | if ImGuiWrapper.beginPopupModal(self.id ?? "##popup", open: &_value, flags: self.options.rawValue) {
48 |
49 | self.child.render()
50 |
51 | ImGuiWrapper.endPopup()
52 | }
53 | }
54 | }
55 | }
56 |
57 | public extension Popup {
58 |
59 | static func open(_ id: String = "##popup") {
60 |
61 | ImGuiWrapper.openPopup(id)
62 | }
63 |
64 | /// PopupCloseCall function.
65 | /// NOTE: This will close any popup opened
66 | static func close() {
67 |
68 | ImGuiWrapper.closeCurrentPopup()
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/SubWindow.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class SubWindow: GuiNode,
12 | SizeModifier {
13 |
14 | public var size: GuiSize?
15 |
16 | public var border: Bool
17 | public var options: GuiWindowConfig
18 |
19 | private let child: GuiView
20 |
21 | public init(border: Bool = false,
22 | options: GuiWindowConfig = .none,
23 | @GuiBuilder child: () -> GuiView) {
24 |
25 | self.border = border
26 | self.options = options
27 | self.child = child()
28 | }
29 |
30 | public override func drawComponent() {
31 |
32 | if ImGuiWrapper.beginChild(self.id ?? "##subwindow",
33 | size: self.size ?? .zero,
34 | border: self.border,
35 | flags: self.options.rawValue) {
36 |
37 | self.child.render()
38 | }
39 | ImGuiWrapper.endChild()
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/ToolTip.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Tooltip: GuiView {
12 |
13 | private let child: GuiView
14 |
15 | public init(@GuiBuilder child: () -> GuiView) {
16 |
17 | self.child = child()
18 | }
19 |
20 | public func render() {
21 |
22 | ImGuiWrapper.beginTooltip()
23 | self.child.render()
24 | ImGuiWrapper.endTooltip()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Generic/Window.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Window: GuiNode,
12 | WindowPositionModifier,
13 | WindowSizeModifier {
14 |
15 | public var position: GuiPoint?
16 | public var positionCondition: GuiCondition?
17 | public var size: GuiSize?
18 | public var sizeCondition: GuiCondition?
19 |
20 | public var text: String
21 | public var options: GuiWindowConfig
22 | private let child: GuiView
23 |
24 | public init(_ text: String = "",
25 | options: GuiWindowConfig = .none,
26 | @GuiBuilder child: () -> GuiView) {
27 |
28 | self.text = text
29 | self.options = options
30 | self.child = child()
31 | }
32 |
33 | public override func drawComponent() {
34 |
35 | if let position = self.position,
36 | let positionCondition = self.positionCondition {
37 |
38 | ImGuiWrapper.setNextWindowPos(position, cond: positionCondition.rawValue, pivot: GuiPoint.zero)
39 | }
40 |
41 | if let size = self.size,
42 | let sizeCondition = self.sizeCondition {
43 |
44 | ImGuiWrapper.setNextWindowSize(size, cond: sizeCondition.rawValue)
45 | }
46 |
47 | if ImGuiWrapper.begin(self.text, flags: self.options.rawValue) {
48 |
49 | self.child.render()
50 | }
51 | ImGuiWrapper.end()
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/Column/Column.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Column: GuiView, IdentifierValue {
12 |
13 | public var id: String?
14 | public var count: Int
15 | public var border: Bool
16 |
17 | public init(count: Int = 1,
18 | border: Bool = true) {
19 |
20 | self.count = count
21 | self.border = border
22 | }
23 |
24 | public func render() {
25 |
26 | ImGuiWrapper.columns(Int32(self.count), strId: self.id ?? "##column", border: self.border)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/Column/ColumnNext.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class ColumnNext: GuiView {
12 |
13 | public init() {}
14 |
15 | public func render() {
16 |
17 | ImGuiWrapper.nextColumn()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/Column/ColumnWidth.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class ColumnWidth: GuiView {
12 |
13 | public var index: Int
14 | public var width: Float
15 |
16 | public init(index: Int,
17 | width: Float) {
18 |
19 | self.index = index
20 | self.width = width
21 | }
22 |
23 | public func render() {
24 |
25 | ImGuiWrapper.setColumnWidth(Int32(self.index), width: self.width)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/Divider.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Divider: GuiView {
12 |
13 | public init() {}
14 |
15 | public func render() {
16 |
17 | ImGuiWrapper.separator()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/HStack.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class HStack: GuiView {
12 |
13 | public var spacing: Float
14 | private let child: GuiView
15 |
16 | public init(spacing: Float = -1.0,
17 | @GuiBuilder child: () -> GuiView) {
18 |
19 | self.spacing = spacing
20 | self.child = child()
21 | }
22 |
23 | public func render() {
24 |
25 | guard let multi = child as? GuiNodeList else {
26 |
27 | child.render()
28 | return
29 | }
30 |
31 | multi.children.forEach {
32 |
33 | ImGuiWrapper.beginGroup()
34 | $0.render()
35 | ImGuiWrapper.endGroup()
36 | ImGuiWrapper.sameLine(0.0, spacing: self.spacing)
37 | }
38 |
39 | ImGuiWrapper.newLine()
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/List.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class List: GuiNode, SizeModifier {
12 |
13 | public var size: GuiSize?
14 |
15 | public var itemHeight: Float
16 | public var border: Bool
17 | public var options: GuiWindowConfig
18 |
19 | public private(set) var buffer: [T]
20 | private let onLoop: ((Int, T) -> GuiView?)
21 |
22 | public init(buffer: [T],
23 | itemHeight: Float = -1,
24 | border: Bool = false,
25 | options: GuiWindowConfig = .none,
26 | onLoop: @escaping ((Int, T) -> GuiView?)) {
27 |
28 | self.buffer = buffer
29 | self.itemHeight = itemHeight
30 | self.border = border
31 | self.options = options
32 | self.onLoop = onLoop
33 | }
34 |
35 | public override func drawComponent() {
36 |
37 | if ImGuiWrapper.beginChild(self.id ?? "##list", size: self.size ?? .zero, border: self.border, flags: self.options.rawValue) {
38 |
39 | if let clipper = ImGuiWrapper.listClipperCreate(0, itemsHeight: self.itemHeight) {
40 |
41 | ImGuiWrapper.listClipperBegin(clipper, itemsCount: Int32(self.buffer.count), itemsHeight: self.itemHeight)
42 |
43 | ImGuiWrapper.listClipperLoop(clipper) { index in
44 |
45 | self.onLoop(Int(index), self.buffer[Int(index)])?.render()
46 | }
47 |
48 | ImGuiWrapper.listClipperEnd(clipper)
49 |
50 | ImGuiWrapper.listClipperDestroy(clipper)
51 | }
52 | }
53 |
54 | ImGuiWrapper.endChild()
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/NewLine.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class NewLine: GuiView {
12 |
13 | public init() {}
14 |
15 | public func render() {
16 |
17 | ImGuiWrapper.newLine()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/SameLine.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class SameLine: GuiView {
12 |
13 | public var offsetX: GuiPoint
14 | public var spacing: Float
15 |
16 | public init(offsetX: GuiPoint = .zero,
17 | spacing: Float = -1.0) {
18 |
19 | self.offsetX = offsetX
20 | self.spacing = spacing
21 | }
22 |
23 | public func render() {
24 |
25 | ImGuiWrapper.sameLine(Float(self.offsetX.x), spacing: self.spacing)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Layout/Spacing.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class Spacing: GuiView {
12 |
13 | public init() {}
14 |
15 | public func render() {
16 |
17 | ImGuiWrapper.spacing()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Menu/MenuBar.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class MenuBar: GuiNode,
12 | BackgroundColorModifier,
13 | HoveredColorModifier {
14 |
15 | public var backgroundColor: GuiColor?
16 | public var hoveredColor: GuiColor?
17 |
18 | private let child: GuiView
19 |
20 | public init(@GuiBuilder child: () -> GuiView) {
21 |
22 | self.child = child()
23 | }
24 |
25 | public override func drawComponent() {
26 |
27 | if let color = self.backgroundColor {
28 | ImGuiWrapper.pushStyleColor(GuiColorProperty.menuBarBg.rawValue, colorRef: color.cgColor)
29 | }
30 |
31 | if let color = self.hoveredColor {
32 | ImGuiWrapper.pushStyleColor(GuiColorProperty.headerHovered.rawValue, colorRef: color.cgColor)
33 | }
34 |
35 | if ImGuiWrapper.beginMenuBar() {
36 |
37 | child.render()
38 | ImGuiWrapper.endMenuBar()
39 | }
40 |
41 | if self.backgroundColor != nil {
42 | ImGuiWrapper.popStyleColor(1)
43 | }
44 |
45 | if self.hoveredColor != nil {
46 | ImGuiWrapper.popStyleColor(1)
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Menu/MenuGroup.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class MenuGroup: GuiNode, BackgroundColorModifier {
12 |
13 | public var backgroundColor: GuiColor?
14 |
15 | public var text: String
16 | public var enabled: Bool
17 |
18 | private let child: GuiView
19 |
20 | public init(_ text: String,
21 | enabled: Bool = true,
22 | @GuiBuilder child: () -> GuiView) {
23 |
24 | self.text = text
25 | self.enabled = enabled
26 | self.child = child()
27 | }
28 |
29 | public override func drawComponent() {
30 |
31 | if let color = self.backgroundColor {
32 | ImGuiWrapper.pushStyleColor(GuiColorProperty.popupBg.rawValue, colorRef: color.cgColor)
33 | }
34 |
35 | if ImGuiWrapper.beginMenu(self.text, enabled: self.enabled) {
36 |
37 | child.render()
38 | ImGuiWrapper.endMenu()
39 | }
40 |
41 | if self.backgroundColor != nil {
42 | ImGuiWrapper.popStyleColor(1)
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Components/Views/Menu/MenuItem.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class MenuItem: GuiNode {
12 |
13 | public var text: String
14 | public var shortcut: String?
15 | public var selected: Bool
16 | public var enabled: Bool
17 |
18 | private let onTap: (() -> Void)?
19 |
20 | public init(_ text: String,
21 | shortcut: String? = nil,
22 | selected: Bool = false,
23 | enabled: Bool = true,
24 | onTap: (() -> Void)? = nil) {
25 |
26 | self.text = text
27 | self.shortcut = shortcut
28 | self.selected = selected
29 | self.enabled = enabled
30 | self.onTap = onTap
31 | }
32 |
33 | public override func drawComponent() {
34 |
35 | if ImGuiWrapper.menuItem(self.text, shortcut: self.shortcut, selected: self.selected, enabled: self.enabled) {
36 | onTap?()
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/GuiRenderer.h:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | @protocol GuiRendererDelegate
4 |
5 | - (void)setup;
6 | - (void)draw;
7 |
8 | @end
9 |
10 | @interface GuiRenderer : NSObject
11 |
12 | @property (nonatomic, weak, nullable) id delegate;
13 |
14 | -(nonnull instancetype)initWithView:(nonnull MTKView *)view;
15 |
16 | -(void)initializePlatform;
17 | -(void)shutdownPlatform;
18 |
19 | #if TARGET_OS_OSX
20 | -(bool)handleEvent:(NSEvent *_Nonnull)event view:(NSView *_Nullable)view;
21 | #else
22 | -(void)handleEvent:(UIEvent *_Nullable)event view:(UIView *_Nullable)view;
23 | #endif
24 |
25 | -(id_Nullable)loadTextureWithURL:(NSURL *_Nonnull)url;
26 | -(id_Nullable)loadTextureWithName:(NSString *_Nonnull)name;
27 |
28 | @end
29 |
30 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/GuiRenderer.mm:
--------------------------------------------------------------------------------
1 | #import "GuiRenderer.h"
2 | #import
3 |
4 | #include "imgui.h"
5 | #include "imgui_impl_metal.h"
6 |
7 | #if TARGET_OS_OSX
8 | #include "imgui_impl_osx.h"
9 | #endif
10 |
11 | @interface GuiRenderer ()
12 | @property (nonatomic, strong) id device;
13 | @property (nonatomic, strong) id commandQueue;
14 | @property (nonatomic, strong) MTKTextureLoader *loader;
15 | @end
16 |
17 |
18 | @implementation GuiRenderer
19 |
20 | -(nonnull instancetype)initWithView:(nonnull MTKView *)view;
21 | {
22 | self = [super init];
23 | if(self)
24 | {
25 | _device = view.device;
26 | _commandQueue = [_device newCommandQueue];
27 | _loader = [[MTKTextureLoader alloc] initWithDevice: _device];
28 |
29 | IMGUI_CHECKVERSION();
30 | ImGui::CreateContext();
31 | ImGui::StyleColorsDark();
32 |
33 | }
34 |
35 | return self;
36 | }
37 |
38 | - (void)drawInMTKView:(MTKView *)view
39 | {
40 | ImGuiIO &io = ImGui::GetIO();
41 | io.DisplaySize.x = view.bounds.size.width;
42 | io.DisplaySize.y = view.bounds.size.height;
43 |
44 | #if TARGET_OS_OSX
45 | CGFloat framebufferScale = view.window.screen.backingScaleFactor ?: NSScreen.mainScreen.backingScaleFactor;
46 | #else
47 | CGFloat framebufferScale = view.window.screen.scale ?: UIScreen.mainScreen.scale;
48 | #endif
49 | io.DisplayFramebufferScale = ImVec2(framebufferScale, framebufferScale);
50 |
51 | id commandBuffer = [self.commandQueue commandBuffer];
52 |
53 | static float clear_color[4] = { 0.5, 0.5, 0.5, 1.0f };
54 |
55 | MTLRenderPassDescriptor *renderPassDescriptor = view.currentRenderPassDescriptor;
56 | if (renderPassDescriptor != nil)
57 | {
58 | renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(clear_color[0], clear_color[1], clear_color[2], clear_color[3]);
59 |
60 | // Here, you could do additional rendering work, including other passes as necessary.
61 |
62 | id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
63 | [renderEncoder pushDebugGroup:@"SwiftGUI"];
64 |
65 | // Start the Dear ImGui frame
66 | ImGui_ImplMetal_NewFrame(renderPassDescriptor);
67 | #if TARGET_OS_OSX
68 | ImGui_ImplOSX_NewFrame(view);
69 | #endif
70 | ImGui::NewFrame();
71 |
72 | if (self.delegate && [self.delegate respondsToSelector:@selector(draw)]) {
73 |
74 | [self.delegate draw];
75 | }
76 |
77 | // Rendering
78 | ImGui::Render();
79 | ImDrawData *drawData = ImGui::GetDrawData();
80 | ImGui_ImplMetal_RenderDrawData(drawData, commandBuffer, renderEncoder);
81 |
82 | [renderEncoder popDebugGroup];
83 | [renderEncoder endEncoding];
84 |
85 | [commandBuffer presentDrawable:view.currentDrawable];
86 | }
87 |
88 | [commandBuffer commit];
89 | }
90 |
91 | - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
92 | }
93 |
94 | -(void)initializePlatform {
95 |
96 | if (self.delegate && [self.delegate respondsToSelector:@selector(setup)]) {
97 |
98 | [self.delegate setup];
99 | }
100 |
101 | ImGui_ImplMetal_Init(_device);
102 |
103 | #if TARGET_OS_OSX
104 | ImGui_ImplOSX_Init();
105 | #endif
106 | }
107 |
108 | -(void)shutdownPlatform {
109 |
110 | #if TARGET_OS_OSX
111 | ImGui_ImplOSX_Shutdown();
112 | #endif
113 | }
114 |
115 | #if TARGET_OS_OSX
116 |
117 | -(bool)handleEvent:(NSEvent *_Nonnull)event view:(NSView *_Nullable)view {
118 |
119 | return ImGui_ImplOSX_HandleEvent(event, view);
120 | }
121 |
122 | #else
123 |
124 | -(void)handleEvent:(UIEvent *_Nullable)event view:(UIView *_Nullable)view {
125 |
126 | UITouch *anyTouch = event.allTouches.anyObject;
127 | CGPoint touchLocation = [anyTouch locationInView:view];
128 | ImGuiIO &io = ImGui::GetIO();
129 | io.MousePos = ImVec2(touchLocation.x, touchLocation.y);
130 |
131 | BOOL hasActiveTouch = NO;
132 | for (UITouch *touch in event.allTouches) {
133 | if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled) {
134 | hasActiveTouch = YES;
135 | break;
136 | }
137 | }
138 | io.MouseDown[0] = hasActiveTouch;
139 | }
140 | #endif
141 |
142 | -(id)loadTextureWithURL:(NSURL *)url {
143 |
144 | id texture = [self.loader newTextureWithContentsOfURL:url options:nil error:nil];
145 |
146 | if(!texture)
147 | {
148 | NSLog(@"Failed to create the texture from %@", url.absoluteString);
149 | return nil;
150 | }
151 | return texture;
152 | }
153 |
154 | -(id)loadTextureWithName:(NSString *)name {
155 |
156 | id texture = [self.loader newTextureWithName:name scaleFactor:1.0 bundle:nil options:nil error:nil];
157 |
158 | if(!texture)
159 | {
160 | NSLog(@"Failed to create the texture from %@", name);
161 | return nil;
162 | }
163 | return texture;
164 | }
165 |
166 | @end
167 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/ImGuiStyleWrapper.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | NS_ASSUME_NONNULL_BEGIN
13 |
14 | @interface ImGuiStyleWrapper : NSObject
15 |
16 | + (void)alpha:(float)alpha;
17 | + (void)windowPadding:(CGPoint)padding;
18 | + (void)windowRounding:(float)rouding;
19 | + (void)windowBorderSize:(float)borderSize;
20 | + (void)windowMinSize:(CGSize)minSize;
21 | + (void)windowTitleAlign:(CGPoint)titleAlign;
22 | + (void)windowMenuButtonPosition:(int)position;
23 | + (void)childRounding:(float)childRounding;
24 | + (void)childBorderSize:(float)childBorderSize;
25 | + (void)popupRounding:(float)popupRounding;
26 | + (void)popupBorderSize:(float)popupBorderSize;
27 | + (void)framePadding:(CGPoint)framePadding;
28 | + (void)frameRounding:(float)frameRounding;
29 | + (void)frameBorderSize:(float)frameBorderSize;
30 | + (void)itemSpacing:(CGPoint)itemSpacing;
31 | + (void)itemInnerSpacing:(CGPoint)itemInnerSpacing;
32 | + (void)touchExtraPadding:(CGPoint)touchExtraPadding;
33 | + (void)indentSpacing:(float)indentSpacing;
34 | + (void)columnsMinSpacing:(float)columnsMinSpacing;
35 | + (void)scrollbarSize:(float)scrollbarSize;
36 | + (void)scrollbarRounding:(float)scrollbarRounding;
37 | + (void)grabMinSize:(float)grabMinSize;
38 | + (void)grabRounding:(float)grabRounding;
39 | + (void)tabRounding:(float)tabRounding;
40 | + (void)tabBorderSize:(float)tabBorderSize;
41 | + (void)colorButtonPosition:(int)colorButtonPosition;
42 | + (void)buttonTextAlign:(CGPoint)buttonTextAlign;
43 | + (void)selectableTextAlign:(CGPoint)selectableTextAlign;
44 | + (void)displayWindowPadding:(CGPoint)displayWindowPadding;
45 | + (void)displaySafeAreaPadding:(CGPoint)displaySafeAreaPadding;
46 | + (void)mouseCursorScale:(float)mouseCursorScale;
47 | + (void)antiAliasedLines:(bool)antiAliasedLines;
48 | + (void)antiAliasedFill:(bool)antiAliasedFill;
49 | + (void)curveTessellationTol:(float)curveTessellationTol;
50 |
51 | + (void)colorText:(CGColorRef _Nonnull)color;
52 | + (void)colorTextDisabled:(CGColorRef _Nonnull)color;
53 | + (void)colorWindowBg:(CGColorRef _Nonnull)color;
54 | + (void)colorChildBg:(CGColorRef _Nonnull)color;
55 | + (void)colorPopupBg:(CGColorRef _Nonnull)color;
56 | + (void)colorBorder:(CGColorRef _Nonnull)color;
57 | + (void)colorBorderShadow:(CGColorRef _Nonnull)color;
58 | + (void)colorFrameBg:(CGColorRef _Nonnull)color;
59 | + (void)colorFrameBgHovered:(CGColorRef _Nonnull)color;
60 | + (void)colorFrameBgActive:(CGColorRef _Nonnull)color;
61 | + (void)colorTitleBg:(CGColorRef _Nonnull)color;
62 | + (void)colorTitleBgActive:(CGColorRef _Nonnull)color;
63 | + (void)colorTitleBgCollapsed:(CGColorRef _Nonnull)color;
64 | + (void)colorMenuBarBg:(CGColorRef _Nonnull)color;
65 | + (void)colorScrollbarBg:(CGColorRef _Nonnull)color;
66 | + (void)colorScrollbarGrab:(CGColorRef _Nonnull)color;
67 | + (void)colorScrollbarGrabHovered:(CGColorRef _Nonnull)color;
68 | + (void)colorScrollbarGrabActive:(CGColorRef _Nonnull)color;
69 | + (void)colorCheckMark:(CGColorRef _Nonnull)color;
70 | + (void)colorSliderGrab:(CGColorRef _Nonnull)color;
71 | + (void)colorSliderGrabActive:(CGColorRef _Nonnull)color;
72 | + (void)colorButton:(CGColorRef _Nonnull)color;
73 | + (void)colorButtonHovered:(CGColorRef _Nonnull)color;
74 | + (void)colorButtonActive:(CGColorRef _Nonnull)color;
75 | + (void)colorHeader:(CGColorRef _Nonnull)color;
76 | + (void)colorHeaderHovered:(CGColorRef _Nonnull)color;
77 | + (void)colorHeaderActive:(CGColorRef _Nonnull)color;
78 | + (void)colorSeparator:(CGColorRef _Nonnull)color;
79 | + (void)colorSeparatorHovered:(CGColorRef _Nonnull)color;
80 | + (void)colorSeparatorActive:(CGColorRef _Nonnull)color;
81 | + (void)colorResizeGrip:(CGColorRef _Nonnull)color;
82 | + (void)colorResizeGripHovered:(CGColorRef _Nonnull)color;
83 | + (void)colorResizeGripActive:(CGColorRef _Nonnull)color;
84 | + (void)colorTab:(CGColorRef _Nonnull)color;
85 | + (void)colorTabHovered:(CGColorRef _Nonnull)color;
86 | + (void)colorTabActive:(CGColorRef _Nonnull)color;
87 | + (void)colorTabUnfocused:(CGColorRef _Nonnull)color;
88 | + (void)colorTabUnfocusedActive:(CGColorRef _Nonnull)color;
89 | + (void)colorDockingPreview:(CGColorRef _Nonnull)color;
90 | + (void)colorDockingEmptyBg:(CGColorRef _Nonnull)color;
91 | + (void)colorPlotLines:(CGColorRef _Nonnull)color;
92 | + (void)colorPlotLinesHovered:(CGColorRef _Nonnull)color;
93 | + (void)colorPlotHistogram:(CGColorRef _Nonnull)color;
94 | + (void)colorPlotHistogramHovered:(CGColorRef _Nonnull)color;
95 | + (void)colorTextSelectedBg:(CGColorRef _Nonnull)color;
96 | + (void)colorDragDropTarget:(CGColorRef _Nonnull)color;
97 | + (void)colorNavHighlight:(CGColorRef _Nonnull)color;
98 | + (void)colorNavWindowingHighlight:(CGColorRef _Nonnull)color;
99 | + (void)colorNavWindowingDimBg:(CGColorRef _Nonnull)color;
100 | + (void)colorModalWindowDimBg:(CGColorRef _Nonnull)color;
101 |
102 | @end
103 |
104 | NS_ASSUME_NONNULL_END
105 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/ImGuiWrapper.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | NS_ASSUME_NONNULL_BEGIN
13 |
14 | @interface ImGuiWrapper : NSObject
15 |
16 | + (bool)button:(NSString *)label size:(CGSize)size;
17 | + (bool)smallButton:(NSString *_Nonnull)label;
18 | + (bool)arrowButton:(NSString *_Nonnull)strId dir:(int)dir;
19 | + (void)bullet;
20 | + (bool)checkbox:(NSString *_Nonnull)label value:(bool *_Nonnull)value;
21 | + (bool)radioButton:(NSString *_Nonnull)label active:(bool)active;
22 | + (bool)radioButton:(NSString *_Nonnull)label value:(int *_Nonnull)value vButton:(int)vButton;
23 | + (void)progressBar:(float)fraction size:(CGSize)size overlay:(NSString *_Nullable)overlay;
24 | + (bool)dragInt:(NSString *_Nonnull)label value:(int *_Nonnull)value vSpeed:(float)vSpeed vMin:(int)vMin vMax:(int)vMax format:(NSString *_Nonnull)format;
25 | + (bool)sliderFloat:(NSString *_Nonnull)label value:(float *_Nonnull)value min:(float)min max:(float)max format:(NSString *_Nullable)format power:(float)power;
26 | + (void)image:(void *_Nonnull)textureId size:(CGSize)size uv0:(CGSize)uv0 uv1:(CGSize)uv1 tintColor:(CGColorRef _Nonnull)tintColor borderColor:(CGColorRef _Nonnull)borderColor;
27 | + (void)pushButtonRepeat:(bool)repeat;
28 | + (void)popButtonRepeat;
29 | + (bool)isItemHovered;
30 | + (bool)beginMenuBar;
31 | + (void)endMenuBar;
32 | + (bool)beginMenu:(NSString *_Nonnull)label enabled:(bool)enabled;
33 | + (void)endMenu;
34 | + (bool)menuItem:(NSString *_Nonnull)label shortcut:(NSString *_Nullable)shortcut selected:(bool)selected enabled:(bool)enabled;
35 | + (void)beginTooltip;
36 | + (void)endTooltip;
37 | + (void)pushID:(NSString *_Nonnull)labelId;
38 | + (void)popID;
39 | + (bool)inputText:(NSString *_Nonnull)label buffer:(char *_Nonnull)buffer bufferSize:(int)bufferSize flags:(int)flags;
40 | + (bool)inputTextWithHint:(NSString *_Nonnull)label hint:(NSString *_Nonnull)hint buffer:(char *_Nonnull)buffer bufferSize:(int)bufferSize flags:(int)flags;
41 | + (bool)inputFloat:(NSString *_Nonnull)label v:(float *_Nonnull)v step:(float)step stepFast:(float)stepFast format:(NSString *_Nonnull)format flags:(int)flags;
42 | + (bool)inputInt:(NSString *_Nonnull)label v:(int *_Nonnull)v step:(int)step stepFast:(int)stepFast flags:(int)flags;
43 | + (bool)inputTextMultiline:(NSString *_Nonnull)label buffer:(char *_Nonnull)buffer bufferSize:(int)bufferSize size:(CGSize)size flags:(int)flags;
44 | + (bool)listBox:(NSString *_Nonnull)label currentItem:(int *_Nonnull)currentItem items:(NSArray *_Nonnull)items heightInItems:(int)heightInItems;
45 | + (bool)colorEdit3:(NSString *_Nonnull)label color:(float *_Nonnull)color flags:(int)flags;
46 | + (bool)combo:(NSString *_Nonnull)label currentItem:(int *_Nonnull)currentItem items:(NSArray *_Nonnull)item popupMaxHeightItems:(int)popupMaxHeightItems;
47 | + (void)separator;
48 | + (void)sameLine:(float)offset_from_start_x spacing:(float)spacing;
49 | + (void)newLine;
50 | + (void)spacing;
51 | + (void)indent:(float)indent_w;
52 | + (void)unindent:(float)indent_w;
53 | + (void)beginGroup;
54 | + (void)endGroup;
55 | + (void)dummy:(CGSize)size;
56 | + (void)text:(NSString *)text;
57 | + (void)textDisabled:(NSString *_Nonnull)text;
58 | + (void)textWrapped:(NSString *_Nonnull)text;
59 | + (void)labelText:(NSString *_Nonnull)label format:(NSString *_Nonnull)format;
60 | + (void)bulletText:(NSString *_Nonnull)text;
61 | + (bool)treeNodeEx:(NSString *_Nonnull)label flags:(int)flags;
62 | + (void)treePop;
63 | + (bool)collapsingHeader:(NSString *_Nonnull)label flags:(int)flags;
64 | + (bool)collapsingHeader:(NSString *_Nonnull)label open:(bool *_Nonnull)open flags:(int)flags;
65 | + (bool)beginPopup:(NSString *)strId flags:(int)flags;
66 | + (bool)beginPopupModal:(NSString *)strId open:(bool *_Nonnull)open flags:(int)flags;
67 | + (void)endPopup;
68 | + (void)openPopup:(NSString *)strId;
69 | + (void)closeCurrentPopup;
70 | + (bool)beginTabBar:(NSString *)strId flags:(int)flags;
71 | + (void)endTabBar;
72 | + (bool)beginTabItem:(NSString *_Nonnull)label flags:(int)flags;
73 | + (void)endTabItem;
74 | + (void)plotLines:(NSString *_Nonnull)label values:(const float *_Nonnull)values valueCount:(int)valueCount valuesOffset:(int)valuesOffset overlayText:(NSString *_Nullable)overlayText minScale:(float)minScale maxScale:(float)maxScale graphSize:(CGSize)graphSize stride:(int)stride;
75 | + (void)plotHistogram:(NSString *_Nonnull)label values:(const float * _Nonnull)values valueCount:(int)valueCount valuesOffset:(int)valuesOffset overlayText:(NSString *_Nullable)overlayText minScale:(float)minScale maxScale:(float)maxScale graphSize:(CGSize)graphSize stride:(int)stride;
76 | + (void)pushStyleColor:(int)idx colorNumber:(unsigned int)color;
77 | + (void)pushStyleColor:(int)idx colorRef:(CGColorRef _Nonnull)color;
78 | + (void)popStyleColor:(int)count;
79 | + (void)pushStyleVar:(int)idx valNumber:(float)val;
80 | + (void)pushStyleVar:(int)idx valPoint:(CGPoint)val;
81 | + (void)popStyleVar:(int)count;
82 | + (void)pushItemWidth:(float)itemWidth;
83 | + (void)popItemWidth;
84 | + (void)pushFont:(void *_Nullable)font;
85 | + (void)popFont;
86 | + (void *_Nullable)getFontWithType:(int)type;
87 | + (void)addFontWithFilename:(NSString *_Nonnull)fileName sizePixels:(float)sizePixels;
88 | + (void)columns:(int)count strId:(NSString *_Nullable)strId border:(bool)border;
89 | + (void)nextColumn;
90 | + (void)setColumnWidth:(int)index width:(float)width;
91 | + (void)setColumnOffset:(int)index offset:(float)offset;
92 | + (bool)begin:(NSString *)name flags:(int)flags;
93 | + (void)end;
94 | + (bool)beginChild:(NSString *)strId size:(CGSize)size border:(bool)border flags:(int)flags;
95 | + (void)endChild;
96 | + (void)setNextWindowPos:(CGPoint)pos cond:(int)cond pivot:(CGPoint)pivot;
97 | + (void)setNextWindowSize:(CGSize)size cond:(int)cond;
98 | + (void *_Nullable)listClipperCreate:(int)itemsCount itemsHeight:(float)itemsHeight;
99 | + (void)listClipperDestroy:(void *_Nullable)clipperObj;
100 | + (void)listClipperBegin:(void *_Nullable)clipperObj itemsCount:(int)itemsCount itemsHeight:(float)itemsHeight;
101 | + (void)listClipperEnd:(void *_Nullable)clipperObj;
102 | + (void)listClipperLoop:(void *_Nullable)clipperObj block:(void (^) (int index))block;
103 |
104 | @end
105 |
106 | NS_ASSUME_NONNULL_END
107 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/TextEditorWrapper.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import
10 |
11 | NS_ASSUME_NONNULL_BEGIN
12 |
13 | typedef NS_ENUM(NSUInteger, TextEditorWrapperLanguage) {
14 | cpp,
15 | hlsl,
16 | glsl,
17 | c,
18 | sql,
19 | angelScript,
20 | lua
21 | };
22 |
23 | typedef NS_ENUM(NSUInteger, TextEditorWrapperPallete) {
24 | dflt,
25 | retroBlue,
26 | light,
27 | dark
28 | };
29 |
30 | @interface TextEditorWrapper : NSObject
31 |
32 | + (void)setLanguageDefinition:(TextEditorWrapperLanguage)type;
33 | + (int)getTotalLines;
34 | + (bool)isOverwrite;
35 | + (void)setReadOnly:(bool)value;
36 | + (bool)isReadOnly;
37 | + (bool)isTextChanged;
38 | + (bool)isCursorPositionChanged;
39 | + (void)setShowWhitespaces:(bool)value;
40 | + (bool)isShowingWhitespaces;
41 | + (void)setColorizerEnable:(bool)value;
42 | + (bool)isColorizerEnabled;
43 | + (void)setTabSize:(int)value;
44 | + (int)getTabSize;
45 | + (bool)canUndo;
46 | + (void)undo;
47 | + (bool)canRedo;
48 | + (void)redo;
49 | + (bool)hasSelection;
50 | + (void)copy;
51 | + (void)cut;
52 | + (void)remove;
53 | + (void)paste;
54 | + (void)selectAll;
55 | + (void)setPallete:(TextEditorWrapperPallete)type;
56 | + (void)setText:(NSString *)text;
57 | + (NSString *)getText;
58 | + (void)insertText:(NSString *)text;
59 | + (void)render:(NSString *)title;
60 |
61 | + (void)clearErrorMarkers;
62 | + (void)insertErrorMarker:(int)index text:(NSString *)text;
63 |
64 | @end
65 |
66 | NS_ASSUME_NONNULL_END
67 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/TextEditorWrapper.mm:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import "TextEditorWrapper.h"
10 | #import "TextEditor.h"
11 |
12 | // restricted to unique editor
13 | static TextEditor textEditor;
14 | static TextEditor::ErrorMarkers markers;
15 |
16 | @interface TextEditorWrapper ()
17 |
18 | @end
19 |
20 | @implementation TextEditorWrapper
21 |
22 | + (void)setLanguageDefinition:(TextEditorWrapperLanguage)type {
23 |
24 | switch (type) {
25 | case cpp: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus()); break;
26 | case hlsl: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::HLSL()); break;
27 | case glsl: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::GLSL()); break;
28 | case c: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::C()); break;
29 | case sql: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::SQL()); break;
30 | case angelScript: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::AngelScript()); break;
31 | case lua: textEditor.SetLanguageDefinition(TextEditor::LanguageDefinition::Lua()); break;
32 | default: break;
33 | }
34 | }
35 |
36 | + (int)getTotalLines {
37 |
38 | return textEditor.GetTotalLines();
39 | }
40 |
41 | + (bool)isOverwrite {
42 |
43 | return textEditor.IsOverwrite();
44 | }
45 |
46 | + (void)setReadOnly:(bool)value {
47 |
48 | textEditor.SetReadOnly(value);
49 | }
50 |
51 | + (bool)isReadOnly {
52 |
53 | return textEditor.IsReadOnly();
54 | }
55 |
56 | + (bool)isTextChanged {
57 |
58 | return textEditor.IsTextChanged();
59 | }
60 |
61 | + (bool)isCursorPositionChanged {
62 |
63 | return textEditor.IsCursorPositionChanged();
64 | }
65 |
66 | + (void)setShowWhitespaces:(bool)value {
67 |
68 | textEditor.SetShowWhitespaces(value);
69 | }
70 |
71 | + (bool)isShowingWhitespaces {
72 |
73 | return textEditor.IsShowingWhitespaces();
74 | }
75 |
76 | + (void)setColorizerEnable:(bool)value {
77 |
78 | textEditor.SetColorizerEnable(value);
79 | }
80 |
81 | + (bool)isColorizerEnabled {
82 |
83 | return textEditor.IsColorizerEnabled();
84 | }
85 |
86 | + (void)setTabSize:(int)value {
87 |
88 | textEditor.SetTabSize(value);
89 | }
90 |
91 | + (int)getTabSize {
92 |
93 | return textEditor.GetTabSize();
94 | }
95 |
96 | + (bool)canUndo {
97 |
98 | return textEditor.CanUndo();
99 | }
100 |
101 | + (void)undo {
102 |
103 | textEditor.Undo();
104 | }
105 |
106 | + (bool)canRedo {
107 |
108 | return textEditor.CanRedo();
109 | }
110 |
111 | + (void)redo {
112 |
113 | textEditor.Redo();
114 | }
115 |
116 | + (bool)hasSelection {
117 |
118 | return textEditor.HasSelection();
119 | }
120 |
121 | + (void)copy {
122 |
123 | textEditor.Copy();
124 | }
125 |
126 | + (void)cut {
127 |
128 | textEditor.Cut();
129 | }
130 |
131 | + (void)remove {
132 |
133 | textEditor.Delete();
134 | }
135 |
136 | + (void)paste {
137 |
138 | textEditor.Paste();
139 | }
140 |
141 | + (void)selectAll {
142 |
143 | textEditor.SelectAll();
144 | }
145 |
146 | + (void)setPallete:(TextEditorWrapperPallete)type {
147 |
148 | switch (type) {
149 | case dflt: textEditor.SetPalette(TextEditor::GetDefaultPalette()); break;
150 | case retroBlue: textEditor.SetPalette(TextEditor::GetRetroBluePalette()); break;
151 | case light: textEditor.SetPalette(TextEditor::GetLightPalette()); break;
152 | case dark: textEditor.SetPalette(TextEditor::GetDarkPalette()); break;
153 | default: break;
154 | }
155 | }
156 |
157 | + (void)setText:(NSString *)text {
158 |
159 | textEditor.SetText(std::string([text UTF8String]));
160 | }
161 |
162 | + (NSString *)getText {
163 |
164 | return [NSString stringWithCString:textEditor.GetText().c_str() encoding:[NSString defaultCStringEncoding]];
165 | }
166 |
167 | + (void)insertText:(NSString *)text {
168 |
169 | textEditor.InsertText(std::string([text UTF8String]));
170 | }
171 |
172 | + (void)render:(NSString *)title {
173 |
174 | textEditor.Render([title UTF8String]);
175 | }
176 |
177 | + (void)clearErrorMarkers {
178 |
179 | markers.clear();
180 |
181 | textEditor.SetErrorMarkers(markers);
182 | }
183 |
184 | + (void)insertErrorMarker:(int)index text:(NSString *)text {
185 |
186 | markers.insert(std::make_pair(index, std::string([text UTF8String])));
187 |
188 | textEditor.SetErrorMarkers(markers);
189 | }
190 |
191 | @end
192 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/imgui/imconfig.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI
3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
5 | //-----------------------------------------------------------------------------
6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h)
7 | // B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
8 | // If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include
9 | // the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
10 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
11 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
12 | //-----------------------------------------------------------------------------
13 |
14 | #pragma once
15 |
16 | //---- Define assertion handler. Defaults to calling assert().
17 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
18 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
19 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
20 |
21 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
22 | // Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
23 | //#define IMGUI_API __declspec( dllexport )
24 | //#define IMGUI_API __declspec( dllimport )
25 |
26 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
27 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
28 |
29 | //---- Disable all of Dear ImGui or don't implement standard windows.
30 | // It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
31 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
32 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
33 | //#define IMGUI_DISABLE_METRICS_WINDOW // Disable debug/metrics window: ShowMetricsWindow() will be empty.
34 |
35 | //---- Don't implement some functions to reduce linkage requirements.
36 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
37 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
38 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
39 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
40 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
41 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
42 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
43 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
44 |
45 | //---- Include imgui_user.h at the end of imgui.h as a convenience
46 | //#define IMGUI_INCLUDE_IMGUI_USER_H
47 |
48 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
49 | //#define IMGUI_USE_BGRA_PACKED_COLOR
50 |
51 | //---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points.
52 | //#define IMGUI_USE_WCHAR32
53 |
54 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
55 | // By default the embedded implementations are declared static and not available outside of imgui cpp files.
56 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
57 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
58 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
59 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
60 |
61 | //---- Unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined, use the much faster STB sprintf library implementation of vsnprintf instead of the one from the default C library.
62 | // Note that stb_sprintf.h is meant to be provided by the user and available in the include path at compile time. Also, the compatibility checks of the arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
63 | // #define IMGUI_USE_STB_SPRINTF
64 |
65 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
66 | // This will be inlined as part of ImVec2 and ImVec4 class declarations.
67 | /*
68 | #define IM_VEC2_CLASS_EXTRA \
69 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
70 | operator MyVec2() const { return MyVec2(x,y); }
71 |
72 | #define IM_VEC4_CLASS_EXTRA \
73 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
74 | operator MyVec4() const { return MyVec4(x,y,z,w); }
75 | */
76 |
77 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
78 | // Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bit indices).
79 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
80 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
81 | //#define ImDrawIdx unsigned int
82 |
83 | //---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
84 | //struct ImDrawList;
85 | //struct ImDrawCmd;
86 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
87 | //#define ImDrawCallback MyImDrawCallback
88 |
89 | //---- Debug Tools: Macro to break in Debugger
90 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
91 | //#define IM_DEBUG_BREAK IM_ASSERT(0)
92 | //#define IM_DEBUG_BREAK __debugbreak()
93 |
94 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
95 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
96 | // This adds a small runtime cost which is why it is not enabled by default.
97 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
98 |
99 | //---- Debug Tools: Enable slower asserts
100 | //#define IMGUI_DEBUG_PARANOID
101 |
102 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
103 | /*
104 | namespace ImGui
105 | {
106 | void MyFunction(const char* name, const MyMatrix44& v);
107 | }
108 | */
109 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/imgui/render/imgui_impl_metal.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Renderer for Metal
2 | // This needs to be used along with a Platform Binding (e.g. OSX)
3 |
4 | // Implemented features:
5 | // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID!
6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
7 | // Missing features:
8 | // [ ] Renderer: Multi-viewport / platform windows.
9 |
10 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
11 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
12 | // https://github.com/ocornut/imgui
13 |
14 | #include "imgui.h" // IMGUI_IMPL_API
15 |
16 | @class MTLRenderPassDescriptor;
17 | @protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder;
18 |
19 | IMGUI_IMPL_API bool ImGui_ImplMetal_Init(id device);
20 | IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown();
21 | IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor *renderPassDescriptor);
22 | IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
23 | id commandBuffer,
24 | id commandEncoder);
25 |
26 | // Called by Init/NewFrame/Shutdown
27 | IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(id device);
28 | IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture();
29 | IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id device);
30 | IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
31 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/thirdparty/ImGuiColorTextEdit/CONTRIBUTING:
--------------------------------------------------------------------------------
1 | # Contributing
2 | Pull requests are welcome, feel free to contribute if you have implemented something which might be useful for the general audience of this little piece of software. Apparently, it became kind of a community project now. :)
3 |
4 | Whem contributing, please follow the following guidelines. I will keep it updated as we bump into something which worth doing better.
5 | - Try to follow the same coding and naming conventions you find in the source already. I know that everyone has its own preference/taste in coding, but please keep the source consistent in style.
6 | - Please submit to the 'dev' branch first for testing, and it will be merged to 'main' if it seems to work fine. I would like try keep 'master' in a good working condition, as more and more people are using it.
7 | - Please send your submissions in small, well defined requests, i. e. do not accumulate many unrelated changes in one large pull request. Keep your submissions as small as possible, it will make everyone's life easier.
8 | - Avoid using ImGui internal since it would make the source fragile against internal changes in ImGui.
9 | - Try to keep the perormance high within the render function. Try to avoid doing anything which leads to memory allocations (like using temporary std::string, std::vector variables), or complex algorithm. If you really have to, try to amortise it between frames.
10 |
11 | Thank you. :)
12 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/thirdparty/ImGuiColorTextEdit/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 BalazsJako
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Core/thirdparty/ImGuiColorTextEdit/README.md:
--------------------------------------------------------------------------------
1 | # ImGuiColorTextEdit
2 | Syntax highlighting text editor for ImGui
3 |
4 | 
5 |
6 | Demo project: https://github.com/BalazsJako/ColorTextEditorDemo
7 |
8 | This started as my attempt to write a relatively simple widget which provides text editing functionality with syntax highlighting. Now there are other contributors who provide valuable additions.
9 |
10 | While it relies on Omar Cornut's https://github.com/ocornut/imgui, it does not follow the "pure" one widget - one function approach. Since the editor has to maintain a relatively complex and large internal state, it did not seem to be practical to try and enforce fully immediate mode. It stores its internal state in an object instance which is reused across frames.
11 |
12 | The code is (still) work in progress, please report if you find any issues.
13 |
14 | # Main features
15 | - approximates typical code editor look and feel (essential mouse/keyboard commands work - I mean, the commands _I_ normally use :))
16 | - undo/redo
17 | - UTF-8 support
18 | - works with both fixed and variable-width fonts
19 | - extensible syntax highlighting for multiple languages
20 | - identifier declarations: a small piece of description can be associated with an identifier. The editor displays it in a tooltip when the mouse cursor is hovered over the identifier
21 | - error markers: the user can specify a list of error messages together the line of occurence, the editor will highligh the lines with red backround and display error message in a tooltip when the mouse cursor is hovered over the line
22 | - large files: there is no explicit limit set on file size or number of lines (below 2GB, performance is not affected when large files are loaded (except syntax coloring, see below)
23 | - color palette support: you can switch between different color palettes, or even define your own
24 | - whitespace indicators (TAB, space)
25 |
26 | # Known issues
27 | - syntax highligthing of most languages - except C/C++ - is based on std::regex, which is diasppointingly slow. Because of that, the highlighting process is amortized between multiple frames. C/C++ has a hand-written tokenizer which is much faster.
28 |
29 | Please post your screenshots if you find this little piece of software useful. :)
30 |
31 | # Contribute
32 |
33 | If you want to contribute, please refer to CONTRIBUTE file.
34 |
--------------------------------------------------------------------------------
/Source/SwiftGui/GuiBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | @_functionBuilder
10 | public struct GuiBuilder {
11 |
12 | public static func buildBlock() -> GuiView {
13 | return Empty()
14 | }
15 |
16 | public static func buildBlock(_ content: GuiView) -> GuiView {
17 | return content
18 | }
19 |
20 | public static func buildBlock(_ content: GuiView...) -> GuiView {
21 | GuiNodeList(children: content)
22 | }
23 |
24 | public static func buildIf(_ content: GuiView?) -> GuiView {
25 | if let content = content { return content }
26 | return GuiNodeList(children: [])
27 | }
28 |
29 | public static func buildEither(first: GuiView) -> GuiView {
30 | first
31 | }
32 |
33 | public static func buildEither(second: GuiView) -> GuiView {
34 | second
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Source/SwiftGui/GuiNode.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | public class GuiNode: GuiView,
10 | IdentifierValue,
11 | HoverEvent,
12 | SnapModifier,
13 | PaddingModifier,
14 | FontModifier,
15 | TextColorModifier {
16 |
17 | public var onHover: (() -> GuiView?)?
18 |
19 | public var id: String?
20 | public var snapWidth: Bool?
21 | public var padding: GuiEdge?
22 | public var paddingValue: Double?
23 | public var fontIndex: Int?
24 | public var textColor: GuiColor?
25 |
26 | public func drawComponent() {}
27 |
28 | final public func render() {
29 |
30 | self.preRendering()
31 |
32 | self.drawComponent()
33 |
34 | self.posRendering()
35 | }
36 | }
37 |
38 | private extension GuiNode {
39 |
40 | func checkHovered() {
41 |
42 | guard let onHover = self.onHover else { return }
43 |
44 | if ImGuiWrapper.isItemHovered() {
45 | onHover()?.render()
46 | }
47 | }
48 |
49 | func preRendering() {
50 |
51 | if let id = self.id {
52 | ImGuiWrapper.pushID(id)
53 | }
54 |
55 | self.paddingPreRendering()
56 |
57 | if let color = self.textColor {
58 | ImGuiWrapper.pushStyleColor(GuiColorProperty.text.rawValue, colorRef: color.cgColor)
59 | }
60 |
61 | if let fontIndex = self.fontIndex,
62 | let font = ImGuiWrapper.getFontWithType(Int32(fontIndex)) {
63 |
64 | ImGuiWrapper.pushFont(font)
65 | }
66 |
67 | if self.snapWidth != nil {
68 | ImGuiWrapper.pushItemWidth(-1)
69 | }
70 | }
71 |
72 | func posRendering() {
73 |
74 | self.checkHovered()
75 |
76 | if self.snapWidth != nil {
77 | ImGuiWrapper.popItemWidth()
78 | }
79 |
80 | if self.fontIndex != nil {
81 | ImGuiWrapper.popFont()
82 | }
83 |
84 | if self.textColor != nil {
85 | ImGuiWrapper.popStyleColor(1)
86 | }
87 |
88 | self.paddingPosRendering()
89 |
90 | if self.id != nil {
91 | ImGuiWrapper.popID()
92 | }
93 | }
94 |
95 | func paddingPreRendering() {
96 |
97 | guard padding != .bottom && padding != .trailing,
98 | let padding = self.padding,
99 | let paddingValue = self.paddingValue else {
100 |
101 | return
102 | }
103 |
104 | switch padding {
105 | case .all:
106 | ImGuiWrapper.dummy(GuiSize(width: 0.0, height: paddingValue))
107 | ImGuiWrapper.dummy(GuiSize(width: paddingValue, height: 0.0))
108 | ImGuiWrapper.sameLine(0.0, spacing: -1)
109 | case .top:
110 | ImGuiWrapper.dummy(GuiSize(width: 0.0, height: paddingValue))
111 | case .leading:
112 | ImGuiWrapper.dummy(GuiSize(width: paddingValue, height: 0.0))
113 | ImGuiWrapper.sameLine(0.0, spacing: -1)
114 | default:
115 | break
116 | }
117 | }
118 |
119 | func paddingPosRendering() {
120 |
121 | guard padding != .top && padding != .leading,
122 | let padding = self.padding,
123 | let paddingValue = self.paddingValue else {
124 |
125 | return
126 | }
127 |
128 | switch padding {
129 | case .all:
130 | ImGuiWrapper.sameLine(0.0, spacing: -1)
131 | ImGuiWrapper.dummy(GuiSize(width: paddingValue, height: 0.0))
132 | ImGuiWrapper.dummy(GuiSize(width: 0.0, height: paddingValue))
133 | case .bottom:
134 | ImGuiWrapper.dummy(GuiSize(width: 0.0, height: paddingValue))
135 | case .trailing:
136 | ImGuiWrapper.sameLine(0.0, spacing: -1)
137 | ImGuiWrapper.dummy(GuiSize(width: paddingValue, height: 0.0))
138 |
139 | default:
140 | break
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/Source/SwiftGui/GuiNodeList.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class GuiNodeList: GuiView {
12 |
13 | let children: [GuiView]
14 |
15 | init(children: [GuiView]) {
16 | self.children = children
17 | }
18 |
19 | public func render() {
20 |
21 | self.children.forEach { $0.render() }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/SwiftGui/GuiView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | public protocol GuiView {
10 |
11 | func render()
12 | }
13 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | $(MARKETING_VERSION)
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSHumanReadableCopyright
22 | Copyright © 2019 Erick Jung. All rights reserved.
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Resources/Font/FiraCodeRegular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erickjung/SwiftGUI/63ab435607b53ab3cbdb61206902d7d593fef077/Source/SwiftGui/Resources/Font/FiraCodeRegular.ttf
--------------------------------------------------------------------------------
/Source/SwiftGui/SwiftGui.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for SwiftGui.
12 | FOUNDATION_EXPORT double SwiftGuiVersionNumber;
13 |
14 | //! Project version string for SwiftGui.
15 | FOUNDATION_EXPORT const unsigned char SwiftGuiVersionString[];
16 |
17 | // In this header, you should import all the public headers of your framework using statements like #import
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Theme/Color/DarculaTheme.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class DarculaTheme: Theme {
12 |
13 | public var colors: [GuiColorProperty : GuiColor] {
14 |
15 | return [
16 | .text: .white,
17 | .textDisabled: GuiColor(r: 0.54, g: 0.54, b: 0.54, a: 1),
18 | .windowBg: GuiColor(r: 0.23, g: 0.24, b: 0.25, a: 1),
19 | .childBg: GuiColor(r: 0.23, g: 0.24, b: 0.25, a: 1),
20 | .popupBg: GuiColor(r: 0.23, g: 0.24, b: 0.25, a: 1),
21 | .border: GuiColor(r: 0.36, g: 0.36, b: 0.36, a: 1),
22 | .borderShadow: GuiColor(r: 0.15, g: 0.15, b: 0.15, a: 0),
23 | .frameBg: GuiColor(r: 0.27, g: 0.28, b: 0.29, a: 1),
24 | .frameBgHovered: GuiColor(r: 0.27, g: 0.28, b: 0.29, a: 1),
25 | .frameBgActive: GuiColor(r: 0.47, g: 0.47, b: 0.47, a: 0.67),
26 | .titleBg: GuiColor(r: 0.04, g: 0.04, b: 0.04, a: 1),
27 | .titleBgActive: GuiColor(r: 0, g: 0, b: 0, a: 0.51),
28 | .titleBgCollapsed: GuiColor(r: 0.16, g: 0.29, b: 0.48, a: 1),
29 | .menuBarBg: GuiColor(r: 0.27, g: 0.28, b: 0.29, a: 0.8),
30 | .scrollbarBg: GuiColor(r: 0.39, g: 0.4, b: 0.4, a: 0),
31 | .scrollbarGrab: GuiColor(r: 0.39, g: 0.4, b: 0.4, a: 1),
32 | .scrollbarGrabHovered: GuiColor(r: 0.39, g: 0.4, b: 0.4, a: 1),
33 | .scrollbarGrabActive: GuiColor(r: 0.39, g: 0.4, b: 0.4, a: 1),
34 | .checkMark: GuiColor(r: 0.65, g: 0.65, b: 0.65, a: 1),
35 | .sliderGrab: GuiColor(r: 0.7, g: 0.7, b: 0.7, a: 0.62),
36 | .sliderGrabActive: GuiColor(r: 0.3, g: 0.3, b: 0.3, a: 0.84),
37 | .button: GuiColor(r: 0.29, g: 0.31, b: 0.32, a: 1),
38 | .buttonHovered: GuiColor(r: 0.29, g: 0.31, b: 0.32, a: 1),
39 | .buttonActive: GuiColor(r: 0.21, g: 0.34, b: 0.5, a: 1),
40 | .header: GuiColor(r: 0.32, g: 0.33, b: 0.34, a: 1),
41 | .headerHovered: GuiColor(r: 0.30, g: 0.32, b: 0.32, a: 1),
42 | .headerActive: GuiColor(r: 0.47, g: 0.47, b: 0.47, a: 0.67),
43 | .separator: GuiColor(r: 0.31, g: 0.31, b: 0.31, a: 1),
44 | .separatorHovered: GuiColor(r: 0.31, g: 0.31, b: 0.31, a: 1),
45 | .separatorActive: GuiColor(r: 0.31, g: 0.31, b: 0.31, a: 1),
46 | .resizeGrip: GuiColor(r: 1, g: 1, b: 1, a: 0.85),
47 | .resizeGripHovered: GuiColor(r: 1, g: 1, b: 1, a: 0.6),
48 | .resizeGripActive: GuiColor(r: 0.47, g: 0.47, b: 0.47, a: 0.67),
49 | .tab: GuiColor(r: 0.32, g: 0.33, b: 0.34, a: 1),
50 | .tabHovered: GuiColor(r: 0.21, g: 0.34, b: 0.5, a: 1),
51 | .tabActive: GuiColor(r: 0.21, g: 0.34, b: 0.5, a: 1),
52 | .tabUnfocused: GuiColor(r: 0.06, g: 0.53, b: 0.98, a: 0.8),
53 | .tabUnfocusedActive: GuiColor(r: 0.06, g: 0.53, b: 0.98, a: 0.4),
54 | .plotLines: GuiColor(r: 0.61, g: 0.61, b: 0.61, a: 1),
55 | .plotLinesHovered: GuiColor(r: 1, g: 0.43, b: 0.35, a: 1),
56 | .plotHistogram: GuiColor(r: 0.9, g: 0.7, b: 0, a: 1),
57 | .plotHistogramHovered: GuiColor(r: 1, g: 0.6, b: 0, a: 1),
58 | .textSelectedBg: GuiColor(r: 0.18, g: 0.39, b: 0.79, a: 0.9),
59 | .modalWindowDimBg: GuiColor(r: 0.18, g: 0.39, b: 0.79, a: 1)
60 | ]
61 | }
62 |
63 | public var windowRounding: Float {
64 | return 5.3
65 | }
66 |
67 | public var grabRounding: Float {
68 | return 2.3
69 | }
70 |
71 | public var frameRounding: Float {
72 | return 2.3
73 | }
74 |
75 | public var scrollbarRounding: Float {
76 | return 5
77 | }
78 |
79 | public var frameBorderSize: Float {
80 | return 1
81 | }
82 |
83 | public var itemSpacing: GuiPoint {
84 | return GuiPoint(x: 8, y: 6.5)
85 | }
86 |
87 | public init() {}
88 | }
89 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Theme/Color/LightTheme.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class LightTheme: Theme {
12 |
13 | public var colors: [GuiColorProperty : GuiColor] {
14 |
15 | return [
16 | .text: GuiColor(r: 0, g: 0, b: 0, a: 1),
17 | .textDisabled: GuiColor(r: 0.6, g: 0.6, b: 0.6, a: 1),
18 | .windowBg: GuiColor(r: 0.95, g: 0.95, b: 0.95, a: 1),
19 | .childBg: GuiColor(r: 0, g: 0, b: 0, a: 0),
20 | .popupBg: GuiColor(r: 0.92, g: 0.92, b: 0.92, a: 1),
21 | .border: GuiColor(r: 0.8, g: 0.8, b: 0.8, a: 1),
22 | .borderShadow: GuiColor(r: 0, g: 0, b: 0, a: 0),
23 | .frameBg: .white,
24 | .frameBgHovered: .white,
25 | .frameBgActive: GuiColor(r: 0.98, g: 0.98, b: 0.98, a: 1),
26 | .titleBg: GuiColor(r: 0.92, g: 0.92, b: 0.92, a: 1),
27 | .titleBgActive: GuiColor(r: 0.82, g: 0.82, b: 0.82, a: 1),
28 | .titleBgCollapsed: GuiColor(r: 1, g: 1, b: 1, a: 0.51),
29 | .menuBarBg: GuiColor(r: 0.90, g: 0.90, b: 0.90, a: 1),
30 | .scrollbarBg: GuiColor(r: 0.98, g: 0.98, b: 0.98, a: 0),
31 | .scrollbarGrab: GuiColor(r: 0.5, g: 0.5, b: 0.5, a: 1),
32 | .scrollbarGrabHovered: GuiColor(r: 0.5, g: 0.5, b: 0.5, a: 1),
33 | .scrollbarGrabActive: GuiColor(r: 0.5, g: 0.5, b: 0.5, a: 1),
34 | .checkMark: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.80),
35 | .sliderGrab: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.80),
36 | .sliderGrabActive: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.80),
37 | .button: .white,
38 | .buttonHovered: .white,
39 | .buttonActive: GuiColor(r: 0.22, g: 0.59, b: 0.98, a: 0.8),
40 | .header: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.31),
41 | .headerHovered: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.80),
42 | .headerActive: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 1),
43 | .separator: GuiColor(r: 0.8, g: 0.8, b: 0.8, a: 1),
44 | .separatorHovered: GuiColor(r: 0.8, g: 0.8, b: 0.8, a: 1),
45 | .separatorActive: GuiColor(r: 0.8, g: 0.8, b: 0.8, a: 1),
46 | .resizeGrip: GuiColor(r: 0.8, g: 0.8, b: 0.8, a: 1),
47 | .resizeGripHovered: .white,
48 | .resizeGripActive: .white,
49 | .tab: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.31),
50 | .tabHovered: GuiColor(r: 0.22, g: 0.59, b: 0.98, a: 1),
51 | .tabActive: GuiColor(r: 0.22, g: 0.59, b: 0.98, a: 1),
52 | .tabUnfocused: GuiColor(r: 0.22, g: 0.59, b: 0.98, a: 0.3),
53 | .tabUnfocusedActive: GuiColor(r: 0.22, g: 0.59, b: 0.98, a: 0.3),
54 | .dockingPreview: GuiColor(r: 0.14, g: 0.44, b: 0.80, a: 0.78),
55 | .dockingEmptyBg: GuiColor(r: 0.2, g: 0.2, b: 0.2, a: 1),
56 | .plotLines: GuiColor(r: 0.39, g: 0.39, b: 0.39, a: 1),
57 | .plotLinesHovered: GuiColor(r: 1, g: 0.43, b: 0.35, a: 1),
58 | .plotHistogram: GuiColor(r: 0.9, g: 0.7, b: 0, a: 1),
59 | .plotHistogramHovered: GuiColor(r: 1, g: 0.45, b: 0, a: 1),
60 | .textSelectedBg: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.35),
61 | .dragDropTarget: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.95),
62 | .navHighlight: GuiColor(r: 0.26, g: 0.59, b: 0.98, a: 0.80),
63 | .navWindowingHighlight: GuiColor(r: 0.7, g: 0.7, b: 0.7, a: 0.7),
64 | .navWindowingDimBg: GuiColor(r: 0.2, g: 0.2, b: 0.2, a: 0.2),
65 | .modalWindowDimBg: GuiColor(r: 0.2, g: 0.2, b: 0.2, a: 0.35)
66 | ]
67 | }
68 |
69 | public var windowRounding: Float {
70 | return 5.3
71 | }
72 |
73 | public var grabRounding: Float {
74 | return 2.3
75 | }
76 |
77 | public var frameRounding: Float {
78 | return 2.3
79 | }
80 |
81 | public var scrollbarRounding: Float {
82 | return 5
83 | }
84 |
85 | public var frameBorderSize: Float {
86 | return 1
87 | }
88 |
89 | public var itemSpacing: GuiPoint {
90 | return GuiPoint(x: 8, y: 6.5)
91 | }
92 |
93 | public init() {}
94 | }
95 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Theme/Font/DefaultFontGroup.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public class DefaultFontGroup: FontGroup {
12 |
13 | public enum Types {
14 |
15 | public static let FiraCode_12 = 0 // default
16 | public static let FiraCode_14 = 1
17 | public static let FiraCode_16 = 2
18 | public static let FiraCode_18 = 3
19 | public static let FiraCode_20 = 4
20 | public static let FiraCode_22 = 5
21 | public static let FiraCode_24 = 6
22 | }
23 |
24 | public var fonts: [[String: [Float]]]? {
25 |
26 | let bundle = Bundle(for: DefaultFontGroup.self)
27 | var fontList = [[String: [Float]]]()
28 |
29 | if let path = bundle.path(forResource: "FiraCodeRegular", ofType: "ttf") {
30 |
31 | fontList.append([path: [12, 14, 16, 18, 20, 22, 24]])
32 | }
33 |
34 | return fontList.count > 0 ? fontList : nil
35 | }
36 |
37 | public init() {}
38 | }
39 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Theme/FontGroup.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | public protocol FontGroup {
12 |
13 | /// Global fonts [font path : [font sizes] ]
14 | var fonts: [[String: [Float]]]? { get }
15 | }
16 |
17 | extension FontGroup {
18 |
19 | public func load() {
20 |
21 | self.fonts?.forEach { font in
22 |
23 | guard let font = font.first else { return }
24 |
25 | font.value.forEach { size in
26 |
27 | ImGuiWrapper.addFont(withFilename: font.key, sizePixels: size)
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Source/SwiftGui/Utils/Extensions.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | import Foundation
10 |
11 | #if os(OSX)
12 |
13 | import Foundation
14 | import AppKit
15 |
16 | public typealias GuiColor = NSColor
17 |
18 | #else
19 |
20 | import AVFoundation
21 | import UIKit
22 |
23 | public typealias GuiColor = UIColor
24 |
25 | #endif
26 |
27 | public typealias GuiPoint = CGPoint
28 | public typealias GuiSize = CGSize
29 | public typealias GuiImage = AnyObject
30 |
31 | public extension String {
32 |
33 | func cChars(with capacity: Int) -> [Int8] {
34 |
35 | return [Int8](unsafeUninitializedCapacity: capacity) { buffer, initializedCount in
36 | let chars = self.utf8CString
37 |
38 | if chars.count < capacity {
39 | _ = buffer.initialize(from: chars)
40 | initializedCount = chars.count
41 |
42 | } else {
43 |
44 | var sub = chars[..<(capacity)]
45 | sub[sub.count - 1] = 0
46 | _ = buffer.initialize(from: sub)
47 | initializedCount = sub.count
48 | }
49 | }
50 | }
51 | }
52 |
53 | public extension GuiColor {
54 |
55 | convenience init(r: Float, g: Float, b: Float, a: Float) {
56 | self.init(red: CGFloat(r), green: CGFloat(g), blue: CGFloat(b), alpha: CGFloat(a))
57 | }
58 |
59 | func convertToFloats() -> [Float] {
60 |
61 | return self.cgColor.components!.map({ (v) -> Float in return Float(v) })
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Source/SwiftGuiMac/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | $(MARKETING_VERSION)
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSHumanReadableCopyright
22 | Copyright © 2020 Erick Jung. All rights reserved.
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Source/SwiftGuiMac/SwiftGui.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for SwiftGuiMac.
12 | FOUNDATION_EXPORT double SwiftGuiMacVersionNumber;
13 |
14 | //! Project version string for SwiftGuiMac.
15 | FOUNDATION_EXPORT const unsigned char SwiftGuiMacVersionString[];
16 |
17 | // In this header, you should import all the public headers of your framework using statements like #import
18 | #import "ImGuiWrapper.h"
19 | #import "ImGuiStyleWrapper.h"
20 | #import "TextEditorWrapper.h"
21 | #import "GuiRenderer.h"
22 |
--------------------------------------------------------------------------------
/Source/SwiftGuiMac/imgui_impl_osx.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Platform Binding for OSX / Cocoa
2 | // This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..)
3 | // [ALPHA] Early bindings, not well tested. If you want a portable application, prefer using the GLFW or SDL platform bindings on Mac.
4 |
5 | // Implemented features:
6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
7 | // [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this back-end).
8 | // Issues:
9 | // [ ] Platform: Keys are all generally very broken. Best using [event keycode] and not [event characters]..
10 | // [ ] Platform: Multi-viewport / platform windows.
11 |
12 | #include "imgui.h" // IMGUI_IMPL_API
13 |
14 | @class NSEvent;
15 | @class NSView;
16 |
17 | IMGUI_IMPL_API bool ImGui_ImplOSX_Init();
18 | IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown();
19 | IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView *_Nullable view);
20 | IMGUI_IMPL_API bool ImGui_ImplOSX_HandleEvent(NSEvent *_Nonnull event, NSView *_Nullable view);
21 |
--------------------------------------------------------------------------------
/Source/SwiftGuiiOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | $(MARKETING_VERSION)
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Source/SwiftGuiiOS/SwiftGui.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2020, Erick Jung.
3 | // All rights reserved.
4 | //
5 | // This source code is licensed under the MIT-style license found in the
6 | // LICENSE file in the root directory of this source tree.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for SwiftGuiiOS.
12 | FOUNDATION_EXPORT double SwiftGuiiOSVersionNumber;
13 |
14 | //! Project version string for SwiftGuiiOS.
15 | FOUNDATION_EXPORT const unsigned char SwiftGuiiOSVersionString[];
16 |
17 | // In this header, you should import all the public headers of your framework using statements like #import
18 | #import "ImGuiWrapper.h"
19 | #import "ImGuiStyleWrapper.h"
20 | #import "TextEditorWrapper.h"
21 | #import "GuiRenderer.h"
22 |
23 |
--------------------------------------------------------------------------------
/SwiftGui.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |spec|
2 |
3 | spec.name = "SwiftGui"
4 | spec.version = "0.9.3"
5 | spec.summary = "SwiftGUI is an experimental API inspired by SwiftUI DSL."
6 | spec.homepage = "https://github.com/erickjung/SwiftGUI"
7 | spec.license = { :type => 'Copyright', :file => 'LICENSE' }
8 | spec.author = { "Erick Jung" => "erickjung@gmail.com" }
9 | spec.ios.deployment_target = "11.0"
10 | spec.osx.deployment_target = "10.13"
11 | spec.source = { :git => "https://github.com/erickjung/SwiftGUI.git", :tag => spec.version }
12 | spec.source_files = 'Source/SwiftGui/**/*.{h,m,mm,cpp,swift}'
13 | spec.osx.source_files = 'Source/SwiftGuiMac/**/*.{h,m,mm,cpp,swift}'
14 | spec.swift_version = '5.0'
15 | spec.public_header_files = [
16 | 'Source/SwiftGui/Core/ImGuiWrapper.h',
17 | 'Source/SwiftGui/Core/ImGuiStyleWrapper.h',
18 | 'Source/SwiftGui/Core/TextEditorWrapper.h',
19 | 'Source/SwiftGui/Core/GuiRenderer.h',
20 | ]
21 | spec.resources = 'Source/SwiftGui/Resources/**/*.ttf'
22 |
23 | end
24 |
--------------------------------------------------------------------------------