├── .gitignore ├── LICENSE ├── README.md ├── SmoothChat ├── SmoothChat.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── SmoothChat │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Chat.swift │ ├── ChatController.swift │ ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json │ ├── SmoothChat.entitlements │ ├── SmoothChatApp.swift │ └── Views │ ├── ChatListEntryView.swift │ ├── ChatListView.swift │ └── SmoothView │ ├── InputOutputHandlingView.swift │ ├── SmoothNSView.swift │ ├── SmoothRendererController.swift │ └── SmoothView.swift └── smooth-ui ├── Cargo.lock ├── Cargo.toml ├── SmoothUI ├── Package.swift └── Sources │ └── SmoothUI │ ├── ChatController.swift │ ├── SwiftBridgeCore.swift │ └── smooth-ui.swift ├── build.rs ├── generated ├── SwiftBridgeCore.h ├── SwiftBridgeCore.swift └── smooth-ui │ ├── smooth-ui.h │ └── smooth-ui.swift ├── scripts ├── build_debug.sh └── build_release.sh └── src ├── chat_ui.rs ├── ffi.rs ├── font_loader.rs ├── input_output.rs ├── lib.rs └── renderer.rs /.gitignore: -------------------------------------------------------------------------------- 1 | smooth-ui/target 2 | smooth-ui/SmoothUI/.build 3 | smooth-ui/SmoothUI/.swiftpm 4 | 5 | smooth-ui/SmoothUI/RustXcframework.xcframework 6 | 7 | 8 | SmoothChat/SmoothChat.xcodeproj/xcuserdata 9 | SmoothChat/SmoothChat.xcodeproj/project.xcworkspace/xcuserdata 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Intro 2 | This project is demonstrating how egui can be embedded into swiftui project. An article can be found [here](https://medium.com/@djalex566/fast-fluid-integrating-rust-egui-into-swiftui-30a218c502c1) 3 | 4 | # Structure 5 | - SmoothChat - Xcode project with swiftui implementation 6 | - smooth-ui - Rust package with egui implementation 7 | - smooth-ui/SmoothUI - SPM package with compiled egui implementation as XCFramework 8 | 9 | # Build instructions 10 | In order to build the project you need to build XCFramework for egui first 11 | 12 | ```Bash 13 | cd smooth-ui 14 | sh scripts/build_debug.sh 15 | ``` 16 | 17 | After that you can open the project from SmoothChat folder in Xcode and run 18 | 19 | # Dependencies 20 | - swift-bridge - For communication between swift and rust code bases 21 | - egui - The UI implementation in rust 22 | - wgpu - The graphics library for rendering egui in a metal view 23 | - font-kit - For dynamically loading system fonts 24 | 25 | # Real projects showcase 26 | - [DataScout](https://apps.apple.com/us/app/datascout-for-sqlite-swiftdata/id6737813684) - Embedded databases debugging tool for macOS 27 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 77; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8AAAFA0F2D92017A006E4F21 /* SmoothUI in Frameworks */ = {isa = PBXBuildFile; productRef = 8AAAFA0E2D92017A006E4F21 /* SmoothUI */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXFileReference section */ 14 | 8AAAF9FB2D92015E006E4F21 /* SmoothChat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SmoothChat.app; sourceTree = BUILT_PRODUCTS_DIR; }; 15 | /* End PBXFileReference section */ 16 | 17 | /* Begin PBXFileSystemSynchronizedRootGroup section */ 18 | 8AAAF9FD2D92015E006E4F21 /* SmoothChat */ = { 19 | isa = PBXFileSystemSynchronizedRootGroup; 20 | path = SmoothChat; 21 | sourceTree = ""; 22 | }; 23 | /* End PBXFileSystemSynchronizedRootGroup section */ 24 | 25 | /* Begin PBXFrameworksBuildPhase section */ 26 | 8AAAF9F82D92015E006E4F21 /* Frameworks */ = { 27 | isa = PBXFrameworksBuildPhase; 28 | buildActionMask = 2147483647; 29 | files = ( 30 | 8AAAFA0F2D92017A006E4F21 /* SmoothUI in Frameworks */, 31 | ); 32 | runOnlyForDeploymentPostprocessing = 0; 33 | }; 34 | /* End PBXFrameworksBuildPhase section */ 35 | 36 | /* Begin PBXGroup section */ 37 | 8AAAF9F22D92015E006E4F21 = { 38 | isa = PBXGroup; 39 | children = ( 40 | 8AAAF9FD2D92015E006E4F21 /* SmoothChat */, 41 | 8AAAF9FC2D92015E006E4F21 /* Products */, 42 | ); 43 | sourceTree = ""; 44 | }; 45 | 8AAAF9FC2D92015E006E4F21 /* Products */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | 8AAAF9FB2D92015E006E4F21 /* SmoothChat.app */, 49 | ); 50 | name = Products; 51 | sourceTree = ""; 52 | }; 53 | /* End PBXGroup section */ 54 | 55 | /* Begin PBXNativeTarget section */ 56 | 8AAAF9FA2D92015E006E4F21 /* SmoothChat */ = { 57 | isa = PBXNativeTarget; 58 | buildConfigurationList = 8AAAFA0A2D92015F006E4F21 /* Build configuration list for PBXNativeTarget "SmoothChat" */; 59 | buildPhases = ( 60 | 8AAAF9F72D92015E006E4F21 /* Sources */, 61 | 8AAAF9F82D92015E006E4F21 /* Frameworks */, 62 | 8AAAF9F92D92015E006E4F21 /* Resources */, 63 | ); 64 | buildRules = ( 65 | ); 66 | dependencies = ( 67 | ); 68 | fileSystemSynchronizedGroups = ( 69 | 8AAAF9FD2D92015E006E4F21 /* SmoothChat */, 70 | ); 71 | name = SmoothChat; 72 | packageProductDependencies = ( 73 | 8AAAFA0E2D92017A006E4F21 /* SmoothUI */, 74 | ); 75 | productName = SmoothChat; 76 | productReference = 8AAAF9FB2D92015E006E4F21 /* SmoothChat.app */; 77 | productType = "com.apple.product-type.application"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | 8AAAF9F32D92015E006E4F21 /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | BuildIndependentTargetsInParallel = 1; 86 | LastSwiftUpdateCheck = 1620; 87 | LastUpgradeCheck = 1620; 88 | TargetAttributes = { 89 | 8AAAF9FA2D92015E006E4F21 = { 90 | CreatedOnToolsVersion = 16.2; 91 | }; 92 | }; 93 | }; 94 | buildConfigurationList = 8AAAF9F62D92015E006E4F21 /* Build configuration list for PBXProject "SmoothChat" */; 95 | developmentRegion = en; 96 | hasScannedForEncodings = 0; 97 | knownRegions = ( 98 | en, 99 | Base, 100 | ); 101 | mainGroup = 8AAAF9F22D92015E006E4F21; 102 | minimizedProjectReferenceProxies = 1; 103 | packageReferences = ( 104 | 8AAAFA0D2D92017A006E4F21 /* XCLocalSwiftPackageReference "../smooth-ui/SmoothUI" */, 105 | ); 106 | preferredProjectObjectVersion = 77; 107 | productRefGroup = 8AAAF9FC2D92015E006E4F21 /* Products */; 108 | projectDirPath = ""; 109 | projectRoot = ""; 110 | targets = ( 111 | 8AAAF9FA2D92015E006E4F21 /* SmoothChat */, 112 | ); 113 | }; 114 | /* End PBXProject section */ 115 | 116 | /* Begin PBXResourcesBuildPhase section */ 117 | 8AAAF9F92D92015E006E4F21 /* Resources */ = { 118 | isa = PBXResourcesBuildPhase; 119 | buildActionMask = 2147483647; 120 | files = ( 121 | ); 122 | runOnlyForDeploymentPostprocessing = 0; 123 | }; 124 | /* End PBXResourcesBuildPhase section */ 125 | 126 | /* Begin PBXSourcesBuildPhase section */ 127 | 8AAAF9F72D92015E006E4F21 /* Sources */ = { 128 | isa = PBXSourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXSourcesBuildPhase section */ 135 | 136 | /* Begin XCBuildConfiguration section */ 137 | 8AAAFA082D92015F006E4F21 /* Debug */ = { 138 | isa = XCBuildConfiguration; 139 | buildSettings = { 140 | ALWAYS_SEARCH_USER_PATHS = NO; 141 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 142 | CLANG_ANALYZER_NONNULL = YES; 143 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 144 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 145 | CLANG_ENABLE_MODULES = YES; 146 | CLANG_ENABLE_OBJC_ARC = YES; 147 | CLANG_ENABLE_OBJC_WEAK = YES; 148 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 149 | CLANG_WARN_BOOL_CONVERSION = YES; 150 | CLANG_WARN_COMMA = YES; 151 | CLANG_WARN_CONSTANT_CONVERSION = YES; 152 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 153 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 154 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 155 | CLANG_WARN_EMPTY_BODY = YES; 156 | CLANG_WARN_ENUM_CONVERSION = YES; 157 | CLANG_WARN_INFINITE_RECURSION = YES; 158 | CLANG_WARN_INT_CONVERSION = YES; 159 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 160 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 161 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 162 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 163 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 164 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 165 | CLANG_WARN_STRICT_PROTOTYPES = YES; 166 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 167 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 168 | CLANG_WARN_UNREACHABLE_CODE = YES; 169 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 170 | COPY_PHASE_STRIP = NO; 171 | DEBUG_INFORMATION_FORMAT = dwarf; 172 | ENABLE_STRICT_OBJC_MSGSEND = YES; 173 | ENABLE_TESTABILITY = YES; 174 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 175 | GCC_C_LANGUAGE_STANDARD = gnu17; 176 | GCC_DYNAMIC_NO_PIC = NO; 177 | GCC_NO_COMMON_BLOCKS = YES; 178 | GCC_OPTIMIZATION_LEVEL = 0; 179 | GCC_PREPROCESSOR_DEFINITIONS = ( 180 | "DEBUG=1", 181 | "$(inherited)", 182 | ); 183 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 184 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 185 | GCC_WARN_UNDECLARED_SELECTOR = YES; 186 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 187 | GCC_WARN_UNUSED_FUNCTION = YES; 188 | GCC_WARN_UNUSED_VARIABLE = YES; 189 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 190 | MACOSX_DEPLOYMENT_TARGET = 15.1; 191 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 192 | MTL_FAST_MATH = YES; 193 | ONLY_ACTIVE_ARCH = YES; 194 | SDKROOT = macosx; 195 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 196 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 197 | }; 198 | name = Debug; 199 | }; 200 | 8AAAFA092D92015F006E4F21 /* Release */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | ALWAYS_SEARCH_USER_PATHS = NO; 204 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 205 | CLANG_ANALYZER_NONNULL = YES; 206 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 207 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 208 | CLANG_ENABLE_MODULES = YES; 209 | CLANG_ENABLE_OBJC_ARC = YES; 210 | CLANG_ENABLE_OBJC_WEAK = YES; 211 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 212 | CLANG_WARN_BOOL_CONVERSION = YES; 213 | CLANG_WARN_COMMA = YES; 214 | CLANG_WARN_CONSTANT_CONVERSION = YES; 215 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 216 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 217 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 218 | CLANG_WARN_EMPTY_BODY = YES; 219 | CLANG_WARN_ENUM_CONVERSION = YES; 220 | CLANG_WARN_INFINITE_RECURSION = YES; 221 | CLANG_WARN_INT_CONVERSION = YES; 222 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 223 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 224 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 225 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 226 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 227 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 228 | CLANG_WARN_STRICT_PROTOTYPES = YES; 229 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 230 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 231 | CLANG_WARN_UNREACHABLE_CODE = YES; 232 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 233 | COPY_PHASE_STRIP = NO; 234 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 235 | ENABLE_NS_ASSERTIONS = NO; 236 | ENABLE_STRICT_OBJC_MSGSEND = YES; 237 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 238 | GCC_C_LANGUAGE_STANDARD = gnu17; 239 | GCC_NO_COMMON_BLOCKS = YES; 240 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 241 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 242 | GCC_WARN_UNDECLARED_SELECTOR = YES; 243 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 244 | GCC_WARN_UNUSED_FUNCTION = YES; 245 | GCC_WARN_UNUSED_VARIABLE = YES; 246 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 247 | MACOSX_DEPLOYMENT_TARGET = 15.1; 248 | MTL_ENABLE_DEBUG_INFO = NO; 249 | MTL_FAST_MATH = YES; 250 | SDKROOT = macosx; 251 | SWIFT_COMPILATION_MODE = wholemodule; 252 | }; 253 | name = Release; 254 | }; 255 | 8AAAFA0B2D92015F006E4F21 /* Debug */ = { 256 | isa = XCBuildConfiguration; 257 | buildSettings = { 258 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 259 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 260 | CODE_SIGN_ENTITLEMENTS = SmoothChat/SmoothChat.entitlements; 261 | CODE_SIGN_STYLE = Automatic; 262 | COMBINE_HIDPI_IMAGES = YES; 263 | CURRENT_PROJECT_VERSION = 1; 264 | DEVELOPMENT_ASSET_PATHS = "\"SmoothChat/Preview Content\""; 265 | DEVELOPMENT_TEAM = 5CWYRH8P25; 266 | ENABLE_HARDENED_RUNTIME = YES; 267 | ENABLE_PREVIEWS = YES; 268 | GENERATE_INFOPLIST_FILE = YES; 269 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 270 | LD_RUNPATH_SEARCH_PATHS = ( 271 | "$(inherited)", 272 | "@executable_path/../Frameworks", 273 | ); 274 | MARKETING_VERSION = 1.0; 275 | PRODUCT_BUNDLE_IDENTIFIER = com.oleksii.SmoothChat; 276 | PRODUCT_NAME = "$(TARGET_NAME)"; 277 | SWIFT_EMIT_LOC_STRINGS = YES; 278 | SWIFT_VERSION = 5.0; 279 | }; 280 | name = Debug; 281 | }; 282 | 8AAAFA0C2D92015F006E4F21 /* Release */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 286 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 287 | CODE_SIGN_ENTITLEMENTS = SmoothChat/SmoothChat.entitlements; 288 | CODE_SIGN_STYLE = Automatic; 289 | COMBINE_HIDPI_IMAGES = YES; 290 | CURRENT_PROJECT_VERSION = 1; 291 | DEVELOPMENT_ASSET_PATHS = "\"SmoothChat/Preview Content\""; 292 | DEVELOPMENT_TEAM = 5CWYRH8P25; 293 | ENABLE_HARDENED_RUNTIME = YES; 294 | ENABLE_PREVIEWS = YES; 295 | GENERATE_INFOPLIST_FILE = YES; 296 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 297 | LD_RUNPATH_SEARCH_PATHS = ( 298 | "$(inherited)", 299 | "@executable_path/../Frameworks", 300 | ); 301 | MARKETING_VERSION = 1.0; 302 | PRODUCT_BUNDLE_IDENTIFIER = com.oleksii.SmoothChat; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SWIFT_EMIT_LOC_STRINGS = YES; 305 | SWIFT_VERSION = 5.0; 306 | }; 307 | name = Release; 308 | }; 309 | /* End XCBuildConfiguration section */ 310 | 311 | /* Begin XCConfigurationList section */ 312 | 8AAAF9F62D92015E006E4F21 /* Build configuration list for PBXProject "SmoothChat" */ = { 313 | isa = XCConfigurationList; 314 | buildConfigurations = ( 315 | 8AAAFA082D92015F006E4F21 /* Debug */, 316 | 8AAAFA092D92015F006E4F21 /* Release */, 317 | ); 318 | defaultConfigurationIsVisible = 0; 319 | defaultConfigurationName = Release; 320 | }; 321 | 8AAAFA0A2D92015F006E4F21 /* Build configuration list for PBXNativeTarget "SmoothChat" */ = { 322 | isa = XCConfigurationList; 323 | buildConfigurations = ( 324 | 8AAAFA0B2D92015F006E4F21 /* Debug */, 325 | 8AAAFA0C2D92015F006E4F21 /* Release */, 326 | ); 327 | defaultConfigurationIsVisible = 0; 328 | defaultConfigurationName = Release; 329 | }; 330 | /* End XCConfigurationList section */ 331 | 332 | /* Begin XCLocalSwiftPackageReference section */ 333 | 8AAAFA0D2D92017A006E4F21 /* XCLocalSwiftPackageReference "../smooth-ui/SmoothUI" */ = { 334 | isa = XCLocalSwiftPackageReference; 335 | relativePath = "../smooth-ui/SmoothUI"; 336 | }; 337 | /* End XCLocalSwiftPackageReference section */ 338 | 339 | /* Begin XCSwiftPackageProductDependency section */ 340 | 8AAAFA0E2D92017A006E4F21 /* SmoothUI */ = { 341 | isa = XCSwiftPackageProductDependency; 342 | productName = SmoothUI; 343 | }; 344 | /* End XCSwiftPackageProductDependency section */ 345 | }; 346 | rootObject = 8AAAF9F32D92015E006E4F21 /* Project object */; 347 | } 348 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "scale" : "1x", 6 | "size" : "16x16" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "scale" : "2x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "scale" : "1x", 16 | "size" : "32x32" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "scale" : "2x", 21 | "size" : "32x32" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "scale" : "1x", 26 | "size" : "128x128" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "scale" : "2x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "scale" : "1x", 36 | "size" : "256x256" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "scale" : "2x", 41 | "size" : "256x256" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "scale" : "1x", 46 | "size" : "512x512" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "scale" : "2x", 51 | "size" : "512x512" 52 | } 53 | ], 54 | "info" : { 55 | "author" : "xcode", 56 | "version" : 1 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Chat.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Chat.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 25.03.25. 6 | // 7 | 8 | import Foundation 9 | 10 | struct Chat: Identifiable, Hashable { 11 | let id: String 12 | let name: String 13 | let messages: [Message] 14 | 15 | static func mockHistory() -> [Chat] { 16 | let randomGreating = ["Hello!", "Hi!", "Hey!", "What's up?"] 17 | return [ 18 | .init( 19 | id: "1", 20 | name: "Karen", 21 | messages: (0..<100).map { 22 | .init(id: "\($0)", 23 | text: randomGreating.randomElement()!) 24 | } 25 | ), 26 | .init( 27 | id: "2", 28 | name: "Bill", 29 | messages: [ 30 | .init(id: "1", text: "Hey! 􀝻"), 31 | .init(id: "3", text: "How are you?"), 32 | .init(id: "2", text: "Up for a run Today?") 33 | ]) 34 | ] 35 | } 36 | 37 | func hash(into hasher: inout Hasher) { 38 | hasher.combine(id) 39 | } 40 | 41 | static func == (lhs: Self, rhs: Self) -> Bool { 42 | lhs.id == rhs.id 43 | } 44 | } 45 | 46 | struct Message: Identifiable, Hashable { 47 | let id: String 48 | let text: String 49 | } 50 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/ChatController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChatController.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 25.03.25. 6 | // 7 | 8 | import Foundation 9 | import Observation 10 | import SmoothUI 11 | 12 | @Observable 13 | final class ChatController: BaseChatController { 14 | 15 | var selectedChat: Chat? 16 | 17 | // MARK: - View 18 | 19 | func select(chat: Chat) { 20 | selectedChat = chat 21 | } 22 | 23 | // MARK: - BaseChatController 24 | 25 | override func bubbles_count() -> UInt { 26 | guard let selectedChat else { 27 | return 0 28 | } 29 | return UInt(selectedChat.messages.count) 30 | } 31 | 32 | override func bubble_at_index(index: UInt) -> ChatBubble { 33 | guard let selectedChat else { 34 | fatalError("Bubble requested without selected chat") 35 | } 36 | let message = selectedChat.messages[Int(index)] 37 | return .init(sender: selectedChat.name.intoRustString(), 38 | text: message.text.intoRustString()) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/SmoothChat.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 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/SmoothChatApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SmoothChatApp.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 24.03.25. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct SmoothChatApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ChatListView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Views/ChatListEntryView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChatListEntryView.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 25.03.25. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ChatListEntryView: View { 11 | let chat: Chat 12 | 13 | var body: some View { 14 | HStack(alignment: .top) { 15 | ZStack { 16 | Circle() 17 | .fill(.green) 18 | .frame(width: 44.0, height: 44.0) 19 | Text(chat.name.prefix(2).uppercased()) 20 | .font(.title2) 21 | } 22 | VStack(alignment: .leading) { 23 | Text(chat.name) 24 | .font(.headline) 25 | .foregroundStyle(.primary) 26 | 27 | if let lastConversation = chat.messages.last { 28 | Text(lastConversation.text) 29 | .font(.caption) 30 | .foregroundStyle(.secondary) 31 | } 32 | } 33 | } 34 | .fontDesign(.rounded) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Views/ChatListView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 24.03.25. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ChatListView: View { 11 | 12 | @State 13 | var controller = ChatController() 14 | 15 | @State 16 | var history = Chat.mockHistory() 17 | 18 | var body: some View { 19 | NavigationSplitView { 20 | List(selection: $controller.selectedChat) { 21 | Section("Today") { 22 | ForEach(Chat.mockHistory()) { chat in 23 | ChatListEntryView(chat: chat) 24 | .tag(chat) 25 | } 26 | } 27 | } 28 | .onAppear { 29 | if let first = history.first { 30 | controller.select(chat: first) 31 | } 32 | } 33 | } detail: { 34 | SmoothView(controller: controller) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Views/SmoothView/InputOutputHandlingView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputOutputHandlingView.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 25.03.25. 6 | // 7 | 8 | import AppKit 9 | import SmoothUI 10 | 11 | class InputOutputHandlingView: NSView { 12 | 13 | private var trackingArea: NSTrackingArea? 14 | private var gatheredEvents: [InputEvent] = [] 15 | 16 | private var currentCursor: NSCursor? 17 | 18 | override var acceptsFirstResponder: Bool { 19 | true 20 | } 21 | 22 | func draingEvents() -> RustVec { 23 | let events = gatheredEvents 24 | gatheredEvents = [] 25 | 26 | let result = RustVec() 27 | for event in events { 28 | result.push(value: event) 29 | } 30 | return result 31 | } 32 | 33 | func handle(output: OutputState) { 34 | let setCursor = output.get_cursor_icon() 35 | let newCursor = cursorToNSCursor(setCursor) 36 | 37 | if currentCursor != newCursor { 38 | if let activeCursor = currentCursor { 39 | activeCursor.pop() 40 | currentCursor = nil 41 | } 42 | 43 | newCursor.push() 44 | currentCursor = newCursor 45 | } 46 | } 47 | 48 | func resetCursor() { 49 | if let activeCursor = currentCursor { 50 | activeCursor.pop() 51 | currentCursor = nil 52 | } 53 | } 54 | 55 | func cursorToNSCursor(_ cursor: CursorIconRef) -> NSCursor { 56 | if cursor.is_default() { 57 | .arrow 58 | } else if cursor.is_pointing_hand() { 59 | .pointingHand 60 | } else if cursor.is_text() { 61 | .iBeam 62 | } else if cursor.is_resize_horizontal(), #available(macOS 15.0, *) { 63 | .columnResize 64 | } else if cursor.is_resize_horizontal() { 65 | .resizeLeftRight 66 | } else if cursor.is_resize_vertical(), #available(macOS 15.0, *) { 67 | .rowResize 68 | } else if cursor.is_resize_vertical() { 69 | .resizeUpDown 70 | } else { 71 | .arrow 72 | } 73 | } 74 | 75 | override func updateTrackingAreas() { 76 | super.updateTrackingAreas() 77 | 78 | if let trackingArea { 79 | removeTrackingArea(trackingArea) 80 | } 81 | 82 | // Use activeInKeyWindow so that the tracking is only active when the window is key. 83 | let options: NSTrackingArea.Options = [ 84 | .mouseEnteredAndExited, 85 | .mouseMoved, 86 | .activeInKeyWindow 87 | ] 88 | let trackingArea = NSTrackingArea(rect: bounds, options: options, owner: self, userInfo: nil) 89 | addTrackingArea(trackingArea) 90 | 91 | self.trackingArea = trackingArea 92 | } 93 | 94 | override func mouseEntered(with event: NSEvent) { 95 | handleMouseMove(event: event) 96 | } 97 | 98 | override func mouseMoved(with event: NSEvent) { 99 | handleMouseMove(event: event) 100 | } 101 | 102 | override func mouseExited(with event: NSEvent) { 103 | handleMouseMove(event: event) 104 | } 105 | 106 | // MARK: - Mouse Button and Scroll Events 107 | 108 | override func mouseDown(with event: NSEvent) { 109 | handleMouseMove(event: event) 110 | super.mouseDown(with: event) 111 | } 112 | 113 | override func mouseUp(with event: NSEvent) { 114 | handleMouseMove(event: event) 115 | super.mouseUp(with: event) 116 | } 117 | 118 | override func mouseDragged(with event: NSEvent) { 119 | handleMouseMove(event: event) 120 | super.mouseDragged(with: event) 121 | } 122 | 123 | override func rightMouseDown(with event: NSEvent) { 124 | handleMouseMove(event: event) 125 | super.rightMouseDown(with: event) 126 | } 127 | 128 | override func rightMouseUp(with event: NSEvent) { 129 | handleMouseMove(event: event) 130 | super.rightMouseUp(with: event) 131 | } 132 | 133 | override func rightMouseDragged(with event: NSEvent) { 134 | handleMouseMove(event: event) 135 | super.rightMouseDragged(with: event) 136 | } 137 | 138 | override func scrollWheel(with event: NSEvent) { 139 | handleMouseMove(event: event) 140 | super.scrollWheel(with: event) 141 | } 142 | 143 | // MARK: - Mapping 144 | 145 | private func handleMouseMove(event: NSEvent) { 146 | let point = convert(event.locationInWindow, from: nil) 147 | let size = bounds.size 148 | 149 | switch event.type { 150 | case .leftMouseDown: 151 | gatheredEvents.append( 152 | .from_left_mouse_down( 153 | Float(point.x), 154 | Float(size.height - point.y), 155 | true 156 | ) 157 | ) 158 | case .leftMouseUp: 159 | gatheredEvents.append( 160 | .from_left_mouse_down( 161 | Float(point.x), 162 | Float(size.height - point.y), 163 | false 164 | ) 165 | ) 166 | case .rightMouseDown: 167 | gatheredEvents.append( 168 | .from_right_mouse_down( 169 | Float(point.x), 170 | Float(size.height - point.y), 171 | true 172 | ) 173 | ) 174 | case .rightMouseUp: 175 | gatheredEvents.append( 176 | .from_right_mouse_down( 177 | Float(point.x), 178 | Float(size.height - point.y), 179 | false 180 | ) 181 | ) 182 | case .mouseMoved, .leftMouseDragged, .rightMouseDragged: 183 | gatheredEvents.append( 184 | .from_pointer_moved( 185 | Float(point.x), 186 | Float(size.height - point.y) 187 | ) 188 | ) 189 | case .mouseEntered: 190 | gatheredEvents.append( 191 | .from_window_focused(true) 192 | ) 193 | case .mouseExited: 194 | gatheredEvents.append( 195 | .from_window_focused(false) 196 | ) 197 | resetCursor() 198 | case .scrollWheel: 199 | gatheredEvents.append( 200 | .from_mouse_wheel( 201 | Float(event.scrollingDeltaX), 202 | Float(event.scrollingDeltaY) 203 | ) 204 | ) 205 | default: 206 | break 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Views/SmoothView/SmoothNSView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SmoothView.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 24.03.25. 6 | // 7 | 8 | import Metal 9 | import AppKit 10 | import SmoothUI 11 | 12 | @MainActor 13 | final class SmoothNSView: InputOutputHandlingView { 14 | 15 | var metalLayer: CAMetalLayer { 16 | layer as! CAMetalLayer 17 | } 18 | 19 | override init(frame frameRect: NSRect) { 20 | super.init(frame: frameRect) 21 | wantsLayer = true 22 | } 23 | 24 | required init?(coder: NSCoder) { 25 | fatalError("init(coder:) has not been implemented") 26 | } 27 | 28 | override func makeBackingLayer() -> CALayer { 29 | CAMetalLayer() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Views/SmoothView/SmoothRendererController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SmoothRendererController.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 24.03.25. 6 | // 7 | 8 | import Metal 9 | import AppKit 10 | import SmoothUI 11 | 12 | @MainActor 13 | final class SmoothRendererController: NSObject { 14 | let controller: BaseChatController 15 | 16 | private weak var view: SmoothNSView! 17 | private var displayLink: CADisplayLink! 18 | 19 | private var renderer: Renderer! 20 | 21 | init(controller: BaseChatController) { 22 | self.controller = controller 23 | } 24 | 25 | deinit { 26 | MainActor.assumeIsolated { 27 | displayLink.invalidate() 28 | } 29 | } 30 | 31 | func initialize(view: SmoothNSView, size: CGSize, scale: CGFloat) { 32 | self.view = view 33 | 34 | let layer = view.metalLayer 35 | layer.framebufferOnly = true 36 | layer.pixelFormat = .bgra8Unorm_srgb 37 | layer.drawableSize = size 38 | layer.contentsScale = scale 39 | 40 | let rawPointer = Unmanaged.passUnretained(layer).toOpaque() 41 | renderer = Renderer( 42 | rawPointer, 43 | UInt32(max(size.width, 100.0) * scale), 44 | UInt32(max(size.height, 100.0) * scale), 45 | Float(scale) 46 | ) 47 | } 48 | 49 | func start(view: SmoothNSView) { 50 | let link = view.displayLink(target: self, selector: #selector(render)) 51 | link.add(to: .main, forMode: .common) 52 | self.displayLink = link 53 | } 54 | 55 | @objc 56 | func render(displayLink: CADisplayLink) { 57 | let events = view.draingEvents() 58 | let state = renderer.render( 59 | displayLink.timestamp, 60 | events, 61 | controller 62 | ) 63 | view.handle(output: state) 64 | } 65 | 66 | func resize(to size: CGSize, scale: CGFloat) { 67 | guard size.width > 0 && size.height > 0 else { 68 | return 69 | } 70 | renderer.resize( 71 | UInt32(size.width * scale), 72 | UInt32(size.height * scale) 73 | ) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /SmoothChat/SmoothChat/Views/SmoothView/SmoothView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SmoothView.swift 3 | // SmoothChat 4 | // 5 | // Created by Oleksii Oliinyk on 24.03.25. 6 | // 7 | 8 | import SwiftUI 9 | import AppKit 10 | import SmoothUI 11 | 12 | struct SmoothView: View { 13 | let controller: BaseChatController 14 | 15 | @Environment(\.displayScale) 16 | var displayScale 17 | 18 | var body: some View { 19 | GeometryReader { proxy in 20 | SmoothNSViewRepresentable( 21 | controller: controller, 22 | size: proxy.size, 23 | scale: displayScale 24 | ) 25 | } 26 | } 27 | } 28 | 29 | private struct SmoothNSViewRepresentable: NSViewRepresentable { 30 | let controller: BaseChatController 31 | let size: CGSize 32 | let scale: CGFloat 33 | 34 | func makeNSView(context: Context) -> SmoothNSView { 35 | let view = SmoothNSView(frame: .zero) 36 | context.coordinator.initialize(view: view, size: size, scale: scale) 37 | context.coordinator.start(view: view) 38 | return view 39 | } 40 | 41 | func updateNSView(_ nsView: SmoothNSView, context: Context) { 42 | context.coordinator.resize(to: size, scale: scale) 43 | } 44 | 45 | func makeCoordinator() -> SmoothRendererController { 46 | SmoothRendererController(controller: controller) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /smooth-ui/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "smooth-ui" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | name = "embed" 8 | crate-type = ["staticlib"] 9 | 10 | [profile.release] 11 | strip = "symbols" 12 | opt-level = "z" # Optimize for size "z" 13 | panic = "abort" # Reduce binary size by avoiding panic unwind 14 | lto = "fat" # Link Time Optimization (LTO) 15 | codegen-units = 1 16 | 17 | [dependencies] 18 | swift-bridge = "0.1" 19 | 20 | futures = "0.3" 21 | 22 | wgpu = "23.0" 23 | egui = "0.30.0" 24 | egui_wgpu_backend = "0.33.0" 25 | 26 | font-kit = "0.14.2" 27 | 28 | [build-dependencies] 29 | swift-bridge-build = "0.1" 30 | -------------------------------------------------------------------------------- /smooth-ui/SmoothUI/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5.0 2 | import PackageDescription 3 | let package = Package( 4 | name: "SmoothUI", 5 | products: [ 6 | .library( 7 | name: "SmoothUI", 8 | targets: ["SmoothUI"]), 9 | ], 10 | dependencies: [], 11 | targets: [ 12 | .binaryTarget( 13 | name: "RustXcframework", 14 | path: "RustXcframework.xcframework" 15 | ), 16 | .target( 17 | name: "SmoothUI", 18 | dependencies: ["RustXcframework"]) 19 | ] 20 | ) 21 | -------------------------------------------------------------------------------- /smooth-ui/SmoothUI/Sources/SmoothUI/ChatController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // SmoothUI 4 | // 5 | // Created by Alexey Oleynik on 25.03.25. 6 | // 7 | 8 | import Foundation 9 | 10 | open class BaseChatController { 11 | 12 | public init() { 13 | } 14 | 15 | open func bubbles_count() -> UInt { 16 | fatalError("Not implemented") 17 | } 18 | 19 | open func bubble_at_index(index: UInt) -> ChatBubble { 20 | fatalError("Not implemented") 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /smooth-ui/SmoothUI/Sources/SmoothUI/SwiftBridgeCore.swift: -------------------------------------------------------------------------------- 1 | import RustXcframework 2 | import Foundation 3 | 4 | extension RustString { 5 | public func toString() -> String { 6 | let str = self.as_str() 7 | let string = str.toString() 8 | 9 | return string 10 | } 11 | } 12 | 13 | extension RustStr { 14 | func toBufferPointer() -> UnsafeBufferPointer { 15 | let bytes = UnsafeBufferPointer(start: self.start, count: Int(self.len)) 16 | return bytes 17 | } 18 | 19 | public func toString() -> String { 20 | let bytes = self.toBufferPointer() 21 | return String(bytes: bytes, encoding: .utf8)! 22 | } 23 | } 24 | extension RustStr: Identifiable { 25 | public var id: String { 26 | self.toString() 27 | } 28 | } 29 | extension RustStr: Equatable { 30 | public static func == (lhs: RustStr, rhs: RustStr) -> Bool { 31 | return __swift_bridge__$RustStr$partial_eq(lhs, rhs); 32 | } 33 | } 34 | 35 | public protocol IntoRustString { 36 | func intoRustString() -> RustString; 37 | } 38 | 39 | extension String: IntoRustString { 40 | public func intoRustString() -> RustString { 41 | // TODO: When passing an owned Swift std String to Rust we've being wasteful here in that 42 | // we're creating a RustString (which involves Boxing a Rust std::string::String) 43 | // only to unbox it back into a String once it gets to the Rust side. 44 | // 45 | // A better approach would be to pass a RustStr to the Rust side and then have Rust 46 | // call `.to_string()` on the RustStr. 47 | RustString(self) 48 | } 49 | } 50 | 51 | extension RustString: IntoRustString { 52 | public func intoRustString() -> RustString { 53 | self 54 | } 55 | } 56 | 57 | /// If the String is Some: 58 | /// Safely get a scoped pointer to the String and then call the callback with a RustStr 59 | /// that uses that pointer. 60 | /// 61 | /// If the String is None: 62 | /// Call the callback with a RustStr that has a null pointer. 63 | /// The Rust side will know to treat this as `None`. 64 | func optionalStringIntoRustString(_ string: Optional) -> RustString? { 65 | if let val = string { 66 | return val.intoRustString() 67 | } else { 68 | return nil 69 | } 70 | } 71 | 72 | /// Used to safely get a pointer to a sequence of utf8 bytes, represented as a `RustStr`. 73 | /// 74 | /// For example, the Swift `String` implementation of the `ToRustStr` protocol does the following: 75 | /// 1. Use Swift's `String.utf8.withUnsafeBufferPointer` to get a pointer to the strings underlying 76 | /// utf8 bytes. 77 | /// 2. Construct a `RustStr` that points to these utf8 bytes. This is safe because `withUnsafeBufferPointer` 78 | /// guarantees that the buffer pointer will be valid for the duration of the `withUnsafeBufferPointer` 79 | /// callback. 80 | /// 3. Pass the `RustStr` to the closure that was passed into `RustStr.toRustStr`. 81 | public protocol ToRustStr { 82 | func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T; 83 | } 84 | 85 | extension String: ToRustStr { 86 | /// Safely get a scoped pointer to the String and then call the callback with a RustStr 87 | /// that uses that pointer. 88 | public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { 89 | return self.utf8CString.withUnsafeBufferPointer({ bufferPtr in 90 | let rustStr = RustStr( 91 | start: UnsafeMutableRawPointer(mutating: bufferPtr.baseAddress!).assumingMemoryBound(to: UInt8.self), 92 | // Subtract 1 because of the null termination character at the end 93 | len: UInt(bufferPtr.count - 1) 94 | ) 95 | return withUnsafeRustStr(rustStr) 96 | }) 97 | } 98 | } 99 | 100 | extension RustStr: ToRustStr { 101 | public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { 102 | return withUnsafeRustStr(self) 103 | } 104 | } 105 | 106 | func optionalRustStrToRustStr(_ str: Optional, _ withUnsafeRustStr: (RustStr) -> T) -> T { 107 | if let val = str { 108 | return val.toRustStr(withUnsafeRustStr) 109 | } else { 110 | return withUnsafeRustStr(RustStr(start: nil, len: 0)) 111 | } 112 | } 113 | public class RustVec { 114 | var ptr: UnsafeMutableRawPointer 115 | var isOwned: Bool = true 116 | 117 | public init(ptr: UnsafeMutableRawPointer) { 118 | self.ptr = ptr 119 | } 120 | 121 | public init() { 122 | ptr = T.vecOfSelfNew() 123 | isOwned = true 124 | } 125 | 126 | public func push (value: T) { 127 | T.vecOfSelfPush(vecPtr: ptr, value: value) 128 | } 129 | 130 | public func pop () -> Optional { 131 | T.vecOfSelfPop(vecPtr: ptr) 132 | } 133 | 134 | public func get(index: UInt) -> Optional { 135 | T.vecOfSelfGet(vecPtr: ptr, index: index) 136 | } 137 | 138 | public func as_ptr() -> UnsafePointer { 139 | UnsafePointer(OpaquePointer(T.vecOfSelfAsPtr(vecPtr: ptr))) 140 | } 141 | 142 | /// Rust returns a UInt, but we cast to an Int because many Swift APIs such as 143 | /// `ForEach(0..rustVec.len())` expect Int. 144 | public func len() -> Int { 145 | Int(T.vecOfSelfLen(vecPtr: ptr)) 146 | } 147 | 148 | deinit { 149 | if isOwned { 150 | T.vecOfSelfFree(vecPtr: ptr) 151 | } 152 | } 153 | } 154 | 155 | extension RustVec: Sequence { 156 | public func makeIterator() -> RustVecIterator { 157 | return RustVecIterator(self) 158 | } 159 | } 160 | 161 | public struct RustVecIterator: IteratorProtocol { 162 | var rustVec: RustVec 163 | var index: UInt = 0 164 | 165 | init (_ rustVec: RustVec) { 166 | self.rustVec = rustVec 167 | } 168 | 169 | public mutating func next() -> T.SelfRef? { 170 | let val = rustVec.get(index: index) 171 | index += 1 172 | return val 173 | } 174 | } 175 | 176 | extension RustVec: Collection { 177 | public typealias Index = Int 178 | 179 | public func index(after i: Int) -> Int { 180 | i + 1 181 | } 182 | 183 | public subscript(position: Int) -> T.SelfRef { 184 | self.get(index: UInt(position))! 185 | } 186 | 187 | public var startIndex: Int { 188 | 0 189 | } 190 | 191 | public var endIndex: Int { 192 | self.len() 193 | } 194 | } 195 | 196 | extension RustVec: RandomAccessCollection {} 197 | 198 | extension UnsafeBufferPointer { 199 | func toFfiSlice () -> __private__FfiSlice { 200 | __private__FfiSlice(start: UnsafeMutablePointer(mutating: self.baseAddress), len: UInt(self.count)) 201 | } 202 | } 203 | 204 | public protocol Vectorizable { 205 | associatedtype SelfRef 206 | associatedtype SelfRefMut 207 | 208 | static func vecOfSelfNew() -> UnsafeMutableRawPointer; 209 | 210 | static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) 211 | 212 | static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) 213 | 214 | static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional 215 | 216 | static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional 217 | 218 | static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional 219 | 220 | static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer 221 | 222 | static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt 223 | } 224 | 225 | extension UInt8: Vectorizable { 226 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 227 | __swift_bridge__$Vec_u8$new() 228 | } 229 | 230 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 231 | __swift_bridge__$Vec_u8$_free(vecPtr) 232 | } 233 | 234 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 235 | __swift_bridge__$Vec_u8$push(vecPtr, value) 236 | } 237 | 238 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 239 | let val = __swift_bridge__$Vec_u8$pop(vecPtr) 240 | if val.is_some { 241 | return val.val 242 | } else { 243 | return nil 244 | } 245 | } 246 | 247 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 248 | let val = __swift_bridge__$Vec_u8$get(vecPtr, index) 249 | if val.is_some { 250 | return val.val 251 | } else { 252 | return nil 253 | } 254 | } 255 | 256 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 257 | let val = __swift_bridge__$Vec_u8$get_mut(vecPtr, index) 258 | if val.is_some { 259 | return val.val 260 | } else { 261 | return nil 262 | } 263 | } 264 | 265 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 266 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u8$as_ptr(vecPtr))) 267 | } 268 | 269 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 270 | __swift_bridge__$Vec_u8$len(vecPtr) 271 | } 272 | } 273 | 274 | extension UInt16: Vectorizable { 275 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 276 | __swift_bridge__$Vec_u16$new() 277 | } 278 | 279 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 280 | __swift_bridge__$Vec_u16$_free(vecPtr) 281 | } 282 | 283 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 284 | __swift_bridge__$Vec_u16$push(vecPtr, value) 285 | } 286 | 287 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 288 | let val = __swift_bridge__$Vec_u16$pop(vecPtr) 289 | if val.is_some { 290 | return val.val 291 | } else { 292 | return nil 293 | } 294 | } 295 | 296 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 297 | let val = __swift_bridge__$Vec_u16$get(vecPtr, index) 298 | if val.is_some { 299 | return val.val 300 | } else { 301 | return nil 302 | } 303 | } 304 | 305 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 306 | let val = __swift_bridge__$Vec_u16$get_mut(vecPtr, index) 307 | if val.is_some { 308 | return val.val 309 | } else { 310 | return nil 311 | } 312 | } 313 | 314 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 315 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u16$as_ptr(vecPtr))) 316 | } 317 | 318 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 319 | __swift_bridge__$Vec_u16$len(vecPtr) 320 | } 321 | } 322 | 323 | extension UInt32: Vectorizable { 324 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 325 | __swift_bridge__$Vec_u32$new() 326 | } 327 | 328 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 329 | __swift_bridge__$Vec_u32$_free(vecPtr) 330 | } 331 | 332 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 333 | __swift_bridge__$Vec_u32$push(vecPtr, value) 334 | } 335 | 336 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 337 | let val = __swift_bridge__$Vec_u32$pop(vecPtr) 338 | if val.is_some { 339 | return val.val 340 | } else { 341 | return nil 342 | } 343 | } 344 | 345 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 346 | let val = __swift_bridge__$Vec_u32$get(vecPtr, index) 347 | if val.is_some { 348 | return val.val 349 | } else { 350 | return nil 351 | } 352 | } 353 | 354 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 355 | let val = __swift_bridge__$Vec_u32$get_mut(vecPtr, index) 356 | if val.is_some { 357 | return val.val 358 | } else { 359 | return nil 360 | } 361 | } 362 | 363 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 364 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u32$as_ptr(vecPtr))) 365 | } 366 | 367 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 368 | __swift_bridge__$Vec_u32$len(vecPtr) 369 | } 370 | } 371 | 372 | extension UInt64: Vectorizable { 373 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 374 | __swift_bridge__$Vec_u64$new() 375 | } 376 | 377 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 378 | __swift_bridge__$Vec_u64$_free(vecPtr) 379 | } 380 | 381 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 382 | __swift_bridge__$Vec_u64$push(vecPtr, value) 383 | } 384 | 385 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 386 | let val = __swift_bridge__$Vec_u64$pop(vecPtr) 387 | if val.is_some { 388 | return val.val 389 | } else { 390 | return nil 391 | } 392 | } 393 | 394 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 395 | let val = __swift_bridge__$Vec_u64$get(vecPtr, index) 396 | if val.is_some { 397 | return val.val 398 | } else { 399 | return nil 400 | } 401 | } 402 | 403 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 404 | let val = __swift_bridge__$Vec_u64$get_mut(vecPtr, index) 405 | if val.is_some { 406 | return val.val 407 | } else { 408 | return nil 409 | } 410 | } 411 | 412 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 413 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u64$as_ptr(vecPtr))) 414 | } 415 | 416 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 417 | __swift_bridge__$Vec_u64$len(vecPtr) 418 | } 419 | } 420 | 421 | extension UInt: Vectorizable { 422 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 423 | __swift_bridge__$Vec_usize$new() 424 | } 425 | 426 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 427 | __swift_bridge__$Vec_usize$_free(vecPtr) 428 | } 429 | 430 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 431 | __swift_bridge__$Vec_usize$push(vecPtr, value) 432 | } 433 | 434 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 435 | let val = __swift_bridge__$Vec_usize$pop(vecPtr) 436 | if val.is_some { 437 | return val.val 438 | } else { 439 | return nil 440 | } 441 | } 442 | 443 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 444 | let val = __swift_bridge__$Vec_usize$get(vecPtr, index) 445 | if val.is_some { 446 | return val.val 447 | } else { 448 | return nil 449 | } 450 | } 451 | 452 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 453 | let val = __swift_bridge__$Vec_usize$get_mut(vecPtr, index) 454 | if val.is_some { 455 | return val.val 456 | } else { 457 | return nil 458 | } 459 | } 460 | 461 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 462 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_usize$as_ptr(vecPtr))) 463 | } 464 | 465 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 466 | __swift_bridge__$Vec_usize$len(vecPtr) 467 | } 468 | } 469 | 470 | extension Int8: Vectorizable { 471 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 472 | __swift_bridge__$Vec_i8$new() 473 | } 474 | 475 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 476 | __swift_bridge__$Vec_i8$_free(vecPtr) 477 | } 478 | 479 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 480 | __swift_bridge__$Vec_i8$push(vecPtr, value) 481 | } 482 | 483 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 484 | let val = __swift_bridge__$Vec_i8$pop(vecPtr) 485 | if val.is_some { 486 | return val.val 487 | } else { 488 | return nil 489 | } 490 | } 491 | 492 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 493 | let val = __swift_bridge__$Vec_i8$get(vecPtr, index) 494 | if val.is_some { 495 | return val.val 496 | } else { 497 | return nil 498 | } 499 | } 500 | 501 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 502 | let val = __swift_bridge__$Vec_i8$get_mut(vecPtr, index) 503 | if val.is_some { 504 | return val.val 505 | } else { 506 | return nil 507 | } 508 | } 509 | 510 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 511 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i8$as_ptr(vecPtr))) 512 | } 513 | 514 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 515 | __swift_bridge__$Vec_i8$len(vecPtr) 516 | } 517 | } 518 | 519 | extension Int16: Vectorizable { 520 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 521 | __swift_bridge__$Vec_i16$new() 522 | } 523 | 524 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 525 | __swift_bridge__$Vec_i16$_free(vecPtr) 526 | } 527 | 528 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 529 | __swift_bridge__$Vec_i16$push(vecPtr, value) 530 | } 531 | 532 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 533 | let val = __swift_bridge__$Vec_i16$pop(vecPtr) 534 | if val.is_some { 535 | return val.val 536 | } else { 537 | return nil 538 | } 539 | } 540 | 541 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 542 | let val = __swift_bridge__$Vec_i16$get(vecPtr, index) 543 | if val.is_some { 544 | return val.val 545 | } else { 546 | return nil 547 | } 548 | } 549 | 550 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 551 | let val = __swift_bridge__$Vec_i16$get_mut(vecPtr, index) 552 | if val.is_some { 553 | return val.val 554 | } else { 555 | return nil 556 | } 557 | } 558 | 559 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 560 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i16$as_ptr(vecPtr))) 561 | } 562 | 563 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 564 | __swift_bridge__$Vec_i16$len(vecPtr) 565 | } 566 | } 567 | 568 | extension Int32: Vectorizable { 569 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 570 | __swift_bridge__$Vec_i32$new() 571 | } 572 | 573 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 574 | __swift_bridge__$Vec_i32$_free(vecPtr) 575 | } 576 | 577 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 578 | __swift_bridge__$Vec_i32$push(vecPtr, value) 579 | } 580 | 581 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 582 | let val = __swift_bridge__$Vec_i32$pop(vecPtr) 583 | if val.is_some { 584 | return val.val 585 | } else { 586 | return nil 587 | } 588 | } 589 | 590 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 591 | let val = __swift_bridge__$Vec_i32$get(vecPtr, index) 592 | if val.is_some { 593 | return val.val 594 | } else { 595 | return nil 596 | } 597 | } 598 | 599 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 600 | let val = __swift_bridge__$Vec_i32$get_mut(vecPtr, index) 601 | if val.is_some { 602 | return val.val 603 | } else { 604 | return nil 605 | } 606 | } 607 | 608 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 609 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i32$as_ptr(vecPtr))) 610 | } 611 | 612 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 613 | __swift_bridge__$Vec_i32$len(vecPtr) 614 | } 615 | } 616 | 617 | extension Int64: Vectorizable { 618 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 619 | __swift_bridge__$Vec_i64$new() 620 | } 621 | 622 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 623 | __swift_bridge__$Vec_i64$_free(vecPtr) 624 | } 625 | 626 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 627 | __swift_bridge__$Vec_i64$push(vecPtr, value) 628 | } 629 | 630 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 631 | let val = __swift_bridge__$Vec_i64$pop(vecPtr) 632 | if val.is_some { 633 | return val.val 634 | } else { 635 | return nil 636 | } 637 | } 638 | 639 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 640 | let val = __swift_bridge__$Vec_i64$get(vecPtr, index) 641 | if val.is_some { 642 | return val.val 643 | } else { 644 | return nil 645 | } 646 | } 647 | 648 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 649 | let val = __swift_bridge__$Vec_i64$get_mut(vecPtr, index) 650 | if val.is_some { 651 | return val.val 652 | } else { 653 | return nil 654 | } 655 | } 656 | 657 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 658 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i64$as_ptr(vecPtr))) 659 | } 660 | 661 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 662 | __swift_bridge__$Vec_i64$len(vecPtr) 663 | } 664 | } 665 | 666 | extension Int: Vectorizable { 667 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 668 | __swift_bridge__$Vec_isize$new() 669 | } 670 | 671 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 672 | __swift_bridge__$Vec_isize$_free(vecPtr) 673 | } 674 | 675 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 676 | __swift_bridge__$Vec_isize$push(vecPtr, value) 677 | } 678 | 679 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 680 | let val = __swift_bridge__$Vec_isize$pop(vecPtr) 681 | if val.is_some { 682 | return val.val 683 | } else { 684 | return nil 685 | } 686 | } 687 | 688 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 689 | let val = __swift_bridge__$Vec_isize$get(vecPtr, index) 690 | if val.is_some { 691 | return val.val 692 | } else { 693 | return nil 694 | } 695 | } 696 | 697 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 698 | let val = __swift_bridge__$Vec_isize$get_mut(vecPtr, index) 699 | if val.is_some { 700 | return val.val 701 | } else { 702 | return nil 703 | } 704 | } 705 | 706 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 707 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_isize$as_ptr(vecPtr))) 708 | } 709 | 710 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 711 | __swift_bridge__$Vec_isize$len(vecPtr) 712 | } 713 | } 714 | 715 | extension Bool: Vectorizable { 716 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 717 | __swift_bridge__$Vec_bool$new() 718 | } 719 | 720 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 721 | __swift_bridge__$Vec_bool$_free(vecPtr) 722 | } 723 | 724 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 725 | __swift_bridge__$Vec_bool$push(vecPtr, value) 726 | } 727 | 728 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 729 | let val = __swift_bridge__$Vec_bool$pop(vecPtr) 730 | if val.is_some { 731 | return val.val 732 | } else { 733 | return nil 734 | } 735 | } 736 | 737 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 738 | let val = __swift_bridge__$Vec_bool$get(vecPtr, index) 739 | if val.is_some { 740 | return val.val 741 | } else { 742 | return nil 743 | } 744 | } 745 | 746 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 747 | let val = __swift_bridge__$Vec_bool$get_mut(vecPtr, index) 748 | if val.is_some { 749 | return val.val 750 | } else { 751 | return nil 752 | } 753 | } 754 | 755 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 756 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_bool$as_ptr(vecPtr))) 757 | } 758 | 759 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 760 | __swift_bridge__$Vec_bool$len(vecPtr) 761 | } 762 | } 763 | 764 | extension Float: Vectorizable { 765 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 766 | __swift_bridge__$Vec_f32$new() 767 | } 768 | 769 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 770 | __swift_bridge__$Vec_f32$_free(vecPtr) 771 | } 772 | 773 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 774 | __swift_bridge__$Vec_f32$push(vecPtr, value) 775 | } 776 | 777 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 778 | let val = __swift_bridge__$Vec_f32$pop(vecPtr) 779 | if val.is_some { 780 | return val.val 781 | } else { 782 | return nil 783 | } 784 | } 785 | 786 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 787 | let val = __swift_bridge__$Vec_f32$get(vecPtr, index) 788 | if val.is_some { 789 | return val.val 790 | } else { 791 | return nil 792 | } 793 | } 794 | 795 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 796 | let val = __swift_bridge__$Vec_f32$get_mut(vecPtr, index) 797 | if val.is_some { 798 | return val.val 799 | } else { 800 | return nil 801 | } 802 | } 803 | 804 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 805 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f32$as_ptr(vecPtr))) 806 | } 807 | 808 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 809 | __swift_bridge__$Vec_f32$len(vecPtr) 810 | } 811 | } 812 | 813 | extension Double: Vectorizable { 814 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 815 | __swift_bridge__$Vec_f64$new() 816 | } 817 | 818 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 819 | __swift_bridge__$Vec_f64$_free(vecPtr) 820 | } 821 | 822 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 823 | __swift_bridge__$Vec_f64$push(vecPtr, value) 824 | } 825 | 826 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 827 | let val = __swift_bridge__$Vec_f64$pop(vecPtr) 828 | if val.is_some { 829 | return val.val 830 | } else { 831 | return nil 832 | } 833 | } 834 | 835 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 836 | let val = __swift_bridge__$Vec_f64$get(vecPtr, index) 837 | if val.is_some { 838 | return val.val 839 | } else { 840 | return nil 841 | } 842 | } 843 | 844 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 845 | let val = __swift_bridge__$Vec_f64$get_mut(vecPtr, index) 846 | if val.is_some { 847 | return val.val 848 | } else { 849 | return nil 850 | } 851 | } 852 | 853 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 854 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f64$as_ptr(vecPtr))) 855 | } 856 | 857 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 858 | __swift_bridge__$Vec_f64$len(vecPtr) 859 | } 860 | } 861 | 862 | protocol SwiftBridgeGenericFreer { 863 | func rust_free(); 864 | } 865 | 866 | protocol SwiftBridgeGenericCopyTypeFfiRepr {} 867 | 868 | public class RustString: RustStringRefMut { 869 | var isOwned: Bool = true 870 | 871 | public override init(ptr: UnsafeMutableRawPointer) { 872 | super.init(ptr: ptr) 873 | } 874 | 875 | deinit { 876 | if isOwned { 877 | __swift_bridge__$RustString$_free(ptr) 878 | } 879 | } 880 | } 881 | extension RustString { 882 | public convenience init() { 883 | self.init(ptr: __swift_bridge__$RustString$new()) 884 | } 885 | 886 | public convenience init(_ str: GenericToRustStr) { 887 | self.init(ptr: str.toRustStr({ strAsRustStr in 888 | __swift_bridge__$RustString$new_with_str(strAsRustStr) 889 | })) 890 | } 891 | } 892 | public class RustStringRefMut: RustStringRef { 893 | public override init(ptr: UnsafeMutableRawPointer) { 894 | super.init(ptr: ptr) 895 | } 896 | } 897 | public class RustStringRef { 898 | var ptr: UnsafeMutableRawPointer 899 | 900 | public init(ptr: UnsafeMutableRawPointer) { 901 | self.ptr = ptr 902 | } 903 | } 904 | extension RustStringRef { 905 | public func len() -> UInt { 906 | __swift_bridge__$RustString$len(ptr) 907 | } 908 | 909 | public func as_str() -> RustStr { 910 | __swift_bridge__$RustString$as_str(ptr) 911 | } 912 | 913 | public func trim() -> RustStr { 914 | __swift_bridge__$RustString$trim(ptr) 915 | } 916 | } 917 | extension RustString: Vectorizable { 918 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 919 | __swift_bridge__$Vec_RustString$new() 920 | } 921 | 922 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 923 | __swift_bridge__$Vec_RustString$drop(vecPtr) 924 | } 925 | 926 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: RustString) { 927 | __swift_bridge__$Vec_RustString$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 928 | } 929 | 930 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 931 | let pointer = __swift_bridge__$Vec_RustString$pop(vecPtr) 932 | if pointer == nil { 933 | return nil 934 | } else { 935 | return (RustString(ptr: pointer!) as! Self) 936 | } 937 | } 938 | 939 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 940 | let pointer = __swift_bridge__$Vec_RustString$get(vecPtr, index) 941 | if pointer == nil { 942 | return nil 943 | } else { 944 | return RustStringRef(ptr: pointer!) 945 | } 946 | } 947 | 948 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 949 | let pointer = __swift_bridge__$Vec_RustString$get_mut(vecPtr, index) 950 | if pointer == nil { 951 | return nil 952 | } else { 953 | return RustStringRefMut(ptr: pointer!) 954 | } 955 | } 956 | 957 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 958 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_RustString$as_ptr(vecPtr))) 959 | } 960 | 961 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 962 | __swift_bridge__$Vec_RustString$len(vecPtr) 963 | } 964 | } 965 | 966 | public class __private__RustFnOnceCallbackNoArgsNoRet { 967 | var ptr: UnsafeMutableRawPointer 968 | var called = false 969 | 970 | init(ptr: UnsafeMutableRawPointer) { 971 | self.ptr = ptr 972 | } 973 | 974 | deinit { 975 | if !called { 976 | __swift_bridge__$free_boxed_fn_once_no_args_no_return(ptr) 977 | } 978 | } 979 | 980 | func call() { 981 | if called { 982 | fatalError("Cannot call a Rust FnOnce function twice") 983 | } 984 | called = true 985 | return __swift_bridge__$call_boxed_fn_once_no_args_no_return(ptr) 986 | } 987 | } 988 | 989 | 990 | public enum RustResult { 991 | case Ok(T) 992 | case Err(E) 993 | } 994 | 995 | extension RustResult { 996 | func ok() -> T? { 997 | switch self { 998 | case .Ok(let ok): 999 | return ok 1000 | case .Err(_): 1001 | return nil 1002 | } 1003 | } 1004 | 1005 | func err() -> E? { 1006 | switch self { 1007 | case .Ok(_): 1008 | return nil 1009 | case .Err(let err): 1010 | return err 1011 | } 1012 | } 1013 | 1014 | func toResult() -> Result 1015 | where E: Error { 1016 | switch self { 1017 | case .Ok(let ok): 1018 | return .success(ok) 1019 | case .Err(let err): 1020 | return .failure(err) 1021 | } 1022 | } 1023 | } 1024 | 1025 | 1026 | extension __private__OptionU8 { 1027 | func intoSwiftRepr() -> Optional { 1028 | if self.is_some { 1029 | return self.val 1030 | } else { 1031 | return nil 1032 | } 1033 | } 1034 | 1035 | init(_ val: Optional) { 1036 | if let val = val { 1037 | self = Self(val: val, is_some: true) 1038 | } else { 1039 | self = Self(val: 123, is_some: false) 1040 | } 1041 | } 1042 | } 1043 | extension Optional where Wrapped == UInt8 { 1044 | func intoFfiRepr() -> __private__OptionU8 { 1045 | __private__OptionU8(self) 1046 | } 1047 | } 1048 | 1049 | extension __private__OptionI8 { 1050 | func intoSwiftRepr() -> Optional { 1051 | if self.is_some { 1052 | return self.val 1053 | } else { 1054 | return nil 1055 | } 1056 | } 1057 | 1058 | init(_ val: Optional) { 1059 | if let val = val { 1060 | self = Self(val: val, is_some: true) 1061 | } else { 1062 | self = Self(val: 123, is_some: false) 1063 | } 1064 | } 1065 | } 1066 | extension Optional where Wrapped == Int8 { 1067 | func intoFfiRepr() -> __private__OptionI8 { 1068 | __private__OptionI8(self) 1069 | } 1070 | } 1071 | 1072 | extension __private__OptionU16 { 1073 | func intoSwiftRepr() -> Optional { 1074 | if self.is_some { 1075 | return self.val 1076 | } else { 1077 | return nil 1078 | } 1079 | } 1080 | 1081 | init(_ val: Optional) { 1082 | if let val = val { 1083 | self = Self(val: val, is_some: true) 1084 | } else { 1085 | self = Self(val: 123, is_some: false) 1086 | } 1087 | } 1088 | } 1089 | extension Optional where Wrapped == UInt16 { 1090 | func intoFfiRepr() -> __private__OptionU16 { 1091 | __private__OptionU16(self) 1092 | } 1093 | } 1094 | 1095 | extension __private__OptionI16 { 1096 | func intoSwiftRepr() -> Optional { 1097 | if self.is_some { 1098 | return self.val 1099 | } else { 1100 | return nil 1101 | } 1102 | } 1103 | 1104 | init(_ val: Optional) { 1105 | if let val = val { 1106 | self = Self(val: val, is_some: true) 1107 | } else { 1108 | self = Self(val: 123, is_some: false) 1109 | } 1110 | } 1111 | } 1112 | extension Optional where Wrapped == Int16 { 1113 | func intoFfiRepr() -> __private__OptionI16 { 1114 | __private__OptionI16(self) 1115 | } 1116 | } 1117 | 1118 | extension __private__OptionU32 { 1119 | func intoSwiftRepr() -> Optional { 1120 | if self.is_some { 1121 | return self.val 1122 | } else { 1123 | return nil 1124 | } 1125 | } 1126 | 1127 | init(_ val: Optional) { 1128 | if let val = val { 1129 | self = Self(val: val, is_some: true) 1130 | } else { 1131 | self = Self(val: 123, is_some: false) 1132 | } 1133 | } 1134 | } 1135 | extension Optional where Wrapped == UInt32 { 1136 | func intoFfiRepr() -> __private__OptionU32 { 1137 | __private__OptionU32(self) 1138 | } 1139 | } 1140 | 1141 | extension __private__OptionI32 { 1142 | func intoSwiftRepr() -> Optional { 1143 | if self.is_some { 1144 | return self.val 1145 | } else { 1146 | return nil 1147 | } 1148 | } 1149 | 1150 | init(_ val: Optional) { 1151 | if let val = val { 1152 | self = Self(val: val, is_some: true) 1153 | } else { 1154 | self = Self(val: 123, is_some: false) 1155 | } 1156 | } 1157 | } 1158 | extension Optional where Wrapped == Int32 { 1159 | func intoFfiRepr() -> __private__OptionI32 { 1160 | __private__OptionI32(self) 1161 | } 1162 | } 1163 | 1164 | extension __private__OptionU64 { 1165 | func intoSwiftRepr() -> Optional { 1166 | if self.is_some { 1167 | return self.val 1168 | } else { 1169 | return nil 1170 | } 1171 | } 1172 | 1173 | init(_ val: Optional) { 1174 | if let val = val { 1175 | self = Self(val: val, is_some: true) 1176 | } else { 1177 | self = Self(val: 123, is_some: false) 1178 | } 1179 | } 1180 | } 1181 | extension Optional where Wrapped == UInt64 { 1182 | func intoFfiRepr() -> __private__OptionU64 { 1183 | __private__OptionU64(self) 1184 | } 1185 | } 1186 | 1187 | extension __private__OptionI64 { 1188 | func intoSwiftRepr() -> Optional { 1189 | if self.is_some { 1190 | return self.val 1191 | } else { 1192 | return nil 1193 | } 1194 | } 1195 | 1196 | init(_ val: Optional) { 1197 | if let val = val { 1198 | self = Self(val: val, is_some: true) 1199 | } else { 1200 | self = Self(val: 123, is_some: false) 1201 | } 1202 | } 1203 | } 1204 | extension Optional where Wrapped == Int64 { 1205 | func intoFfiRepr() -> __private__OptionI64 { 1206 | __private__OptionI64(self) 1207 | } 1208 | } 1209 | 1210 | extension __private__OptionUsize { 1211 | func intoSwiftRepr() -> Optional { 1212 | if self.is_some { 1213 | return self.val 1214 | } else { 1215 | return nil 1216 | } 1217 | } 1218 | 1219 | init(_ val: Optional) { 1220 | if let val = val { 1221 | self = Self(val: val, is_some: true) 1222 | } else { 1223 | self = Self(val: 123, is_some: false) 1224 | } 1225 | } 1226 | } 1227 | extension Optional where Wrapped == UInt { 1228 | func intoFfiRepr() -> __private__OptionUsize { 1229 | __private__OptionUsize(self) 1230 | } 1231 | } 1232 | 1233 | extension __private__OptionIsize { 1234 | func intoSwiftRepr() -> Optional { 1235 | if self.is_some { 1236 | return self.val 1237 | } else { 1238 | return nil 1239 | } 1240 | } 1241 | 1242 | init(_ val: Optional) { 1243 | if let val = val { 1244 | self = Self(val: val, is_some: true) 1245 | } else { 1246 | self = Self(val: 123, is_some: false) 1247 | } 1248 | } 1249 | } 1250 | extension Optional where Wrapped == Int { 1251 | func intoFfiRepr() -> __private__OptionIsize { 1252 | __private__OptionIsize(self) 1253 | } 1254 | } 1255 | 1256 | extension __private__OptionF32 { 1257 | func intoSwiftRepr() -> Optional { 1258 | if self.is_some { 1259 | return self.val 1260 | } else { 1261 | return nil 1262 | } 1263 | } 1264 | 1265 | init(_ val: Optional) { 1266 | if let val = val { 1267 | self = Self(val: val, is_some: true) 1268 | } else { 1269 | self = Self(val: 123.4, is_some: false) 1270 | } 1271 | } 1272 | } 1273 | extension Optional where Wrapped == Float { 1274 | func intoFfiRepr() -> __private__OptionF32 { 1275 | __private__OptionF32(self) 1276 | } 1277 | } 1278 | 1279 | extension __private__OptionF64 { 1280 | func intoSwiftRepr() -> Optional { 1281 | if self.is_some { 1282 | return self.val 1283 | } else { 1284 | return nil 1285 | } 1286 | } 1287 | 1288 | init(_ val: Optional) { 1289 | if let val = val { 1290 | self = Self(val: val, is_some: true) 1291 | } else { 1292 | self = Self(val: 123.4, is_some: false) 1293 | } 1294 | } 1295 | } 1296 | extension Optional where Wrapped == Double { 1297 | func intoFfiRepr() -> __private__OptionF64 { 1298 | __private__OptionF64(self) 1299 | } 1300 | } 1301 | 1302 | extension __private__OptionBool { 1303 | func intoSwiftRepr() -> Optional { 1304 | if self.is_some { 1305 | return self.val 1306 | } else { 1307 | return nil 1308 | } 1309 | } 1310 | 1311 | init(_ val: Optional) { 1312 | if let val = val { 1313 | self = Self(val: val, is_some: true) 1314 | } else { 1315 | self = Self(val: false, is_some: false) 1316 | } 1317 | } 1318 | } 1319 | extension Optional where Wrapped == Bool { 1320 | func intoFfiRepr() -> __private__OptionBool { 1321 | __private__OptionBool(self) 1322 | } 1323 | } 1324 | -------------------------------------------------------------------------------- /smooth-ui/SmoothUI/Sources/SmoothUI/smooth-ui.swift: -------------------------------------------------------------------------------- 1 | import RustXcframework 2 | @_cdecl("__swift_bridge__$BaseChatController$bubbles_count") 3 | func __swift_bridge__BaseChatController_bubbles_count (_ this: UnsafeMutableRawPointer) -> UInt { 4 | Unmanaged.fromOpaque(this).takeUnretainedValue().bubbles_count() 5 | } 6 | 7 | @_cdecl("__swift_bridge__$BaseChatController$bubble_at_index") 8 | func __swift_bridge__BaseChatController_bubble_at_index (_ this: UnsafeMutableRawPointer, _ index: UInt) -> __swift_bridge__$ChatBubble { 9 | Unmanaged.fromOpaque(this).takeUnretainedValue().bubble_at_index(index: index).intoFfiRepr() 10 | } 11 | 12 | public struct ChatBubble { 13 | public var sender: RustString 14 | public var text: RustString 15 | 16 | public init(sender: RustString,text: RustString) { 17 | self.sender = sender 18 | self.text = text 19 | } 20 | 21 | @inline(__always) 22 | func intoFfiRepr() -> __swift_bridge__$ChatBubble { 23 | { let val = self; return __swift_bridge__$ChatBubble(sender: { let rustString = val.sender.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), text: { let rustString = val.text.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); }() 24 | } 25 | } 26 | extension __swift_bridge__$ChatBubble { 27 | @inline(__always) 28 | func intoSwiftRepr() -> ChatBubble { 29 | { let val = self; return ChatBubble(sender: RustString(ptr: val.sender), text: RustString(ptr: val.text)); }() 30 | } 31 | } 32 | extension __swift_bridge__$Option$ChatBubble { 33 | @inline(__always) 34 | func intoSwiftRepr() -> Optional { 35 | if self.is_some { 36 | return self.val.intoSwiftRepr() 37 | } else { 38 | return nil 39 | } 40 | } 41 | 42 | @inline(__always) 43 | static func fromSwiftRepr(_ val: Optional) -> __swift_bridge__$Option$ChatBubble { 44 | if let v = val { 45 | return __swift_bridge__$Option$ChatBubble(is_some: true, val: v.intoFfiRepr()) 46 | } else { 47 | return __swift_bridge__$Option$ChatBubble(is_some: false, val: __swift_bridge__$ChatBubble()) 48 | } 49 | } 50 | } 51 | 52 | public class InputEvent: InputEventRefMut { 53 | var isOwned: Bool = true 54 | 55 | public override init(ptr: UnsafeMutableRawPointer) { 56 | super.init(ptr: ptr) 57 | } 58 | 59 | deinit { 60 | if isOwned { 61 | __swift_bridge__$InputEvent$_free(ptr) 62 | } 63 | } 64 | } 65 | extension InputEvent { 66 | class public func from_pointer_moved(_ x: Float, _ y: Float) -> InputEvent { 67 | InputEvent(ptr: __swift_bridge__$InputEvent$from_pointer_moved(x, y)) 68 | } 69 | 70 | class public func from_mouse_wheel(_ x: Float, _ y: Float) -> InputEvent { 71 | InputEvent(ptr: __swift_bridge__$InputEvent$from_mouse_wheel(x, y)) 72 | } 73 | 74 | class public func from_left_mouse_down(_ x: Float, _ y: Float, _ pressed: Bool) -> InputEvent { 75 | InputEvent(ptr: __swift_bridge__$InputEvent$from_left_mouse_down(x, y, pressed)) 76 | } 77 | 78 | class public func from_right_mouse_down(_ x: Float, _ y: Float, _ pressed: Bool) -> InputEvent { 79 | InputEvent(ptr: __swift_bridge__$InputEvent$from_right_mouse_down(x, y, pressed)) 80 | } 81 | 82 | class public func from_window_focused(_ focused: Bool) -> InputEvent { 83 | InputEvent(ptr: __swift_bridge__$InputEvent$from_window_focused(focused)) 84 | } 85 | } 86 | public class InputEventRefMut: InputEventRef { 87 | public override init(ptr: UnsafeMutableRawPointer) { 88 | super.init(ptr: ptr) 89 | } 90 | } 91 | public class InputEventRef { 92 | var ptr: UnsafeMutableRawPointer 93 | 94 | public init(ptr: UnsafeMutableRawPointer) { 95 | self.ptr = ptr 96 | } 97 | } 98 | extension InputEvent: Vectorizable { 99 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 100 | __swift_bridge__$Vec_InputEvent$new() 101 | } 102 | 103 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 104 | __swift_bridge__$Vec_InputEvent$drop(vecPtr) 105 | } 106 | 107 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: InputEvent) { 108 | __swift_bridge__$Vec_InputEvent$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 109 | } 110 | 111 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 112 | let pointer = __swift_bridge__$Vec_InputEvent$pop(vecPtr) 113 | if pointer == nil { 114 | return nil 115 | } else { 116 | return (InputEvent(ptr: pointer!) as! Self) 117 | } 118 | } 119 | 120 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 121 | let pointer = __swift_bridge__$Vec_InputEvent$get(vecPtr, index) 122 | if pointer == nil { 123 | return nil 124 | } else { 125 | return InputEventRef(ptr: pointer!) 126 | } 127 | } 128 | 129 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 130 | let pointer = __swift_bridge__$Vec_InputEvent$get_mut(vecPtr, index) 131 | if pointer == nil { 132 | return nil 133 | } else { 134 | return InputEventRefMut(ptr: pointer!) 135 | } 136 | } 137 | 138 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 139 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_InputEvent$as_ptr(vecPtr))) 140 | } 141 | 142 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 143 | __swift_bridge__$Vec_InputEvent$len(vecPtr) 144 | } 145 | } 146 | 147 | 148 | public class OutputState: OutputStateRefMut { 149 | var isOwned: Bool = true 150 | 151 | public override init(ptr: UnsafeMutableRawPointer) { 152 | super.init(ptr: ptr) 153 | } 154 | 155 | deinit { 156 | if isOwned { 157 | __swift_bridge__$OutputState$_free(ptr) 158 | } 159 | } 160 | } 161 | public class OutputStateRefMut: OutputStateRef { 162 | public override init(ptr: UnsafeMutableRawPointer) { 163 | super.init(ptr: ptr) 164 | } 165 | } 166 | public class OutputStateRef { 167 | var ptr: UnsafeMutableRawPointer 168 | 169 | public init(ptr: UnsafeMutableRawPointer) { 170 | self.ptr = ptr 171 | } 172 | } 173 | extension OutputStateRef { 174 | public func get_cursor_icon() -> CursorIconRef { 175 | CursorIconRef(ptr: __swift_bridge__$OutputState$get_cursor_icon(ptr)) 176 | } 177 | } 178 | extension OutputState: Vectorizable { 179 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 180 | __swift_bridge__$Vec_OutputState$new() 181 | } 182 | 183 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 184 | __swift_bridge__$Vec_OutputState$drop(vecPtr) 185 | } 186 | 187 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: OutputState) { 188 | __swift_bridge__$Vec_OutputState$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 189 | } 190 | 191 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 192 | let pointer = __swift_bridge__$Vec_OutputState$pop(vecPtr) 193 | if pointer == nil { 194 | return nil 195 | } else { 196 | return (OutputState(ptr: pointer!) as! Self) 197 | } 198 | } 199 | 200 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 201 | let pointer = __swift_bridge__$Vec_OutputState$get(vecPtr, index) 202 | if pointer == nil { 203 | return nil 204 | } else { 205 | return OutputStateRef(ptr: pointer!) 206 | } 207 | } 208 | 209 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 210 | let pointer = __swift_bridge__$Vec_OutputState$get_mut(vecPtr, index) 211 | if pointer == nil { 212 | return nil 213 | } else { 214 | return OutputStateRefMut(ptr: pointer!) 215 | } 216 | } 217 | 218 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 219 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_OutputState$as_ptr(vecPtr))) 220 | } 221 | 222 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 223 | __swift_bridge__$Vec_OutputState$len(vecPtr) 224 | } 225 | } 226 | 227 | 228 | public class CursorIcon: CursorIconRefMut { 229 | var isOwned: Bool = true 230 | 231 | public override init(ptr: UnsafeMutableRawPointer) { 232 | super.init(ptr: ptr) 233 | } 234 | 235 | deinit { 236 | if isOwned { 237 | __swift_bridge__$CursorIcon$_free(ptr) 238 | } 239 | } 240 | } 241 | public class CursorIconRefMut: CursorIconRef { 242 | public override init(ptr: UnsafeMutableRawPointer) { 243 | super.init(ptr: ptr) 244 | } 245 | } 246 | public class CursorIconRef { 247 | var ptr: UnsafeMutableRawPointer 248 | 249 | public init(ptr: UnsafeMutableRawPointer) { 250 | self.ptr = ptr 251 | } 252 | } 253 | extension CursorIconRef { 254 | public func is_default() -> Bool { 255 | __swift_bridge__$CursorIcon$is_default(ptr) 256 | } 257 | 258 | public func is_pointing_hand() -> Bool { 259 | __swift_bridge__$CursorIcon$is_pointing_hand(ptr) 260 | } 261 | 262 | public func is_resize_horizontal() -> Bool { 263 | __swift_bridge__$CursorIcon$is_resize_horizontal(ptr) 264 | } 265 | 266 | public func is_resize_vertical() -> Bool { 267 | __swift_bridge__$CursorIcon$is_resize_vertical(ptr) 268 | } 269 | 270 | public func is_text() -> Bool { 271 | __swift_bridge__$CursorIcon$is_text(ptr) 272 | } 273 | } 274 | extension CursorIcon: Vectorizable { 275 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 276 | __swift_bridge__$Vec_CursorIcon$new() 277 | } 278 | 279 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 280 | __swift_bridge__$Vec_CursorIcon$drop(vecPtr) 281 | } 282 | 283 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: CursorIcon) { 284 | __swift_bridge__$Vec_CursorIcon$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 285 | } 286 | 287 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 288 | let pointer = __swift_bridge__$Vec_CursorIcon$pop(vecPtr) 289 | if pointer == nil { 290 | return nil 291 | } else { 292 | return (CursorIcon(ptr: pointer!) as! Self) 293 | } 294 | } 295 | 296 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 297 | let pointer = __swift_bridge__$Vec_CursorIcon$get(vecPtr, index) 298 | if pointer == nil { 299 | return nil 300 | } else { 301 | return CursorIconRef(ptr: pointer!) 302 | } 303 | } 304 | 305 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 306 | let pointer = __swift_bridge__$Vec_CursorIcon$get_mut(vecPtr, index) 307 | if pointer == nil { 308 | return nil 309 | } else { 310 | return CursorIconRefMut(ptr: pointer!) 311 | } 312 | } 313 | 314 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 315 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_CursorIcon$as_ptr(vecPtr))) 316 | } 317 | 318 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 319 | __swift_bridge__$Vec_CursorIcon$len(vecPtr) 320 | } 321 | } 322 | 323 | 324 | public class Renderer: RendererRefMut { 325 | var isOwned: Bool = true 326 | 327 | public override init(ptr: UnsafeMutableRawPointer) { 328 | super.init(ptr: ptr) 329 | } 330 | 331 | deinit { 332 | if isOwned { 333 | __swift_bridge__$Renderer$_free(ptr) 334 | } 335 | } 336 | } 337 | extension Renderer { 338 | public convenience init(_ layer_ptr: UnsafeMutableRawPointer, _ width: UInt32, _ height: UInt32, _ display_scale: Float) { 339 | self.init(ptr: __swift_bridge__$Renderer$new(layer_ptr, width, height, display_scale)) 340 | } 341 | } 342 | public class RendererRefMut: RendererRef { 343 | public override init(ptr: UnsafeMutableRawPointer) { 344 | super.init(ptr: ptr) 345 | } 346 | } 347 | extension RendererRefMut { 348 | public func resize(_ width: UInt32, _ height: UInt32) { 349 | __swift_bridge__$Renderer$resize(ptr, width, height) 350 | } 351 | 352 | public func render(_ time: Double, _ input_events: RustVec, _ controller: BaseChatController) -> OutputState { 353 | OutputState(ptr: __swift_bridge__$Renderer$render(ptr, time, { let val = input_events; val.isOwned = false; return val.ptr }(), Unmanaged.passRetained(controller).toOpaque())) 354 | } 355 | } 356 | public class RendererRef { 357 | var ptr: UnsafeMutableRawPointer 358 | 359 | public init(ptr: UnsafeMutableRawPointer) { 360 | self.ptr = ptr 361 | } 362 | } 363 | extension Renderer: Vectorizable { 364 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 365 | __swift_bridge__$Vec_Renderer$new() 366 | } 367 | 368 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 369 | __swift_bridge__$Vec_Renderer$drop(vecPtr) 370 | } 371 | 372 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Renderer) { 373 | __swift_bridge__$Vec_Renderer$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 374 | } 375 | 376 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 377 | let pointer = __swift_bridge__$Vec_Renderer$pop(vecPtr) 378 | if pointer == nil { 379 | return nil 380 | } else { 381 | return (Renderer(ptr: pointer!) as! Self) 382 | } 383 | } 384 | 385 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 386 | let pointer = __swift_bridge__$Vec_Renderer$get(vecPtr, index) 387 | if pointer == nil { 388 | return nil 389 | } else { 390 | return RendererRef(ptr: pointer!) 391 | } 392 | } 393 | 394 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 395 | let pointer = __swift_bridge__$Vec_Renderer$get_mut(vecPtr, index) 396 | if pointer == nil { 397 | return nil 398 | } else { 399 | return RendererRefMut(ptr: pointer!) 400 | } 401 | } 402 | 403 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 404 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_Renderer$as_ptr(vecPtr))) 405 | } 406 | 407 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 408 | __swift_bridge__$Vec_Renderer$len(vecPtr) 409 | } 410 | } 411 | 412 | 413 | @_cdecl("__swift_bridge__$BaseChatController$_free") 414 | func __swift_bridge__BaseChatController__free (ptr: UnsafeMutableRawPointer) { 415 | let _ = Unmanaged.fromOpaque(ptr).takeRetainedValue() 416 | } 417 | 418 | 419 | 420 | -------------------------------------------------------------------------------- /smooth-ui/build.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | 3 | fn main() { 4 | let out_dir = PathBuf::from("./generated"); 5 | 6 | let bridges = vec!["src/ffi.rs"]; 7 | for path in &bridges { 8 | println!("cargo:rerun-if-changed={}", path); 9 | } 10 | 11 | swift_bridge_build::parse_bridges(bridges) 12 | .write_all_concatenated(out_dir, env!("CARGO_PKG_NAME")); 13 | } -------------------------------------------------------------------------------- /smooth-ui/generated/SwiftBridgeCore.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | typedef struct RustStr { uint8_t* const start; uintptr_t len; } RustStr; 4 | typedef struct __private__FfiSlice { void* const start; uintptr_t len; } __private__FfiSlice; 5 | void* __swift_bridge__null_pointer(void); 6 | 7 | 8 | typedef struct __private__OptionU8 { uint8_t val; bool is_some; } __private__OptionU8; 9 | typedef struct __private__OptionI8 { int8_t val; bool is_some; } __private__OptionI8; 10 | typedef struct __private__OptionU16 { uint16_t val; bool is_some; } __private__OptionU16; 11 | typedef struct __private__OptionI16 { int16_t val; bool is_some; } __private__OptionI16; 12 | typedef struct __private__OptionU32 { uint32_t val; bool is_some; } __private__OptionU32; 13 | typedef struct __private__OptionI32 { int32_t val; bool is_some; } __private__OptionI32; 14 | typedef struct __private__OptionU64 { uint64_t val; bool is_some; } __private__OptionU64; 15 | typedef struct __private__OptionI64 { int64_t val; bool is_some; } __private__OptionI64; 16 | typedef struct __private__OptionUsize { uintptr_t val; bool is_some; } __private__OptionUsize; 17 | typedef struct __private__OptionIsize { intptr_t val; bool is_some; } __private__OptionIsize; 18 | typedef struct __private__OptionF32 { float val; bool is_some; } __private__OptionF32; 19 | typedef struct __private__OptionF64 { double val; bool is_some; } __private__OptionF64; 20 | typedef struct __private__OptionBool { bool val; bool is_some; } __private__OptionBool; 21 | 22 | void* __swift_bridge__$Vec_u8$new(); 23 | void __swift_bridge__$Vec_u8$_free(void* const vec); 24 | uintptr_t __swift_bridge__$Vec_u8$len(void* const vec); 25 | void __swift_bridge__$Vec_u8$push(void* const vec, uint8_t val); 26 | __private__OptionU8 __swift_bridge__$Vec_u8$pop(void* const vec); 27 | __private__OptionU8 __swift_bridge__$Vec_u8$get(void* const vec, uintptr_t index); 28 | __private__OptionU8 __swift_bridge__$Vec_u8$get_mut(void* const vec, uintptr_t index); 29 | uint8_t const * __swift_bridge__$Vec_u8$as_ptr(void* const vec); 30 | 31 | void* __swift_bridge__$Vec_u16$new(); 32 | void __swift_bridge__$Vec_u16$_free(void* const vec); 33 | uintptr_t __swift_bridge__$Vec_u16$len(void* const vec); 34 | void __swift_bridge__$Vec_u16$push(void* const vec, uint16_t val); 35 | __private__OptionU16 __swift_bridge__$Vec_u16$pop(void* const vec); 36 | __private__OptionU16 __swift_bridge__$Vec_u16$get(void* const vec, uintptr_t index); 37 | __private__OptionU16 __swift_bridge__$Vec_u16$get_mut(void* const vec, uintptr_t index); 38 | uint16_t const * __swift_bridge__$Vec_u16$as_ptr(void* const vec); 39 | 40 | void* __swift_bridge__$Vec_u32$new(); 41 | void __swift_bridge__$Vec_u32$_free(void* const vec); 42 | uintptr_t __swift_bridge__$Vec_u32$len(void* const vec); 43 | void __swift_bridge__$Vec_u32$push(void* const vec, uint32_t val); 44 | __private__OptionU32 __swift_bridge__$Vec_u32$pop(void* const vec); 45 | __private__OptionU32 __swift_bridge__$Vec_u32$get(void* const vec, uintptr_t index); 46 | __private__OptionU32 __swift_bridge__$Vec_u32$get_mut(void* const vec, uintptr_t index); 47 | uint32_t const * __swift_bridge__$Vec_u32$as_ptr(void* const vec); 48 | 49 | void* __swift_bridge__$Vec_u64$new(); 50 | void __swift_bridge__$Vec_u64$_free(void* const vec); 51 | uintptr_t __swift_bridge__$Vec_u64$len(void* const vec); 52 | void __swift_bridge__$Vec_u64$push(void* const vec, uint64_t val); 53 | __private__OptionU64 __swift_bridge__$Vec_u64$pop(void* const vec); 54 | __private__OptionU64 __swift_bridge__$Vec_u64$get(void* const vec, uintptr_t index); 55 | __private__OptionU64 __swift_bridge__$Vec_u64$get_mut(void* const vec, uintptr_t index); 56 | uint64_t const * __swift_bridge__$Vec_u64$as_ptr(void* const vec); 57 | 58 | void* __swift_bridge__$Vec_usize$new(); 59 | void __swift_bridge__$Vec_usize$_free(void* const vec); 60 | uintptr_t __swift_bridge__$Vec_usize$len(void* const vec); 61 | void __swift_bridge__$Vec_usize$push(void* const vec, uintptr_t val); 62 | __private__OptionUsize __swift_bridge__$Vec_usize$pop(void* const vec); 63 | __private__OptionUsize __swift_bridge__$Vec_usize$get(void* const vec, uintptr_t index); 64 | __private__OptionUsize __swift_bridge__$Vec_usize$get_mut(void* const vec, uintptr_t index); 65 | uintptr_t const * __swift_bridge__$Vec_usize$as_ptr(void* const vec); 66 | 67 | void* __swift_bridge__$Vec_i8$new(); 68 | void __swift_bridge__$Vec_i8$_free(void* const vec); 69 | uintptr_t __swift_bridge__$Vec_i8$len(void* const vec); 70 | void __swift_bridge__$Vec_i8$push(void* const vec, int8_t val); 71 | __private__OptionI8 __swift_bridge__$Vec_i8$pop(void* const vec); 72 | __private__OptionI8 __swift_bridge__$Vec_i8$get(void* const vec, uintptr_t index); 73 | __private__OptionI8 __swift_bridge__$Vec_i8$get_mut(void* const vec, uintptr_t index); 74 | int8_t const * __swift_bridge__$Vec_i8$as_ptr(void* const vec); 75 | 76 | void* __swift_bridge__$Vec_i16$new(); 77 | void __swift_bridge__$Vec_i16$_free(void* const vec); 78 | uintptr_t __swift_bridge__$Vec_i16$len(void* const vec); 79 | void __swift_bridge__$Vec_i16$push(void* const vec, int16_t val); 80 | __private__OptionI16 __swift_bridge__$Vec_i16$pop(void* const vec); 81 | __private__OptionI16 __swift_bridge__$Vec_i16$get(void* const vec, uintptr_t index); 82 | __private__OptionI16 __swift_bridge__$Vec_i16$get_mut(void* const vec, uintptr_t index); 83 | int16_t const * __swift_bridge__$Vec_i16$as_ptr(void* const vec); 84 | 85 | void* __swift_bridge__$Vec_i32$new(); 86 | void __swift_bridge__$Vec_i32$_free(void* const vec); 87 | uintptr_t __swift_bridge__$Vec_i32$len(void* const vec); 88 | void __swift_bridge__$Vec_i32$push(void* const vec, int32_t val); 89 | __private__OptionI32 __swift_bridge__$Vec_i32$pop(void* const vec); 90 | __private__OptionI32 __swift_bridge__$Vec_i32$get(void* const vec, uintptr_t index); 91 | __private__OptionI32 __swift_bridge__$Vec_i32$get_mut(void* const vec, uintptr_t index); 92 | int32_t const * __swift_bridge__$Vec_i32$as_ptr(void* const vec); 93 | 94 | void* __swift_bridge__$Vec_i64$new(); 95 | void __swift_bridge__$Vec_i64$_free(void* const vec); 96 | uintptr_t __swift_bridge__$Vec_i64$len(void* const vec); 97 | void __swift_bridge__$Vec_i64$push(void* const vec, int64_t val); 98 | __private__OptionI64 __swift_bridge__$Vec_i64$pop(void* const vec); 99 | __private__OptionI64 __swift_bridge__$Vec_i64$get(void* const vec, uintptr_t index); 100 | __private__OptionI64 __swift_bridge__$Vec_i64$get_mut(void* const vec, uintptr_t index); 101 | int64_t const * __swift_bridge__$Vec_i64$as_ptr(void* const vec); 102 | 103 | void* __swift_bridge__$Vec_isize$new(); 104 | void __swift_bridge__$Vec_isize$_free(void* const vec); 105 | uintptr_t __swift_bridge__$Vec_isize$len(void* const vec); 106 | void __swift_bridge__$Vec_isize$push(void* const vec, intptr_t val); 107 | __private__OptionIsize __swift_bridge__$Vec_isize$pop(void* const vec); 108 | __private__OptionIsize __swift_bridge__$Vec_isize$get(void* const vec, uintptr_t index); 109 | __private__OptionIsize __swift_bridge__$Vec_isize$get_mut(void* const vec, uintptr_t index); 110 | intptr_t const * __swift_bridge__$Vec_isize$as_ptr(void* const vec); 111 | 112 | void* __swift_bridge__$Vec_bool$new(); 113 | void __swift_bridge__$Vec_bool$_free(void* const vec); 114 | uintptr_t __swift_bridge__$Vec_bool$len(void* const vec); 115 | void __swift_bridge__$Vec_bool$push(void* const vec, bool val); 116 | __private__OptionBool __swift_bridge__$Vec_bool$pop(void* const vec); 117 | __private__OptionBool __swift_bridge__$Vec_bool$get(void* const vec, uintptr_t index); 118 | __private__OptionBool __swift_bridge__$Vec_bool$get_mut(void* const vec, uintptr_t index); 119 | bool const * __swift_bridge__$Vec_bool$as_ptr(void* const vec); 120 | 121 | void* __swift_bridge__$Vec_f32$new(); 122 | void __swift_bridge__$Vec_f32$_free(void* const vec); 123 | uintptr_t __swift_bridge__$Vec_f32$len(void* const vec); 124 | void __swift_bridge__$Vec_f32$push(void* const vec, float val); 125 | __private__OptionF32 __swift_bridge__$Vec_f32$pop(void* const vec); 126 | __private__OptionF32 __swift_bridge__$Vec_f32$get(void* const vec, uintptr_t index); 127 | __private__OptionF32 __swift_bridge__$Vec_f32$get_mut(void* const vec, uintptr_t index); 128 | float const * __swift_bridge__$Vec_f32$as_ptr(void* const vec); 129 | 130 | void* __swift_bridge__$Vec_f64$new(); 131 | void __swift_bridge__$Vec_f64$_free(void* const vec); 132 | uintptr_t __swift_bridge__$Vec_f64$len(void* const vec); 133 | void __swift_bridge__$Vec_f64$push(void* const vec, double val); 134 | __private__OptionF64 __swift_bridge__$Vec_f64$pop(void* const vec); 135 | __private__OptionF64 __swift_bridge__$Vec_f64$get(void* const vec, uintptr_t index); 136 | __private__OptionF64 __swift_bridge__$Vec_f64$get_mut(void* const vec, uintptr_t index); 137 | double const * __swift_bridge__$Vec_f64$as_ptr(void* const vec); 138 | 139 | #include 140 | typedef struct RustString RustString; 141 | void __swift_bridge__$RustString$_free(void* self); 142 | 143 | void* __swift_bridge__$Vec_RustString$new(void); 144 | void __swift_bridge__$Vec_RustString$drop(void* vec_ptr); 145 | void __swift_bridge__$Vec_RustString$push(void* vec_ptr, void* item_ptr); 146 | void* __swift_bridge__$Vec_RustString$pop(void* vec_ptr); 147 | void* __swift_bridge__$Vec_RustString$get(void* vec_ptr, uintptr_t index); 148 | void* __swift_bridge__$Vec_RustString$get_mut(void* vec_ptr, uintptr_t index); 149 | uintptr_t __swift_bridge__$Vec_RustString$len(void* vec_ptr); 150 | void* __swift_bridge__$Vec_RustString$as_ptr(void* vec_ptr); 151 | 152 | void* __swift_bridge__$RustString$new(void); 153 | void* __swift_bridge__$RustString$new_with_str(struct RustStr str); 154 | uintptr_t __swift_bridge__$RustString$len(void* self); 155 | struct RustStr __swift_bridge__$RustString$as_str(void* self); 156 | struct RustStr __swift_bridge__$RustString$trim(void* self); 157 | bool __swift_bridge__$RustStr$partial_eq(struct RustStr lhs, struct RustStr rhs); 158 | 159 | 160 | void __swift_bridge__$call_boxed_fn_once_no_args_no_return(void* boxed_fnonce); 161 | void __swift_bridge__$free_boxed_fn_once_no_args_no_return(void* boxed_fnonce); 162 | 163 | 164 | struct __private__ResultPtrAndPtr { bool is_ok; void* ok_or_err; }; 165 | -------------------------------------------------------------------------------- /smooth-ui/generated/SwiftBridgeCore.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension RustString { 4 | public func toString() -> String { 5 | let str = self.as_str() 6 | let string = str.toString() 7 | 8 | return string 9 | } 10 | } 11 | 12 | extension RustStr { 13 | func toBufferPointer() -> UnsafeBufferPointer { 14 | let bytes = UnsafeBufferPointer(start: self.start, count: Int(self.len)) 15 | return bytes 16 | } 17 | 18 | public func toString() -> String { 19 | let bytes = self.toBufferPointer() 20 | return String(bytes: bytes, encoding: .utf8)! 21 | } 22 | } 23 | extension RustStr: Identifiable { 24 | public var id: String { 25 | self.toString() 26 | } 27 | } 28 | extension RustStr: Equatable { 29 | public static func == (lhs: RustStr, rhs: RustStr) -> Bool { 30 | return __swift_bridge__$RustStr$partial_eq(lhs, rhs); 31 | } 32 | } 33 | 34 | public protocol IntoRustString { 35 | func intoRustString() -> RustString; 36 | } 37 | 38 | extension String: IntoRustString { 39 | public func intoRustString() -> RustString { 40 | // TODO: When passing an owned Swift std String to Rust we've being wasteful here in that 41 | // we're creating a RustString (which involves Boxing a Rust std::string::String) 42 | // only to unbox it back into a String once it gets to the Rust side. 43 | // 44 | // A better approach would be to pass a RustStr to the Rust side and then have Rust 45 | // call `.to_string()` on the RustStr. 46 | RustString(self) 47 | } 48 | } 49 | 50 | extension RustString: IntoRustString { 51 | public func intoRustString() -> RustString { 52 | self 53 | } 54 | } 55 | 56 | /// If the String is Some: 57 | /// Safely get a scoped pointer to the String and then call the callback with a RustStr 58 | /// that uses that pointer. 59 | /// 60 | /// If the String is None: 61 | /// Call the callback with a RustStr that has a null pointer. 62 | /// The Rust side will know to treat this as `None`. 63 | func optionalStringIntoRustString(_ string: Optional) -> RustString? { 64 | if let val = string { 65 | return val.intoRustString() 66 | } else { 67 | return nil 68 | } 69 | } 70 | 71 | /// Used to safely get a pointer to a sequence of utf8 bytes, represented as a `RustStr`. 72 | /// 73 | /// For example, the Swift `String` implementation of the `ToRustStr` protocol does the following: 74 | /// 1. Use Swift's `String.utf8.withUnsafeBufferPointer` to get a pointer to the strings underlying 75 | /// utf8 bytes. 76 | /// 2. Construct a `RustStr` that points to these utf8 bytes. This is safe because `withUnsafeBufferPointer` 77 | /// guarantees that the buffer pointer will be valid for the duration of the `withUnsafeBufferPointer` 78 | /// callback. 79 | /// 3. Pass the `RustStr` to the closure that was passed into `RustStr.toRustStr`. 80 | public protocol ToRustStr { 81 | func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T; 82 | } 83 | 84 | extension String: ToRustStr { 85 | /// Safely get a scoped pointer to the String and then call the callback with a RustStr 86 | /// that uses that pointer. 87 | public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { 88 | return self.utf8CString.withUnsafeBufferPointer({ bufferPtr in 89 | let rustStr = RustStr( 90 | start: UnsafeMutableRawPointer(mutating: bufferPtr.baseAddress!).assumingMemoryBound(to: UInt8.self), 91 | // Subtract 1 because of the null termination character at the end 92 | len: UInt(bufferPtr.count - 1) 93 | ) 94 | return withUnsafeRustStr(rustStr) 95 | }) 96 | } 97 | } 98 | 99 | extension RustStr: ToRustStr { 100 | public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { 101 | return withUnsafeRustStr(self) 102 | } 103 | } 104 | 105 | func optionalRustStrToRustStr(_ str: Optional, _ withUnsafeRustStr: (RustStr) -> T) -> T { 106 | if let val = str { 107 | return val.toRustStr(withUnsafeRustStr) 108 | } else { 109 | return withUnsafeRustStr(RustStr(start: nil, len: 0)) 110 | } 111 | } 112 | public class RustVec { 113 | var ptr: UnsafeMutableRawPointer 114 | var isOwned: Bool = true 115 | 116 | public init(ptr: UnsafeMutableRawPointer) { 117 | self.ptr = ptr 118 | } 119 | 120 | public init() { 121 | ptr = T.vecOfSelfNew() 122 | isOwned = true 123 | } 124 | 125 | public func push (value: T) { 126 | T.vecOfSelfPush(vecPtr: ptr, value: value) 127 | } 128 | 129 | public func pop () -> Optional { 130 | T.vecOfSelfPop(vecPtr: ptr) 131 | } 132 | 133 | public func get(index: UInt) -> Optional { 134 | T.vecOfSelfGet(vecPtr: ptr, index: index) 135 | } 136 | 137 | public func as_ptr() -> UnsafePointer { 138 | UnsafePointer(OpaquePointer(T.vecOfSelfAsPtr(vecPtr: ptr))) 139 | } 140 | 141 | /// Rust returns a UInt, but we cast to an Int because many Swift APIs such as 142 | /// `ForEach(0..rustVec.len())` expect Int. 143 | public func len() -> Int { 144 | Int(T.vecOfSelfLen(vecPtr: ptr)) 145 | } 146 | 147 | deinit { 148 | if isOwned { 149 | T.vecOfSelfFree(vecPtr: ptr) 150 | } 151 | } 152 | } 153 | 154 | extension RustVec: Sequence { 155 | public func makeIterator() -> RustVecIterator { 156 | return RustVecIterator(self) 157 | } 158 | } 159 | 160 | public struct RustVecIterator: IteratorProtocol { 161 | var rustVec: RustVec 162 | var index: UInt = 0 163 | 164 | init (_ rustVec: RustVec) { 165 | self.rustVec = rustVec 166 | } 167 | 168 | public mutating func next() -> T.SelfRef? { 169 | let val = rustVec.get(index: index) 170 | index += 1 171 | return val 172 | } 173 | } 174 | 175 | extension RustVec: Collection { 176 | public typealias Index = Int 177 | 178 | public func index(after i: Int) -> Int { 179 | i + 1 180 | } 181 | 182 | public subscript(position: Int) -> T.SelfRef { 183 | self.get(index: UInt(position))! 184 | } 185 | 186 | public var startIndex: Int { 187 | 0 188 | } 189 | 190 | public var endIndex: Int { 191 | self.len() 192 | } 193 | } 194 | 195 | extension RustVec: RandomAccessCollection {} 196 | 197 | extension UnsafeBufferPointer { 198 | func toFfiSlice () -> __private__FfiSlice { 199 | __private__FfiSlice(start: UnsafeMutablePointer(mutating: self.baseAddress), len: UInt(self.count)) 200 | } 201 | } 202 | 203 | public protocol Vectorizable { 204 | associatedtype SelfRef 205 | associatedtype SelfRefMut 206 | 207 | static func vecOfSelfNew() -> UnsafeMutableRawPointer; 208 | 209 | static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) 210 | 211 | static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) 212 | 213 | static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional 214 | 215 | static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional 216 | 217 | static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional 218 | 219 | static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer 220 | 221 | static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt 222 | } 223 | 224 | extension UInt8: Vectorizable { 225 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 226 | __swift_bridge__$Vec_u8$new() 227 | } 228 | 229 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 230 | __swift_bridge__$Vec_u8$_free(vecPtr) 231 | } 232 | 233 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 234 | __swift_bridge__$Vec_u8$push(vecPtr, value) 235 | } 236 | 237 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 238 | let val = __swift_bridge__$Vec_u8$pop(vecPtr) 239 | if val.is_some { 240 | return val.val 241 | } else { 242 | return nil 243 | } 244 | } 245 | 246 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 247 | let val = __swift_bridge__$Vec_u8$get(vecPtr, index) 248 | if val.is_some { 249 | return val.val 250 | } else { 251 | return nil 252 | } 253 | } 254 | 255 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 256 | let val = __swift_bridge__$Vec_u8$get_mut(vecPtr, index) 257 | if val.is_some { 258 | return val.val 259 | } else { 260 | return nil 261 | } 262 | } 263 | 264 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 265 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u8$as_ptr(vecPtr))) 266 | } 267 | 268 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 269 | __swift_bridge__$Vec_u8$len(vecPtr) 270 | } 271 | } 272 | 273 | extension UInt16: Vectorizable { 274 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 275 | __swift_bridge__$Vec_u16$new() 276 | } 277 | 278 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 279 | __swift_bridge__$Vec_u16$_free(vecPtr) 280 | } 281 | 282 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 283 | __swift_bridge__$Vec_u16$push(vecPtr, value) 284 | } 285 | 286 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 287 | let val = __swift_bridge__$Vec_u16$pop(vecPtr) 288 | if val.is_some { 289 | return val.val 290 | } else { 291 | return nil 292 | } 293 | } 294 | 295 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 296 | let val = __swift_bridge__$Vec_u16$get(vecPtr, index) 297 | if val.is_some { 298 | return val.val 299 | } else { 300 | return nil 301 | } 302 | } 303 | 304 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 305 | let val = __swift_bridge__$Vec_u16$get_mut(vecPtr, index) 306 | if val.is_some { 307 | return val.val 308 | } else { 309 | return nil 310 | } 311 | } 312 | 313 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 314 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u16$as_ptr(vecPtr))) 315 | } 316 | 317 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 318 | __swift_bridge__$Vec_u16$len(vecPtr) 319 | } 320 | } 321 | 322 | extension UInt32: Vectorizable { 323 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 324 | __swift_bridge__$Vec_u32$new() 325 | } 326 | 327 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 328 | __swift_bridge__$Vec_u32$_free(vecPtr) 329 | } 330 | 331 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 332 | __swift_bridge__$Vec_u32$push(vecPtr, value) 333 | } 334 | 335 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 336 | let val = __swift_bridge__$Vec_u32$pop(vecPtr) 337 | if val.is_some { 338 | return val.val 339 | } else { 340 | return nil 341 | } 342 | } 343 | 344 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 345 | let val = __swift_bridge__$Vec_u32$get(vecPtr, index) 346 | if val.is_some { 347 | return val.val 348 | } else { 349 | return nil 350 | } 351 | } 352 | 353 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 354 | let val = __swift_bridge__$Vec_u32$get_mut(vecPtr, index) 355 | if val.is_some { 356 | return val.val 357 | } else { 358 | return nil 359 | } 360 | } 361 | 362 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 363 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u32$as_ptr(vecPtr))) 364 | } 365 | 366 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 367 | __swift_bridge__$Vec_u32$len(vecPtr) 368 | } 369 | } 370 | 371 | extension UInt64: Vectorizable { 372 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 373 | __swift_bridge__$Vec_u64$new() 374 | } 375 | 376 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 377 | __swift_bridge__$Vec_u64$_free(vecPtr) 378 | } 379 | 380 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 381 | __swift_bridge__$Vec_u64$push(vecPtr, value) 382 | } 383 | 384 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 385 | let val = __swift_bridge__$Vec_u64$pop(vecPtr) 386 | if val.is_some { 387 | return val.val 388 | } else { 389 | return nil 390 | } 391 | } 392 | 393 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 394 | let val = __swift_bridge__$Vec_u64$get(vecPtr, index) 395 | if val.is_some { 396 | return val.val 397 | } else { 398 | return nil 399 | } 400 | } 401 | 402 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 403 | let val = __swift_bridge__$Vec_u64$get_mut(vecPtr, index) 404 | if val.is_some { 405 | return val.val 406 | } else { 407 | return nil 408 | } 409 | } 410 | 411 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 412 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u64$as_ptr(vecPtr))) 413 | } 414 | 415 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 416 | __swift_bridge__$Vec_u64$len(vecPtr) 417 | } 418 | } 419 | 420 | extension UInt: Vectorizable { 421 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 422 | __swift_bridge__$Vec_usize$new() 423 | } 424 | 425 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 426 | __swift_bridge__$Vec_usize$_free(vecPtr) 427 | } 428 | 429 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 430 | __swift_bridge__$Vec_usize$push(vecPtr, value) 431 | } 432 | 433 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 434 | let val = __swift_bridge__$Vec_usize$pop(vecPtr) 435 | if val.is_some { 436 | return val.val 437 | } else { 438 | return nil 439 | } 440 | } 441 | 442 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 443 | let val = __swift_bridge__$Vec_usize$get(vecPtr, index) 444 | if val.is_some { 445 | return val.val 446 | } else { 447 | return nil 448 | } 449 | } 450 | 451 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 452 | let val = __swift_bridge__$Vec_usize$get_mut(vecPtr, index) 453 | if val.is_some { 454 | return val.val 455 | } else { 456 | return nil 457 | } 458 | } 459 | 460 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 461 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_usize$as_ptr(vecPtr))) 462 | } 463 | 464 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 465 | __swift_bridge__$Vec_usize$len(vecPtr) 466 | } 467 | } 468 | 469 | extension Int8: Vectorizable { 470 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 471 | __swift_bridge__$Vec_i8$new() 472 | } 473 | 474 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 475 | __swift_bridge__$Vec_i8$_free(vecPtr) 476 | } 477 | 478 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 479 | __swift_bridge__$Vec_i8$push(vecPtr, value) 480 | } 481 | 482 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 483 | let val = __swift_bridge__$Vec_i8$pop(vecPtr) 484 | if val.is_some { 485 | return val.val 486 | } else { 487 | return nil 488 | } 489 | } 490 | 491 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 492 | let val = __swift_bridge__$Vec_i8$get(vecPtr, index) 493 | if val.is_some { 494 | return val.val 495 | } else { 496 | return nil 497 | } 498 | } 499 | 500 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 501 | let val = __swift_bridge__$Vec_i8$get_mut(vecPtr, index) 502 | if val.is_some { 503 | return val.val 504 | } else { 505 | return nil 506 | } 507 | } 508 | 509 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 510 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i8$as_ptr(vecPtr))) 511 | } 512 | 513 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 514 | __swift_bridge__$Vec_i8$len(vecPtr) 515 | } 516 | } 517 | 518 | extension Int16: Vectorizable { 519 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 520 | __swift_bridge__$Vec_i16$new() 521 | } 522 | 523 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 524 | __swift_bridge__$Vec_i16$_free(vecPtr) 525 | } 526 | 527 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 528 | __swift_bridge__$Vec_i16$push(vecPtr, value) 529 | } 530 | 531 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 532 | let val = __swift_bridge__$Vec_i16$pop(vecPtr) 533 | if val.is_some { 534 | return val.val 535 | } else { 536 | return nil 537 | } 538 | } 539 | 540 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 541 | let val = __swift_bridge__$Vec_i16$get(vecPtr, index) 542 | if val.is_some { 543 | return val.val 544 | } else { 545 | return nil 546 | } 547 | } 548 | 549 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 550 | let val = __swift_bridge__$Vec_i16$get_mut(vecPtr, index) 551 | if val.is_some { 552 | return val.val 553 | } else { 554 | return nil 555 | } 556 | } 557 | 558 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 559 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i16$as_ptr(vecPtr))) 560 | } 561 | 562 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 563 | __swift_bridge__$Vec_i16$len(vecPtr) 564 | } 565 | } 566 | 567 | extension Int32: Vectorizable { 568 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 569 | __swift_bridge__$Vec_i32$new() 570 | } 571 | 572 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 573 | __swift_bridge__$Vec_i32$_free(vecPtr) 574 | } 575 | 576 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 577 | __swift_bridge__$Vec_i32$push(vecPtr, value) 578 | } 579 | 580 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 581 | let val = __swift_bridge__$Vec_i32$pop(vecPtr) 582 | if val.is_some { 583 | return val.val 584 | } else { 585 | return nil 586 | } 587 | } 588 | 589 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 590 | let val = __swift_bridge__$Vec_i32$get(vecPtr, index) 591 | if val.is_some { 592 | return val.val 593 | } else { 594 | return nil 595 | } 596 | } 597 | 598 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 599 | let val = __swift_bridge__$Vec_i32$get_mut(vecPtr, index) 600 | if val.is_some { 601 | return val.val 602 | } else { 603 | return nil 604 | } 605 | } 606 | 607 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 608 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i32$as_ptr(vecPtr))) 609 | } 610 | 611 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 612 | __swift_bridge__$Vec_i32$len(vecPtr) 613 | } 614 | } 615 | 616 | extension Int64: Vectorizable { 617 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 618 | __swift_bridge__$Vec_i64$new() 619 | } 620 | 621 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 622 | __swift_bridge__$Vec_i64$_free(vecPtr) 623 | } 624 | 625 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 626 | __swift_bridge__$Vec_i64$push(vecPtr, value) 627 | } 628 | 629 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 630 | let val = __swift_bridge__$Vec_i64$pop(vecPtr) 631 | if val.is_some { 632 | return val.val 633 | } else { 634 | return nil 635 | } 636 | } 637 | 638 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 639 | let val = __swift_bridge__$Vec_i64$get(vecPtr, index) 640 | if val.is_some { 641 | return val.val 642 | } else { 643 | return nil 644 | } 645 | } 646 | 647 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 648 | let val = __swift_bridge__$Vec_i64$get_mut(vecPtr, index) 649 | if val.is_some { 650 | return val.val 651 | } else { 652 | return nil 653 | } 654 | } 655 | 656 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 657 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i64$as_ptr(vecPtr))) 658 | } 659 | 660 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 661 | __swift_bridge__$Vec_i64$len(vecPtr) 662 | } 663 | } 664 | 665 | extension Int: Vectorizable { 666 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 667 | __swift_bridge__$Vec_isize$new() 668 | } 669 | 670 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 671 | __swift_bridge__$Vec_isize$_free(vecPtr) 672 | } 673 | 674 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 675 | __swift_bridge__$Vec_isize$push(vecPtr, value) 676 | } 677 | 678 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 679 | let val = __swift_bridge__$Vec_isize$pop(vecPtr) 680 | if val.is_some { 681 | return val.val 682 | } else { 683 | return nil 684 | } 685 | } 686 | 687 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 688 | let val = __swift_bridge__$Vec_isize$get(vecPtr, index) 689 | if val.is_some { 690 | return val.val 691 | } else { 692 | return nil 693 | } 694 | } 695 | 696 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 697 | let val = __swift_bridge__$Vec_isize$get_mut(vecPtr, index) 698 | if val.is_some { 699 | return val.val 700 | } else { 701 | return nil 702 | } 703 | } 704 | 705 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 706 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_isize$as_ptr(vecPtr))) 707 | } 708 | 709 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 710 | __swift_bridge__$Vec_isize$len(vecPtr) 711 | } 712 | } 713 | 714 | extension Bool: Vectorizable { 715 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 716 | __swift_bridge__$Vec_bool$new() 717 | } 718 | 719 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 720 | __swift_bridge__$Vec_bool$_free(vecPtr) 721 | } 722 | 723 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 724 | __swift_bridge__$Vec_bool$push(vecPtr, value) 725 | } 726 | 727 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 728 | let val = __swift_bridge__$Vec_bool$pop(vecPtr) 729 | if val.is_some { 730 | return val.val 731 | } else { 732 | return nil 733 | } 734 | } 735 | 736 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 737 | let val = __swift_bridge__$Vec_bool$get(vecPtr, index) 738 | if val.is_some { 739 | return val.val 740 | } else { 741 | return nil 742 | } 743 | } 744 | 745 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 746 | let val = __swift_bridge__$Vec_bool$get_mut(vecPtr, index) 747 | if val.is_some { 748 | return val.val 749 | } else { 750 | return nil 751 | } 752 | } 753 | 754 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 755 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_bool$as_ptr(vecPtr))) 756 | } 757 | 758 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 759 | __swift_bridge__$Vec_bool$len(vecPtr) 760 | } 761 | } 762 | 763 | extension Float: Vectorizable { 764 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 765 | __swift_bridge__$Vec_f32$new() 766 | } 767 | 768 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 769 | __swift_bridge__$Vec_f32$_free(vecPtr) 770 | } 771 | 772 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 773 | __swift_bridge__$Vec_f32$push(vecPtr, value) 774 | } 775 | 776 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 777 | let val = __swift_bridge__$Vec_f32$pop(vecPtr) 778 | if val.is_some { 779 | return val.val 780 | } else { 781 | return nil 782 | } 783 | } 784 | 785 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 786 | let val = __swift_bridge__$Vec_f32$get(vecPtr, index) 787 | if val.is_some { 788 | return val.val 789 | } else { 790 | return nil 791 | } 792 | } 793 | 794 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 795 | let val = __swift_bridge__$Vec_f32$get_mut(vecPtr, index) 796 | if val.is_some { 797 | return val.val 798 | } else { 799 | return nil 800 | } 801 | } 802 | 803 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 804 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f32$as_ptr(vecPtr))) 805 | } 806 | 807 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 808 | __swift_bridge__$Vec_f32$len(vecPtr) 809 | } 810 | } 811 | 812 | extension Double: Vectorizable { 813 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 814 | __swift_bridge__$Vec_f64$new() 815 | } 816 | 817 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 818 | __swift_bridge__$Vec_f64$_free(vecPtr) 819 | } 820 | 821 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { 822 | __swift_bridge__$Vec_f64$push(vecPtr, value) 823 | } 824 | 825 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 826 | let val = __swift_bridge__$Vec_f64$pop(vecPtr) 827 | if val.is_some { 828 | return val.val 829 | } else { 830 | return nil 831 | } 832 | } 833 | 834 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 835 | let val = __swift_bridge__$Vec_f64$get(vecPtr, index) 836 | if val.is_some { 837 | return val.val 838 | } else { 839 | return nil 840 | } 841 | } 842 | 843 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 844 | let val = __swift_bridge__$Vec_f64$get_mut(vecPtr, index) 845 | if val.is_some { 846 | return val.val 847 | } else { 848 | return nil 849 | } 850 | } 851 | 852 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 853 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f64$as_ptr(vecPtr))) 854 | } 855 | 856 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 857 | __swift_bridge__$Vec_f64$len(vecPtr) 858 | } 859 | } 860 | 861 | protocol SwiftBridgeGenericFreer { 862 | func rust_free(); 863 | } 864 | 865 | protocol SwiftBridgeGenericCopyTypeFfiRepr {} 866 | 867 | public class RustString: RustStringRefMut { 868 | var isOwned: Bool = true 869 | 870 | public override init(ptr: UnsafeMutableRawPointer) { 871 | super.init(ptr: ptr) 872 | } 873 | 874 | deinit { 875 | if isOwned { 876 | __swift_bridge__$RustString$_free(ptr) 877 | } 878 | } 879 | } 880 | extension RustString { 881 | public convenience init() { 882 | self.init(ptr: __swift_bridge__$RustString$new()) 883 | } 884 | 885 | public convenience init(_ str: GenericToRustStr) { 886 | self.init(ptr: str.toRustStr({ strAsRustStr in 887 | __swift_bridge__$RustString$new_with_str(strAsRustStr) 888 | })) 889 | } 890 | } 891 | public class RustStringRefMut: RustStringRef { 892 | public override init(ptr: UnsafeMutableRawPointer) { 893 | super.init(ptr: ptr) 894 | } 895 | } 896 | public class RustStringRef { 897 | var ptr: UnsafeMutableRawPointer 898 | 899 | public init(ptr: UnsafeMutableRawPointer) { 900 | self.ptr = ptr 901 | } 902 | } 903 | extension RustStringRef { 904 | public func len() -> UInt { 905 | __swift_bridge__$RustString$len(ptr) 906 | } 907 | 908 | public func as_str() -> RustStr { 909 | __swift_bridge__$RustString$as_str(ptr) 910 | } 911 | 912 | public func trim() -> RustStr { 913 | __swift_bridge__$RustString$trim(ptr) 914 | } 915 | } 916 | extension RustString: Vectorizable { 917 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 918 | __swift_bridge__$Vec_RustString$new() 919 | } 920 | 921 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 922 | __swift_bridge__$Vec_RustString$drop(vecPtr) 923 | } 924 | 925 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: RustString) { 926 | __swift_bridge__$Vec_RustString$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 927 | } 928 | 929 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 930 | let pointer = __swift_bridge__$Vec_RustString$pop(vecPtr) 931 | if pointer == nil { 932 | return nil 933 | } else { 934 | return (RustString(ptr: pointer!) as! Self) 935 | } 936 | } 937 | 938 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 939 | let pointer = __swift_bridge__$Vec_RustString$get(vecPtr, index) 940 | if pointer == nil { 941 | return nil 942 | } else { 943 | return RustStringRef(ptr: pointer!) 944 | } 945 | } 946 | 947 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 948 | let pointer = __swift_bridge__$Vec_RustString$get_mut(vecPtr, index) 949 | if pointer == nil { 950 | return nil 951 | } else { 952 | return RustStringRefMut(ptr: pointer!) 953 | } 954 | } 955 | 956 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 957 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_RustString$as_ptr(vecPtr))) 958 | } 959 | 960 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 961 | __swift_bridge__$Vec_RustString$len(vecPtr) 962 | } 963 | } 964 | 965 | public class __private__RustFnOnceCallbackNoArgsNoRet { 966 | var ptr: UnsafeMutableRawPointer 967 | var called = false 968 | 969 | init(ptr: UnsafeMutableRawPointer) { 970 | self.ptr = ptr 971 | } 972 | 973 | deinit { 974 | if !called { 975 | __swift_bridge__$free_boxed_fn_once_no_args_no_return(ptr) 976 | } 977 | } 978 | 979 | func call() { 980 | if called { 981 | fatalError("Cannot call a Rust FnOnce function twice") 982 | } 983 | called = true 984 | return __swift_bridge__$call_boxed_fn_once_no_args_no_return(ptr) 985 | } 986 | } 987 | 988 | 989 | public enum RustResult { 990 | case Ok(T) 991 | case Err(E) 992 | } 993 | 994 | extension RustResult { 995 | func ok() -> T? { 996 | switch self { 997 | case .Ok(let ok): 998 | return ok 999 | case .Err(_): 1000 | return nil 1001 | } 1002 | } 1003 | 1004 | func err() -> E? { 1005 | switch self { 1006 | case .Ok(_): 1007 | return nil 1008 | case .Err(let err): 1009 | return err 1010 | } 1011 | } 1012 | 1013 | func toResult() -> Result 1014 | where E: Error { 1015 | switch self { 1016 | case .Ok(let ok): 1017 | return .success(ok) 1018 | case .Err(let err): 1019 | return .failure(err) 1020 | } 1021 | } 1022 | } 1023 | 1024 | 1025 | extension __private__OptionU8 { 1026 | func intoSwiftRepr() -> Optional { 1027 | if self.is_some { 1028 | return self.val 1029 | } else { 1030 | return nil 1031 | } 1032 | } 1033 | 1034 | init(_ val: Optional) { 1035 | if let val = val { 1036 | self = Self(val: val, is_some: true) 1037 | } else { 1038 | self = Self(val: 123, is_some: false) 1039 | } 1040 | } 1041 | } 1042 | extension Optional where Wrapped == UInt8 { 1043 | func intoFfiRepr() -> __private__OptionU8 { 1044 | __private__OptionU8(self) 1045 | } 1046 | } 1047 | 1048 | extension __private__OptionI8 { 1049 | func intoSwiftRepr() -> Optional { 1050 | if self.is_some { 1051 | return self.val 1052 | } else { 1053 | return nil 1054 | } 1055 | } 1056 | 1057 | init(_ val: Optional) { 1058 | if let val = val { 1059 | self = Self(val: val, is_some: true) 1060 | } else { 1061 | self = Self(val: 123, is_some: false) 1062 | } 1063 | } 1064 | } 1065 | extension Optional where Wrapped == Int8 { 1066 | func intoFfiRepr() -> __private__OptionI8 { 1067 | __private__OptionI8(self) 1068 | } 1069 | } 1070 | 1071 | extension __private__OptionU16 { 1072 | func intoSwiftRepr() -> Optional { 1073 | if self.is_some { 1074 | return self.val 1075 | } else { 1076 | return nil 1077 | } 1078 | } 1079 | 1080 | init(_ val: Optional) { 1081 | if let val = val { 1082 | self = Self(val: val, is_some: true) 1083 | } else { 1084 | self = Self(val: 123, is_some: false) 1085 | } 1086 | } 1087 | } 1088 | extension Optional where Wrapped == UInt16 { 1089 | func intoFfiRepr() -> __private__OptionU16 { 1090 | __private__OptionU16(self) 1091 | } 1092 | } 1093 | 1094 | extension __private__OptionI16 { 1095 | func intoSwiftRepr() -> Optional { 1096 | if self.is_some { 1097 | return self.val 1098 | } else { 1099 | return nil 1100 | } 1101 | } 1102 | 1103 | init(_ val: Optional) { 1104 | if let val = val { 1105 | self = Self(val: val, is_some: true) 1106 | } else { 1107 | self = Self(val: 123, is_some: false) 1108 | } 1109 | } 1110 | } 1111 | extension Optional where Wrapped == Int16 { 1112 | func intoFfiRepr() -> __private__OptionI16 { 1113 | __private__OptionI16(self) 1114 | } 1115 | } 1116 | 1117 | extension __private__OptionU32 { 1118 | func intoSwiftRepr() -> Optional { 1119 | if self.is_some { 1120 | return self.val 1121 | } else { 1122 | return nil 1123 | } 1124 | } 1125 | 1126 | init(_ val: Optional) { 1127 | if let val = val { 1128 | self = Self(val: val, is_some: true) 1129 | } else { 1130 | self = Self(val: 123, is_some: false) 1131 | } 1132 | } 1133 | } 1134 | extension Optional where Wrapped == UInt32 { 1135 | func intoFfiRepr() -> __private__OptionU32 { 1136 | __private__OptionU32(self) 1137 | } 1138 | } 1139 | 1140 | extension __private__OptionI32 { 1141 | func intoSwiftRepr() -> Optional { 1142 | if self.is_some { 1143 | return self.val 1144 | } else { 1145 | return nil 1146 | } 1147 | } 1148 | 1149 | init(_ val: Optional) { 1150 | if let val = val { 1151 | self = Self(val: val, is_some: true) 1152 | } else { 1153 | self = Self(val: 123, is_some: false) 1154 | } 1155 | } 1156 | } 1157 | extension Optional where Wrapped == Int32 { 1158 | func intoFfiRepr() -> __private__OptionI32 { 1159 | __private__OptionI32(self) 1160 | } 1161 | } 1162 | 1163 | extension __private__OptionU64 { 1164 | func intoSwiftRepr() -> Optional { 1165 | if self.is_some { 1166 | return self.val 1167 | } else { 1168 | return nil 1169 | } 1170 | } 1171 | 1172 | init(_ val: Optional) { 1173 | if let val = val { 1174 | self = Self(val: val, is_some: true) 1175 | } else { 1176 | self = Self(val: 123, is_some: false) 1177 | } 1178 | } 1179 | } 1180 | extension Optional where Wrapped == UInt64 { 1181 | func intoFfiRepr() -> __private__OptionU64 { 1182 | __private__OptionU64(self) 1183 | } 1184 | } 1185 | 1186 | extension __private__OptionI64 { 1187 | func intoSwiftRepr() -> Optional { 1188 | if self.is_some { 1189 | return self.val 1190 | } else { 1191 | return nil 1192 | } 1193 | } 1194 | 1195 | init(_ val: Optional) { 1196 | if let val = val { 1197 | self = Self(val: val, is_some: true) 1198 | } else { 1199 | self = Self(val: 123, is_some: false) 1200 | } 1201 | } 1202 | } 1203 | extension Optional where Wrapped == Int64 { 1204 | func intoFfiRepr() -> __private__OptionI64 { 1205 | __private__OptionI64(self) 1206 | } 1207 | } 1208 | 1209 | extension __private__OptionUsize { 1210 | func intoSwiftRepr() -> Optional { 1211 | if self.is_some { 1212 | return self.val 1213 | } else { 1214 | return nil 1215 | } 1216 | } 1217 | 1218 | init(_ val: Optional) { 1219 | if let val = val { 1220 | self = Self(val: val, is_some: true) 1221 | } else { 1222 | self = Self(val: 123, is_some: false) 1223 | } 1224 | } 1225 | } 1226 | extension Optional where Wrapped == UInt { 1227 | func intoFfiRepr() -> __private__OptionUsize { 1228 | __private__OptionUsize(self) 1229 | } 1230 | } 1231 | 1232 | extension __private__OptionIsize { 1233 | func intoSwiftRepr() -> Optional { 1234 | if self.is_some { 1235 | return self.val 1236 | } else { 1237 | return nil 1238 | } 1239 | } 1240 | 1241 | init(_ val: Optional) { 1242 | if let val = val { 1243 | self = Self(val: val, is_some: true) 1244 | } else { 1245 | self = Self(val: 123, is_some: false) 1246 | } 1247 | } 1248 | } 1249 | extension Optional where Wrapped == Int { 1250 | func intoFfiRepr() -> __private__OptionIsize { 1251 | __private__OptionIsize(self) 1252 | } 1253 | } 1254 | 1255 | extension __private__OptionF32 { 1256 | func intoSwiftRepr() -> Optional { 1257 | if self.is_some { 1258 | return self.val 1259 | } else { 1260 | return nil 1261 | } 1262 | } 1263 | 1264 | init(_ val: Optional) { 1265 | if let val = val { 1266 | self = Self(val: val, is_some: true) 1267 | } else { 1268 | self = Self(val: 123.4, is_some: false) 1269 | } 1270 | } 1271 | } 1272 | extension Optional where Wrapped == Float { 1273 | func intoFfiRepr() -> __private__OptionF32 { 1274 | __private__OptionF32(self) 1275 | } 1276 | } 1277 | 1278 | extension __private__OptionF64 { 1279 | func intoSwiftRepr() -> Optional { 1280 | if self.is_some { 1281 | return self.val 1282 | } else { 1283 | return nil 1284 | } 1285 | } 1286 | 1287 | init(_ val: Optional) { 1288 | if let val = val { 1289 | self = Self(val: val, is_some: true) 1290 | } else { 1291 | self = Self(val: 123.4, is_some: false) 1292 | } 1293 | } 1294 | } 1295 | extension Optional where Wrapped == Double { 1296 | func intoFfiRepr() -> __private__OptionF64 { 1297 | __private__OptionF64(self) 1298 | } 1299 | } 1300 | 1301 | extension __private__OptionBool { 1302 | func intoSwiftRepr() -> Optional { 1303 | if self.is_some { 1304 | return self.val 1305 | } else { 1306 | return nil 1307 | } 1308 | } 1309 | 1310 | init(_ val: Optional) { 1311 | if let val = val { 1312 | self = Self(val: val, is_some: true) 1313 | } else { 1314 | self = Self(val: false, is_some: false) 1315 | } 1316 | } 1317 | } 1318 | extension Optional where Wrapped == Bool { 1319 | func intoFfiRepr() -> __private__OptionBool { 1320 | __private__OptionBool(self) 1321 | } 1322 | } 1323 | -------------------------------------------------------------------------------- /smooth-ui/generated/smooth-ui/smooth-ui.h: -------------------------------------------------------------------------------- 1 | // File automatically generated by swift-bridge. 2 | #include 3 | #include 4 | typedef struct __swift_bridge__$ChatBubble { void* sender; void* text; } __swift_bridge__$ChatBubble; 5 | typedef struct __swift_bridge__$Option$ChatBubble { bool is_some; __swift_bridge__$ChatBubble val; } __swift_bridge__$Option$ChatBubble; 6 | typedef struct InputEvent InputEvent; 7 | void __swift_bridge__$InputEvent$_free(void* self); 8 | 9 | void* __swift_bridge__$Vec_InputEvent$new(void); 10 | void __swift_bridge__$Vec_InputEvent$drop(void* vec_ptr); 11 | void __swift_bridge__$Vec_InputEvent$push(void* vec_ptr, void* item_ptr); 12 | void* __swift_bridge__$Vec_InputEvent$pop(void* vec_ptr); 13 | void* __swift_bridge__$Vec_InputEvent$get(void* vec_ptr, uintptr_t index); 14 | void* __swift_bridge__$Vec_InputEvent$get_mut(void* vec_ptr, uintptr_t index); 15 | uintptr_t __swift_bridge__$Vec_InputEvent$len(void* vec_ptr); 16 | void* __swift_bridge__$Vec_InputEvent$as_ptr(void* vec_ptr); 17 | 18 | typedef struct OutputState OutputState; 19 | void __swift_bridge__$OutputState$_free(void* self); 20 | 21 | void* __swift_bridge__$Vec_OutputState$new(void); 22 | void __swift_bridge__$Vec_OutputState$drop(void* vec_ptr); 23 | void __swift_bridge__$Vec_OutputState$push(void* vec_ptr, void* item_ptr); 24 | void* __swift_bridge__$Vec_OutputState$pop(void* vec_ptr); 25 | void* __swift_bridge__$Vec_OutputState$get(void* vec_ptr, uintptr_t index); 26 | void* __swift_bridge__$Vec_OutputState$get_mut(void* vec_ptr, uintptr_t index); 27 | uintptr_t __swift_bridge__$Vec_OutputState$len(void* vec_ptr); 28 | void* __swift_bridge__$Vec_OutputState$as_ptr(void* vec_ptr); 29 | 30 | typedef struct CursorIcon CursorIcon; 31 | void __swift_bridge__$CursorIcon$_free(void* self); 32 | 33 | void* __swift_bridge__$Vec_CursorIcon$new(void); 34 | void __swift_bridge__$Vec_CursorIcon$drop(void* vec_ptr); 35 | void __swift_bridge__$Vec_CursorIcon$push(void* vec_ptr, void* item_ptr); 36 | void* __swift_bridge__$Vec_CursorIcon$pop(void* vec_ptr); 37 | void* __swift_bridge__$Vec_CursorIcon$get(void* vec_ptr, uintptr_t index); 38 | void* __swift_bridge__$Vec_CursorIcon$get_mut(void* vec_ptr, uintptr_t index); 39 | uintptr_t __swift_bridge__$Vec_CursorIcon$len(void* vec_ptr); 40 | void* __swift_bridge__$Vec_CursorIcon$as_ptr(void* vec_ptr); 41 | 42 | typedef struct Renderer Renderer; 43 | void __swift_bridge__$Renderer$_free(void* self); 44 | 45 | void* __swift_bridge__$Vec_Renderer$new(void); 46 | void __swift_bridge__$Vec_Renderer$drop(void* vec_ptr); 47 | void __swift_bridge__$Vec_Renderer$push(void* vec_ptr, void* item_ptr); 48 | void* __swift_bridge__$Vec_Renderer$pop(void* vec_ptr); 49 | void* __swift_bridge__$Vec_Renderer$get(void* vec_ptr, uintptr_t index); 50 | void* __swift_bridge__$Vec_Renderer$get_mut(void* vec_ptr, uintptr_t index); 51 | uintptr_t __swift_bridge__$Vec_Renderer$len(void* vec_ptr); 52 | void* __swift_bridge__$Vec_Renderer$as_ptr(void* vec_ptr); 53 | 54 | void* __swift_bridge__$InputEvent$from_pointer_moved(float x, float y); 55 | void* __swift_bridge__$InputEvent$from_mouse_wheel(float x, float y); 56 | void* __swift_bridge__$InputEvent$from_left_mouse_down(float x, float y, bool pressed); 57 | void* __swift_bridge__$InputEvent$from_right_mouse_down(float x, float y, bool pressed); 58 | void* __swift_bridge__$InputEvent$from_window_focused(bool focused); 59 | void* __swift_bridge__$OutputState$get_cursor_icon(void* self); 60 | bool __swift_bridge__$CursorIcon$is_default(void* self); 61 | bool __swift_bridge__$CursorIcon$is_pointing_hand(void* self); 62 | bool __swift_bridge__$CursorIcon$is_resize_horizontal(void* self); 63 | bool __swift_bridge__$CursorIcon$is_resize_vertical(void* self); 64 | bool __swift_bridge__$CursorIcon$is_text(void* self); 65 | void* __swift_bridge__$Renderer$new(void* layer_ptr, uint32_t width, uint32_t height, float display_scale); 66 | void __swift_bridge__$Renderer$resize(void* self, uint32_t width, uint32_t height); 67 | void* __swift_bridge__$Renderer$render(void* self, double time, void* input_events, void* controller); 68 | 69 | 70 | -------------------------------------------------------------------------------- /smooth-ui/generated/smooth-ui/smooth-ui.swift: -------------------------------------------------------------------------------- 1 | @_cdecl("__swift_bridge__$BaseChatController$bubbles_count") 2 | func __swift_bridge__BaseChatController_bubbles_count (_ this: UnsafeMutableRawPointer) -> UInt { 3 | Unmanaged.fromOpaque(this).takeUnretainedValue().bubbles_count() 4 | } 5 | 6 | @_cdecl("__swift_bridge__$BaseChatController$bubble_at_index") 7 | func __swift_bridge__BaseChatController_bubble_at_index (_ this: UnsafeMutableRawPointer, _ index: UInt) -> __swift_bridge__$ChatBubble { 8 | Unmanaged.fromOpaque(this).takeUnretainedValue().bubble_at_index(index: index).intoFfiRepr() 9 | } 10 | 11 | public struct ChatBubble { 12 | public var sender: RustString 13 | public var text: RustString 14 | 15 | public init(sender: RustString,text: RustString) { 16 | self.sender = sender 17 | self.text = text 18 | } 19 | 20 | @inline(__always) 21 | func intoFfiRepr() -> __swift_bridge__$ChatBubble { 22 | { let val = self; return __swift_bridge__$ChatBubble(sender: { let rustString = val.sender.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), text: { let rustString = val.text.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); }() 23 | } 24 | } 25 | extension __swift_bridge__$ChatBubble { 26 | @inline(__always) 27 | func intoSwiftRepr() -> ChatBubble { 28 | { let val = self; return ChatBubble(sender: RustString(ptr: val.sender), text: RustString(ptr: val.text)); }() 29 | } 30 | } 31 | extension __swift_bridge__$Option$ChatBubble { 32 | @inline(__always) 33 | func intoSwiftRepr() -> Optional { 34 | if self.is_some { 35 | return self.val.intoSwiftRepr() 36 | } else { 37 | return nil 38 | } 39 | } 40 | 41 | @inline(__always) 42 | static func fromSwiftRepr(_ val: Optional) -> __swift_bridge__$Option$ChatBubble { 43 | if let v = val { 44 | return __swift_bridge__$Option$ChatBubble(is_some: true, val: v.intoFfiRepr()) 45 | } else { 46 | return __swift_bridge__$Option$ChatBubble(is_some: false, val: __swift_bridge__$ChatBubble()) 47 | } 48 | } 49 | } 50 | 51 | public class InputEvent: InputEventRefMut { 52 | var isOwned: Bool = true 53 | 54 | public override init(ptr: UnsafeMutableRawPointer) { 55 | super.init(ptr: ptr) 56 | } 57 | 58 | deinit { 59 | if isOwned { 60 | __swift_bridge__$InputEvent$_free(ptr) 61 | } 62 | } 63 | } 64 | extension InputEvent { 65 | class public func from_pointer_moved(_ x: Float, _ y: Float) -> InputEvent { 66 | InputEvent(ptr: __swift_bridge__$InputEvent$from_pointer_moved(x, y)) 67 | } 68 | 69 | class public func from_mouse_wheel(_ x: Float, _ y: Float) -> InputEvent { 70 | InputEvent(ptr: __swift_bridge__$InputEvent$from_mouse_wheel(x, y)) 71 | } 72 | 73 | class public func from_left_mouse_down(_ x: Float, _ y: Float, _ pressed: Bool) -> InputEvent { 74 | InputEvent(ptr: __swift_bridge__$InputEvent$from_left_mouse_down(x, y, pressed)) 75 | } 76 | 77 | class public func from_right_mouse_down(_ x: Float, _ y: Float, _ pressed: Bool) -> InputEvent { 78 | InputEvent(ptr: __swift_bridge__$InputEvent$from_right_mouse_down(x, y, pressed)) 79 | } 80 | 81 | class public func from_window_focused(_ focused: Bool) -> InputEvent { 82 | InputEvent(ptr: __swift_bridge__$InputEvent$from_window_focused(focused)) 83 | } 84 | } 85 | public class InputEventRefMut: InputEventRef { 86 | public override init(ptr: UnsafeMutableRawPointer) { 87 | super.init(ptr: ptr) 88 | } 89 | } 90 | public class InputEventRef { 91 | var ptr: UnsafeMutableRawPointer 92 | 93 | public init(ptr: UnsafeMutableRawPointer) { 94 | self.ptr = ptr 95 | } 96 | } 97 | extension InputEvent: Vectorizable { 98 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 99 | __swift_bridge__$Vec_InputEvent$new() 100 | } 101 | 102 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 103 | __swift_bridge__$Vec_InputEvent$drop(vecPtr) 104 | } 105 | 106 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: InputEvent) { 107 | __swift_bridge__$Vec_InputEvent$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 108 | } 109 | 110 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 111 | let pointer = __swift_bridge__$Vec_InputEvent$pop(vecPtr) 112 | if pointer == nil { 113 | return nil 114 | } else { 115 | return (InputEvent(ptr: pointer!) as! Self) 116 | } 117 | } 118 | 119 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 120 | let pointer = __swift_bridge__$Vec_InputEvent$get(vecPtr, index) 121 | if pointer == nil { 122 | return nil 123 | } else { 124 | return InputEventRef(ptr: pointer!) 125 | } 126 | } 127 | 128 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 129 | let pointer = __swift_bridge__$Vec_InputEvent$get_mut(vecPtr, index) 130 | if pointer == nil { 131 | return nil 132 | } else { 133 | return InputEventRefMut(ptr: pointer!) 134 | } 135 | } 136 | 137 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 138 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_InputEvent$as_ptr(vecPtr))) 139 | } 140 | 141 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 142 | __swift_bridge__$Vec_InputEvent$len(vecPtr) 143 | } 144 | } 145 | 146 | 147 | public class OutputState: OutputStateRefMut { 148 | var isOwned: Bool = true 149 | 150 | public override init(ptr: UnsafeMutableRawPointer) { 151 | super.init(ptr: ptr) 152 | } 153 | 154 | deinit { 155 | if isOwned { 156 | __swift_bridge__$OutputState$_free(ptr) 157 | } 158 | } 159 | } 160 | public class OutputStateRefMut: OutputStateRef { 161 | public override init(ptr: UnsafeMutableRawPointer) { 162 | super.init(ptr: ptr) 163 | } 164 | } 165 | public class OutputStateRef { 166 | var ptr: UnsafeMutableRawPointer 167 | 168 | public init(ptr: UnsafeMutableRawPointer) { 169 | self.ptr = ptr 170 | } 171 | } 172 | extension OutputStateRef { 173 | public func get_cursor_icon() -> CursorIconRef { 174 | CursorIconRef(ptr: __swift_bridge__$OutputState$get_cursor_icon(ptr)) 175 | } 176 | } 177 | extension OutputState: Vectorizable { 178 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 179 | __swift_bridge__$Vec_OutputState$new() 180 | } 181 | 182 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 183 | __swift_bridge__$Vec_OutputState$drop(vecPtr) 184 | } 185 | 186 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: OutputState) { 187 | __swift_bridge__$Vec_OutputState$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 188 | } 189 | 190 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 191 | let pointer = __swift_bridge__$Vec_OutputState$pop(vecPtr) 192 | if pointer == nil { 193 | return nil 194 | } else { 195 | return (OutputState(ptr: pointer!) as! Self) 196 | } 197 | } 198 | 199 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 200 | let pointer = __swift_bridge__$Vec_OutputState$get(vecPtr, index) 201 | if pointer == nil { 202 | return nil 203 | } else { 204 | return OutputStateRef(ptr: pointer!) 205 | } 206 | } 207 | 208 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 209 | let pointer = __swift_bridge__$Vec_OutputState$get_mut(vecPtr, index) 210 | if pointer == nil { 211 | return nil 212 | } else { 213 | return OutputStateRefMut(ptr: pointer!) 214 | } 215 | } 216 | 217 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 218 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_OutputState$as_ptr(vecPtr))) 219 | } 220 | 221 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 222 | __swift_bridge__$Vec_OutputState$len(vecPtr) 223 | } 224 | } 225 | 226 | 227 | public class CursorIcon: CursorIconRefMut { 228 | var isOwned: Bool = true 229 | 230 | public override init(ptr: UnsafeMutableRawPointer) { 231 | super.init(ptr: ptr) 232 | } 233 | 234 | deinit { 235 | if isOwned { 236 | __swift_bridge__$CursorIcon$_free(ptr) 237 | } 238 | } 239 | } 240 | public class CursorIconRefMut: CursorIconRef { 241 | public override init(ptr: UnsafeMutableRawPointer) { 242 | super.init(ptr: ptr) 243 | } 244 | } 245 | public class CursorIconRef { 246 | var ptr: UnsafeMutableRawPointer 247 | 248 | public init(ptr: UnsafeMutableRawPointer) { 249 | self.ptr = ptr 250 | } 251 | } 252 | extension CursorIconRef { 253 | public func is_default() -> Bool { 254 | __swift_bridge__$CursorIcon$is_default(ptr) 255 | } 256 | 257 | public func is_pointing_hand() -> Bool { 258 | __swift_bridge__$CursorIcon$is_pointing_hand(ptr) 259 | } 260 | 261 | public func is_resize_horizontal() -> Bool { 262 | __swift_bridge__$CursorIcon$is_resize_horizontal(ptr) 263 | } 264 | 265 | public func is_resize_vertical() -> Bool { 266 | __swift_bridge__$CursorIcon$is_resize_vertical(ptr) 267 | } 268 | 269 | public func is_text() -> Bool { 270 | __swift_bridge__$CursorIcon$is_text(ptr) 271 | } 272 | } 273 | extension CursorIcon: Vectorizable { 274 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 275 | __swift_bridge__$Vec_CursorIcon$new() 276 | } 277 | 278 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 279 | __swift_bridge__$Vec_CursorIcon$drop(vecPtr) 280 | } 281 | 282 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: CursorIcon) { 283 | __swift_bridge__$Vec_CursorIcon$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 284 | } 285 | 286 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 287 | let pointer = __swift_bridge__$Vec_CursorIcon$pop(vecPtr) 288 | if pointer == nil { 289 | return nil 290 | } else { 291 | return (CursorIcon(ptr: pointer!) as! Self) 292 | } 293 | } 294 | 295 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 296 | let pointer = __swift_bridge__$Vec_CursorIcon$get(vecPtr, index) 297 | if pointer == nil { 298 | return nil 299 | } else { 300 | return CursorIconRef(ptr: pointer!) 301 | } 302 | } 303 | 304 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 305 | let pointer = __swift_bridge__$Vec_CursorIcon$get_mut(vecPtr, index) 306 | if pointer == nil { 307 | return nil 308 | } else { 309 | return CursorIconRefMut(ptr: pointer!) 310 | } 311 | } 312 | 313 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 314 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_CursorIcon$as_ptr(vecPtr))) 315 | } 316 | 317 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 318 | __swift_bridge__$Vec_CursorIcon$len(vecPtr) 319 | } 320 | } 321 | 322 | 323 | public class Renderer: RendererRefMut { 324 | var isOwned: Bool = true 325 | 326 | public override init(ptr: UnsafeMutableRawPointer) { 327 | super.init(ptr: ptr) 328 | } 329 | 330 | deinit { 331 | if isOwned { 332 | __swift_bridge__$Renderer$_free(ptr) 333 | } 334 | } 335 | } 336 | extension Renderer { 337 | public convenience init(_ layer_ptr: UnsafeMutableRawPointer, _ width: UInt32, _ height: UInt32, _ display_scale: Float) { 338 | self.init(ptr: __swift_bridge__$Renderer$new(layer_ptr, width, height, display_scale)) 339 | } 340 | } 341 | public class RendererRefMut: RendererRef { 342 | public override init(ptr: UnsafeMutableRawPointer) { 343 | super.init(ptr: ptr) 344 | } 345 | } 346 | extension RendererRefMut { 347 | public func resize(_ width: UInt32, _ height: UInt32) { 348 | __swift_bridge__$Renderer$resize(ptr, width, height) 349 | } 350 | 351 | public func render(_ time: Double, _ input_events: RustVec, _ controller: BaseChatController) -> OutputState { 352 | OutputState(ptr: __swift_bridge__$Renderer$render(ptr, time, { let val = input_events; val.isOwned = false; return val.ptr }(), Unmanaged.passRetained(controller).toOpaque())) 353 | } 354 | } 355 | public class RendererRef { 356 | var ptr: UnsafeMutableRawPointer 357 | 358 | public init(ptr: UnsafeMutableRawPointer) { 359 | self.ptr = ptr 360 | } 361 | } 362 | extension Renderer: Vectorizable { 363 | public static func vecOfSelfNew() -> UnsafeMutableRawPointer { 364 | __swift_bridge__$Vec_Renderer$new() 365 | } 366 | 367 | public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { 368 | __swift_bridge__$Vec_Renderer$drop(vecPtr) 369 | } 370 | 371 | public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Renderer) { 372 | __swift_bridge__$Vec_Renderer$push(vecPtr, {value.isOwned = false; return value.ptr;}()) 373 | } 374 | 375 | public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { 376 | let pointer = __swift_bridge__$Vec_Renderer$pop(vecPtr) 377 | if pointer == nil { 378 | return nil 379 | } else { 380 | return (Renderer(ptr: pointer!) as! Self) 381 | } 382 | } 383 | 384 | public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 385 | let pointer = __swift_bridge__$Vec_Renderer$get(vecPtr, index) 386 | if pointer == nil { 387 | return nil 388 | } else { 389 | return RendererRef(ptr: pointer!) 390 | } 391 | } 392 | 393 | public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { 394 | let pointer = __swift_bridge__$Vec_Renderer$get_mut(vecPtr, index) 395 | if pointer == nil { 396 | return nil 397 | } else { 398 | return RendererRefMut(ptr: pointer!) 399 | } 400 | } 401 | 402 | public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { 403 | UnsafePointer(OpaquePointer(__swift_bridge__$Vec_Renderer$as_ptr(vecPtr))) 404 | } 405 | 406 | public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { 407 | __swift_bridge__$Vec_Renderer$len(vecPtr) 408 | } 409 | } 410 | 411 | 412 | @_cdecl("__swift_bridge__$BaseChatController$_free") 413 | func __swift_bridge__BaseChatController__free (ptr: UnsafeMutableRawPointer) { 414 | let _ = Unmanaged.fromOpaque(ptr).takeRetainedValue() 415 | } 416 | 417 | 418 | 419 | -------------------------------------------------------------------------------- /smooth-ui/scripts/build_debug.sh: -------------------------------------------------------------------------------- 1 | cargo build 2 | 3 | swift-bridge-cli create-package \ 4 | --bridges-dir ./generated \ 5 | --out-dir SmoothUI \ 6 | --macos target/debug/libembed.a \ 7 | --name SmoothUI -------------------------------------------------------------------------------- /smooth-ui/scripts/build_release.sh: -------------------------------------------------------------------------------- 1 | cargo build --release 2 | 3 | swift-bridge-cli create-package \ 4 | --bridges-dir ./generated \ 5 | --out-dir SmoothUI \ 6 | --macos target/release/libembed.a \ 7 | --name SmoothUI -------------------------------------------------------------------------------- /smooth-ui/src/chat_ui.rs: -------------------------------------------------------------------------------- 1 | use crate::ffi::ffi::{BaseChatController, ChatBubble}; 2 | 3 | use egui::{Align, Color32, Frame, Label, Layout, Rect, RichText, Rounding, ScrollArea, Shape, Stroke, UiBuilder, Vec2}; 4 | 5 | pub struct ChatUI { 6 | } 7 | 8 | impl ChatUI { 9 | 10 | pub fn ui(ui: &mut egui::Ui, controller: &BaseChatController) { 11 | ui.set_width(ui.available_width()); 12 | ui.set_height(ui.available_height()); 13 | 14 | ScrollArea::vertical() 15 | .animated(false) 16 | .auto_shrink([false, false]) 17 | .stick_to_bottom(true) 18 | .show(ui, |ui| { 19 | let count = controller.bubbles_count(); 20 | for i in 0..count { 21 | Self::bubble_ui(ui, controller.bubble_at_index(i)); 22 | } 23 | }); 24 | } 25 | 26 | fn bubble_ui(ui: &mut egui::Ui, bubble: ChatBubble) { 27 | let max_msg_width = ui.available_width() - 40.0; 28 | let inner_margin = 8.0; 29 | let outer_margin = 8.0; 30 | 31 | let layout = Layout::top_down(Align::Min); 32 | 33 | ui.with_layout(layout, |ui| { 34 | ui.set_max_width(max_msg_width); 35 | 36 | let mut measure = |text| { 37 | let label = Label::new(text); 38 | let (_pos, galley, _response) = label.layout_in_ui( 39 | &mut ui.new_child(UiBuilder::new().max_rect(ui.max_rect())), 40 | ); 41 | let rect = galley.rect; 42 | f32::min( 43 | rect.width() + inner_margin * 2.0 + outer_margin * 2.0 + 0.1, 44 | max_msg_width, 45 | ) 46 | }; 47 | 48 | let text = &bubble.text; 49 | let sender = &bubble.sender; 50 | 51 | let content = RichText::new(text).strong(); 52 | let mut msg_width = measure(content.clone()); 53 | 54 | let name = RichText::new(sender).small().strong(); 55 | let width = measure(name.clone()); 56 | msg_width = f32::max(msg_width, width); 57 | 58 | ui.set_min_width(msg_width); 59 | 60 | // Draw the message. 61 | let msg_color = Color32::from_rgb(0, 120, 254); 62 | 63 | let rounding = 8.0; 64 | let margin = 8.0; 65 | let response = Frame::none() 66 | .rounding(Rounding { 67 | ne: rounding, 68 | nw: 0.0, 69 | se: rounding, 70 | sw: rounding, 71 | }) 72 | .inner_margin(margin) 73 | .outer_margin(margin) 74 | .fill(msg_color) 75 | .show(ui, |ui| { 76 | ui.with_layout(Layout::top_down(Align::Min), |ui| { 77 | ui.label(name); 78 | ui.label(content); 79 | }); 80 | }) 81 | .response; 82 | 83 | 84 | // Draw a triangle pointing to the sender. 85 | let points = { 86 | let top = response.rect.left_top() + Vec2::splat(margin); 87 | let arrow_rect = Rect::from_two_pos( 88 | top, 89 | top + Vec2::new(-f32::from(rounding), rounding.into()), 90 | ); 91 | 92 | vec![ 93 | arrow_rect.left_top(), 94 | arrow_rect.right_top(), 95 | arrow_rect.right_bottom(), 96 | ] 97 | }; 98 | 99 | ui.painter() 100 | .add(Shape::convex_polygon(points, msg_color, Stroke::NONE)) 101 | }); 102 | } 103 | } -------------------------------------------------------------------------------- /smooth-ui/src/ffi.rs: -------------------------------------------------------------------------------- 1 | 2 | use crate::renderer::Renderer; 3 | use crate::input_output::{InputEvent, OutputState, CursorIcon}; 4 | 5 | use std::ffi::c_void; 6 | 7 | #[swift_bridge::bridge] 8 | pub mod ffi { 9 | 10 | #[swift_bridge(swift_repr = "struct")] 11 | struct ChatBubble { 12 | sender: String, 13 | text: String 14 | } 15 | 16 | extern "Rust" { 17 | type InputEvent; 18 | 19 | #[swift_bridge(associated_to = InputEvent)] 20 | fn from_pointer_moved(x: f32, y: f32) -> InputEvent; 21 | 22 | #[swift_bridge(associated_to = InputEvent)] 23 | fn from_mouse_wheel(x: f32, y: f32) -> InputEvent; 24 | 25 | #[swift_bridge(associated_to = InputEvent)] 26 | fn from_left_mouse_down(x: f32, y: f32, pressed: bool) -> InputEvent; 27 | 28 | #[swift_bridge(associated_to = InputEvent)] 29 | fn from_right_mouse_down(x: f32, y: f32, pressed: bool) -> InputEvent; 30 | 31 | #[swift_bridge(associated_to = InputEvent)] 32 | fn from_window_focused(focused: bool) -> InputEvent; 33 | } 34 | 35 | extern "Rust" { 36 | type OutputState; 37 | 38 | fn get_cursor_icon(&self) -> &CursorIcon; 39 | } 40 | 41 | extern "Rust" { 42 | type CursorIcon; 43 | 44 | fn is_default(&self) -> bool; 45 | 46 | fn is_pointing_hand(&self) -> bool; 47 | 48 | fn is_resize_horizontal(&self) -> bool; 49 | 50 | fn is_resize_vertical(&self) -> bool; 51 | 52 | fn is_text(&self) -> bool; 53 | } 54 | 55 | extern "Rust" { 56 | type Renderer; 57 | 58 | #[swift_bridge(init)] 59 | fn new(layer_ptr: *mut c_void, width: u32, height: u32, display_scale: f32) -> Renderer; 60 | 61 | fn resize(&mut self, width: u32, height: u32); 62 | 63 | fn render(&mut self, time: f64, input_events: Vec, controller: BaseChatController) -> OutputState; 64 | } 65 | 66 | extern "Swift" { 67 | type BaseChatController; 68 | 69 | fn bubbles_count(&self) -> usize; 70 | 71 | fn bubble_at_index(&self, index: usize) -> ChatBubble; 72 | } 73 | } 74 | 75 | // Extra interface for accessing the Input event from swift 76 | impl InputEvent { 77 | 78 | fn from_pointer_moved(x: f32, y: f32) -> Self { 79 | Self::PointerMoved(x, y) 80 | } 81 | 82 | fn from_mouse_wheel(x: f32, y: f32) -> Self { 83 | Self::MouseWheel(x, y) 84 | } 85 | 86 | fn from_left_mouse_down(x: f32, y: f32, pressed: bool) -> Self { 87 | Self::LeftMouseDown(x, y, pressed) 88 | } 89 | 90 | fn from_right_mouse_down(x: f32, y: f32, pressed: bool) -> Self { 91 | Self::RightMouseDown(x, y, pressed) 92 | } 93 | 94 | fn from_window_focused(focused: bool) -> Self { 95 | Self::WindowFocused(focused) 96 | } 97 | } 98 | 99 | impl CursorIcon { 100 | 101 | fn is_default(&self) -> bool { 102 | match self { 103 | Self::Default => true, 104 | _ => false 105 | } 106 | } 107 | 108 | fn is_pointing_hand(&self) -> bool { 109 | match self { 110 | Self::PointingHand => true, 111 | _ => false 112 | } 113 | } 114 | 115 | fn is_resize_horizontal(&self) -> bool { 116 | match self { 117 | Self::ResizeHorizontal => true, 118 | _ => false 119 | } 120 | } 121 | 122 | fn is_resize_vertical(&self) -> bool { 123 | match self { 124 | Self::ResizeVertical => true, 125 | _ => false 126 | } 127 | } 128 | 129 | fn is_text(&self) -> bool { 130 | match self { 131 | Self::Text => true, 132 | _ => false 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /smooth-ui/src/font_loader.rs: -------------------------------------------------------------------------------- 1 | use font_kit::source::SystemSource; 2 | 3 | pub fn load_font_data_by_name(font_name: &str) -> Result, String> { 4 | let font = SystemSource::new() 5 | .select_by_postscript_name(font_name) 6 | .map_err(|e| e.to_string())? 7 | .load() 8 | .map_err(|e| e.to_string())?; 9 | 10 | if let Some(data) = font.copy_font_data() { 11 | Ok(data.to_vec()) 12 | } else { 13 | Err("Failed to get font data".to_string()) 14 | } 15 | } -------------------------------------------------------------------------------- /smooth-ui/src/input_output.rs: -------------------------------------------------------------------------------- 1 | use egui::{Event, Modifiers}; 2 | 3 | pub enum InputEvent { 4 | PointerMoved(f32, f32), 5 | MouseWheel(f32, f32), 6 | LeftMouseDown(f32, f32, bool), 7 | RightMouseDown(f32, f32, bool), 8 | WindowFocused(bool) 9 | } 10 | 11 | impl Into for InputEvent { 12 | 13 | fn into(self) -> Event { 14 | match self { 15 | InputEvent::PointerMoved(x, y) => Event::PointerMoved(egui::Pos2::new(x, y)), 16 | InputEvent::MouseWheel(x, y) => Event::MouseWheel { unit: egui::MouseWheelUnit::Point, delta: egui::vec2(x, y), modifiers: Modifiers::default() }, 17 | InputEvent::LeftMouseDown(x, y, pressed) => Event::PointerButton { pos: egui::Pos2::new(x, y), button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::default() }, 18 | InputEvent::RightMouseDown(x, y, pressed) => Event::PointerButton { pos: egui::Pos2::new(x, y), button: egui::PointerButton::Secondary, pressed, modifiers: Modifiers::default() }, 19 | InputEvent::WindowFocused(focused) => Event::WindowFocused(focused), 20 | } 21 | } 22 | } 23 | 24 | pub struct OutputState { 25 | cursor_icon: CursorIcon, 26 | } 27 | 28 | impl OutputState { 29 | 30 | pub fn new(cursor_icon: CursorIcon) -> Self { 31 | Self { 32 | cursor_icon 33 | } 34 | } 35 | 36 | pub fn get_cursor_icon(&self) -> &CursorIcon { 37 | &self.cursor_icon 38 | } 39 | } 40 | 41 | pub enum CursorIcon { 42 | Default, 43 | PointingHand, 44 | ResizeHorizontal, 45 | ResizeVertical, 46 | Text, 47 | } 48 | 49 | impl From for CursorIcon { 50 | 51 | fn from(cursor_icon: egui::CursorIcon) -> Self { 52 | match cursor_icon { 53 | egui::CursorIcon::Default => Self::Default, 54 | egui::CursorIcon::PointingHand => Self::PointingHand, 55 | egui::CursorIcon::ResizeHorizontal | egui::CursorIcon::ResizeColumn => Self::ResizeHorizontal, 56 | egui::CursorIcon::ResizeVertical | egui::CursorIcon::ResizeRow => Self::ResizeVertical, 57 | egui::CursorIcon::Text => Self::Text, 58 | default => { 59 | println!("Unsupported cursor icon: {:?}", default); 60 | Self::Default 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /smooth-ui/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod ffi; 2 | mod renderer; 3 | mod font_loader; 4 | mod chat_ui; 5 | mod input_output; -------------------------------------------------------------------------------- /smooth-ui/src/renderer.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::BTreeMap, sync::Arc}; 2 | 3 | use futures::executor; 4 | 5 | use egui_wgpu_backend::{RenderPass, ScreenDescriptor}; 6 | 7 | use crate::{chat_ui::ChatUI, ffi::ffi::BaseChatController, font_loader::load_font_data_by_name, input_output::{InputEvent, OutputState}}; 8 | 9 | pub struct Renderer { 10 | // wgpu 11 | device: wgpu::Device, 12 | queue: wgpu::Queue, 13 | surface: wgpu::Surface<'static>, 14 | config: wgpu::SurfaceConfiguration, 15 | 16 | // egui 17 | context: egui::Context, 18 | raw_input: egui::RawInput, 19 | egui_rpass: RenderPass, 20 | } 21 | 22 | impl Renderer { 23 | pub fn new(layer_ptr: *mut std::ffi::c_void, width: u32, height: u32, display_scale: f32) -> Self { 24 | // Setup wgpu 25 | let descriptor = wgpu::InstanceDescriptor { 26 | backends: wgpu::Backends::METAL, 27 | ..Default::default() 28 | }; 29 | let instance = wgpu::Instance::new(descriptor); 30 | let surface = unsafe { 31 | instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::CoreAnimationLayer(layer_ptr)).unwrap() 32 | }; 33 | 34 | let adapter = executor::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { 35 | power_preference: wgpu::PowerPreference::HighPerformance, 36 | force_fallback_adapter: false, 37 | compatible_surface: Some(&surface), 38 | })) 39 | .expect("Failed to find an appropriate adapter"); 40 | 41 | let (device, queue) = executor::block_on(adapter.request_device(&wgpu::DeviceDescriptor { 42 | required_features: wgpu::Features::MAPPABLE_PRIMARY_BUFFERS | wgpu::Features::TEXTURE_COMPRESSION_ASTC_HDR, 43 | ..Default::default() 44 | }, None)) 45 | .expect("Failed to create device"); 46 | 47 | let tex_format = wgpu::TextureFormat::Bgra8UnormSrgb; 48 | 49 | let mut config = surface.get_default_config(&adapter, width, height).expect("Failed to create config"); 50 | config.format = tex_format; 51 | config.view_formats = vec![tex_format]; 52 | 53 | surface.configure(&device, &config); 54 | 55 | // Setup egui 56 | let context = egui::Context::default(); 57 | 58 | let display_font_data = load_font_data_by_name("SF Pro Text Medium"); 59 | 60 | if let Ok(display_font_data) = display_font_data { 61 | 62 | let mut fonts = egui::FontDefinitions::default(); 63 | 64 | let display_font_data = Arc::new(egui::FontData::from_owned(display_font_data)); 65 | fonts.font_data.insert("SF-Pro-Text-Medium".to_owned(), display_font_data); 66 | 67 | let display_family = egui::FontFamily::Name("SF-Pro-Text".into()); 68 | fonts.families.insert(display_family.clone(), vec!["SF-Pro-Text-Medium".to_owned()]); 69 | 70 | context.set_fonts(fonts); 71 | 72 | context.all_styles_mut(|style| { 73 | let text_styles: BTreeMap<_, _> = [ 74 | (egui::TextStyle::Heading, egui::FontId::new(11.0, display_family.clone())), 75 | (egui::TextStyle::Body, egui::FontId::new(13.0, display_family.clone())), 76 | 77 | (egui::TextStyle::Button, egui::FontId::new(14.0, display_family.clone())), 78 | (egui::TextStyle::Small, egui::FontId::new(10.0, display_family.clone())), 79 | ].into(); 80 | 81 | style.text_styles = text_styles; 82 | }); 83 | } 84 | 85 | let raw_input = egui::RawInput { 86 | viewport_id: egui::ViewportId::ROOT, 87 | viewports: std::iter::once((egui::ViewportId::ROOT, egui::ViewportInfo { 88 | native_pixels_per_point: Some(display_scale), 89 | focused: Some(true), 90 | ..Default::default() 91 | })).collect(), 92 | predicted_dt: 1.0 / 120.0, 93 | focused: true, 94 | system_theme: None, 95 | max_texture_side: Some(wgpu::Limits::default().max_texture_dimension_2d as usize), 96 | ..Default::default() 97 | }; 98 | let egui_rpass = RenderPass::new(&device, tex_format, 1); 99 | 100 | Self { 101 | device, 102 | queue, 103 | surface, 104 | config, 105 | context, 106 | raw_input, 107 | egui_rpass 108 | } 109 | } 110 | 111 | pub fn resize(&mut self, width: u32, height: u32) { 112 | let mut config = self.config.clone(); 113 | config.width = width; 114 | config.height = height; 115 | self.surface.configure(&self.device, &config); 116 | 117 | self.config = config; 118 | } 119 | 120 | pub fn render(&mut self, time: f64, input_events: Vec, controller: BaseChatController) -> OutputState { 121 | 122 | let device = &self.device; 123 | let queue = &self.queue; 124 | let surface = &self.surface; 125 | 126 | let ctx = &self.context; 127 | let egui_rpass = &mut self.egui_rpass; 128 | 129 | self.raw_input.time = Some(time); 130 | 131 | let rect = egui::Rect::from_min_size( 132 | egui::Pos2::ZERO, 133 | egui::vec2( 134 | self.config.width as f32 / ctx.pixels_per_point(), 135 | self.config.height as f32 / ctx.pixels_per_point() 136 | ) 137 | ); 138 | self.raw_input.screen_rect = Some(rect); 139 | self.raw_input.events = input_events.into_iter().map(|e| e.into()).collect(); 140 | 141 | let full_output = ctx.run(self.raw_input.take(), |ctx| { 142 | egui::CentralPanel::default().show(&ctx, |ui| { 143 | ChatUI::ui(ui, &controller); 144 | }); 145 | }); 146 | 147 | let paint_jobs = ctx.tessellate(full_output.shapes, ctx.pixels_per_point()); 148 | 149 | // Get the next frame 150 | let frame = surface.get_current_texture().expect("Failed to get next frame"); 151 | let view = frame.texture.create_view(&wgpu::TextureViewDescriptor::default()); 152 | 153 | // Begin rendering 154 | let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { 155 | label: Some("Render Encoder"), 156 | }); 157 | 158 | let screen_descriptor = ScreenDescriptor { 159 | physical_width: self.config.width, 160 | physical_height: self.config.height, 161 | scale_factor: ctx.pixels_per_point(), 162 | }; 163 | let tdelta: egui::TexturesDelta = full_output.textures_delta; 164 | 165 | egui_rpass 166 | .add_textures(&device, &queue, &tdelta) 167 | .expect("add texture ok"); 168 | 169 | egui_rpass.update_buffers(&device, &queue, &paint_jobs, &screen_descriptor); 170 | 171 | // Record all render passes. 172 | egui_rpass 173 | .execute( 174 | &mut encoder, 175 | &view, 176 | &paint_jobs, 177 | &screen_descriptor, 178 | Some(wgpu::Color::BLACK), 179 | ) 180 | .unwrap(); 181 | 182 | // Submit commands 183 | self.queue.submit(Some(encoder.finish())); 184 | 185 | // Present the frame 186 | frame.present(); 187 | 188 | egui_rpass.remove_textures(tdelta).unwrap(); 189 | 190 | OutputState::new(full_output.platform_output.cursor_icon.into()) 191 | } 192 | } --------------------------------------------------------------------------------