diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 3a03fe61..a865ad85 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(Calculator) add_subdirectory(HelloWorld) +add_subdirectory(Notepad) add_subdirectory(UICatalog) diff --git a/Examples/Notepad/CMakeLists.txt b/Examples/Notepad/CMakeLists.txt new file mode 100644 index 00000000..bb0f960d --- /dev/null +++ b/Examples/Notepad/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(Notepad + Notepad.swift) +add_custom_command(TARGET Notepad POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist $) +# FIXME(SR-12683) `@main` requires `-parse-as-library` +target_compile_options(Notepad PRIVATE + -parse-as-library) +target_link_libraries(Notepad PRIVATE + SwiftWin32) diff --git a/Examples/Notepad/Info.plist b/Examples/Notepad/Info.plist new file mode 100644 index 00000000..ba40d8b6 --- /dev/null +++ b/Examples/Notepad/Info.plist @@ -0,0 +1,23 @@ + + + + + ApplicationSceneManifest + + ApplicationSupportsMultipleScenes + + SceneConfigurations + + UIWindowSceneSessionRoleApplication + + + SceneConfigurationName + Default Configuration + SceneDelegateClassName + Notepad.Notepad + + + + + + diff --git a/Examples/Notepad/Notepad.swift b/Examples/Notepad/Notepad.swift new file mode 100644 index 00000000..2a04ea85 --- /dev/null +++ b/Examples/Notepad/Notepad.swift @@ -0,0 +1,36 @@ +/** + * Copyright © 2020 Puyan Lotfi + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + **/ + +import SwiftWin32 + +@main +final class Notepad: ApplicationDelegate { + var window: Window? + lazy var textview: TextView = + TextView(frame: Rect(x: 10.0, y: 10.0, width: 750.0, height: 750.0)) +} + +extension Notepad: SceneDelegate { + func scene( + _ scene: Scene, willConnectTo session: SceneSession, + options: Scene.ConnectionOptions + ) { + guard let windowScene = scene as? WindowScene else { return } + + self.window = Window(windowScene: windowScene) + self.window?.makeKeyAndVisible() + self.window?.addSubview(self.textview) + + self.textview.text = """ + He piled upon the whale’s white hump the sum of all the general rage and + hate felt by his whole race from Adam down; and then, as if his chest had + been a mortar, he burst his hot heart’s shell upon it. + """ + + self.window?.makeKeyAndVisible() + } +} diff --git a/Examples/Notepad/main.swift b/Examples/Notepad/main.swift new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Examples/Notepad/main.swift @@ -0,0 +1 @@ +