Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] SDL2 Renderer for tokamak #553

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
"revision" : "f8a9c997c3c1dab4e216a8ec9014e23144cbab37",
"version" : "1.9.0"
}
},
{
"identity" : "swiftsdl2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ctreffs/SwiftSDL2.git",
"state" : {
"revision" : "30a2886bd68e43fc19ba29b63ffe230ac0e4db7a",
"version" : "1.4.1"
}
}
],
"version" : 2
Expand Down
23 changes: 23 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6

Check warning on line 1 in Package.swift

View workflow job for this annotation

GitHub Actions / codecov

The current code coverage percentage is passing with 20.47% (minimum allowed: 15%).

import PackageDescription

Expand Down Expand Up @@ -27,6 +27,10 @@
name: "TokamakStaticHTMLDemo",
targets: ["TokamakStaticHTMLDemo"]
),
.library(
name: "TokamakSDL2",
targets: ["TokamakSDL2"]
),
.library(
name: "TokamakGTK",
targets: ["TokamakGTK"]
Expand Down Expand Up @@ -65,6 +69,10 @@
url: "https://github.com/pointfreeco/swift-snapshot-testing.git",
from: "1.9.0"
),
.package(
url: "https://github.com/ctreffs/SwiftSDL2.git",
from: "1.4.1"
),
],
targets: [
// Targets are the basic building blocks of a package. A target can define
Expand All @@ -85,6 +93,7 @@
dependencies: [
.target(name: "TokamakDOM", condition: .when(platforms: [.wasi])),
.target(name: "TokamakGTK", condition: .when(platforms: [.linux])),
.target(name: "TokamakSDL2", condition: .when(platforms: [.linux, .windows, .android])),
]
),
.systemLibrary(
Expand Down Expand Up @@ -119,6 +128,20 @@
),
]
),
.target(
name: "TokamakSDL2",
dependencies: [
"TokamakCore",
.product(
name: "OpenCombineShim",
package: "OpenCombine"
),
.product(
name: "SDL",
package: "SwiftSDL2"
),
]
),
.executableTarget(
name: "TokamakGTKDemo",
dependencies: ["TokamakGTK"],
Expand Down
39 changes: 39 additions & 0 deletions Sources/TokamakSDL2/App/App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Created by Szymon on 2/10/23.
//

import OpenCombineShim
import SDL
import TokamakCore

public extension App {
static func _launch(_ app: Self, with configuration: _AppConfiguration) {
_ = Unmanaged.passRetained(SDLRenderer(app, configuration.rootEnvironment))
}

static func _setTitle(_ title: String) {
guard let window = SDLRenderer.shared?.window else { return }
SDL_SetWindowTitle(window, title)
}

var _phasePublisher: AnyPublisher<ScenePhase, Never> {
CurrentValueSubject(.active).eraseToAnyPublisher()
}

var _colorSchemePublisher: AnyPublisher<ColorScheme, Never> {
CurrentValueSubject(.light).eraseToAnyPublisher()
}
}
256 changes: 256 additions & 0 deletions Sources/TokamakSDL2/Core.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Created by Szymon on 30/09/23.
//

import TokamakCore

// MARK: Environment & State

public typealias DynamicProperty = TokamakCore.DynamicProperty

public typealias Environment = TokamakCore.Environment
public typealias EnvironmentKey = TokamakCore.EnvironmentKey
public typealias EnvironmentObject = TokamakCore.EnvironmentObject
public typealias EnvironmentValues = TokamakCore.EnvironmentValues

public typealias PreferenceKey = TokamakCore.PreferenceKey

public typealias Binding = TokamakCore.Binding
public typealias ObservableObject = TokamakCore.ObservableObject
public typealias ObservedObject = TokamakCore.ObservedObject
public typealias Published = TokamakCore.Published
public typealias State = TokamakCore.State
public typealias StateObject = TokamakCore.StateObject

// MARK: Modifiers & Styles

public typealias ViewModifier = TokamakCore.ViewModifier
public typealias ModifiedContent = TokamakCore.ModifiedContent

public typealias DefaultTextFieldStyle = TokamakCore.DefaultTextFieldStyle
public typealias PlainTextFieldStyle = TokamakCore.PlainTextFieldStyle
public typealias RoundedBorderTextFieldStyle = TokamakCore.RoundedBorderTextFieldStyle
public typealias SquareBorderTextFieldStyle = TokamakCore.SquareBorderTextFieldStyle

public typealias DefaultListStyle = TokamakCore.DefaultListStyle
public typealias PlainListStyle = TokamakCore.PlainListStyle
public typealias InsetListStyle = TokamakCore.InsetListStyle
public typealias GroupedListStyle = TokamakCore.GroupedListStyle
public typealias InsetGroupedListStyle = TokamakCore.InsetGroupedListStyle
public typealias SidebarListStyle = TokamakCore.SidebarListStyle

public typealias DefaultPickerStyle = TokamakCore.DefaultPickerStyle
public typealias PopUpButtonPickerStyle = TokamakCore.PopUpButtonPickerStyle
public typealias RadioGroupPickerStyle = TokamakCore.RadioGroupPickerStyle
public typealias SegmentedPickerStyle = TokamakCore.SegmentedPickerStyle
public typealias WheelPickerStyle = TokamakCore.WheelPickerStyle

public typealias ToggleStyle = TokamakCore.ToggleStyle
public typealias ToggleStyleConfiguration = TokamakCore.ToggleStyleConfiguration

public typealias ButtonStyle = TokamakCore.ButtonStyle
public typealias ButtonStyleConfiguration = TokamakCore.ButtonStyleConfiguration
public typealias DefaultButtonStyle = TokamakCore.DefaultButtonStyle
public typealias PlainButtonStyle = TokamakCore.PlainButtonStyle
public typealias BorderedButtonStyle = TokamakCore.BorderedButtonStyle
public typealias BorderedProminentButtonStyle = TokamakCore.BorderedProminentButtonStyle
public typealias BorderlessButtonStyle = TokamakCore.BorderlessButtonStyle
public typealias LinkButtonStyle = TokamakCore.LinkButtonStyle

public typealias ControlGroupStyle = TokamakCore.ControlGroupStyle
public typealias AutomaticControlGroupStyle = TokamakCore.AutomaticControlGroupStyle
public typealias NavigationControlGroupStyle = TokamakCore.NavigationControlGroupStyle

public typealias TextFieldStyle = TokamakCore.TextFieldStyle

public typealias FillStyle = TokamakCore.FillStyle
public typealias ShapeStyle = TokamakCore.ShapeStyle
public typealias StrokeStyle = TokamakCore.StrokeStyle

public typealias ColorScheme = TokamakCore.ColorScheme

// MARK: Shapes

public typealias Shape = TokamakCore.Shape

public typealias Capsule = TokamakCore.Capsule
public typealias Circle = TokamakCore.Circle
public typealias Ellipse = TokamakCore.Ellipse
public typealias Path = TokamakCore.Path
public typealias Rectangle = TokamakCore.Rectangle
public typealias RoundedRectangle = TokamakCore.RoundedRectangle
public typealias ContainerRelativeShape = TokamakCore.ContainerRelativeShape

// MARK: Shape Styles

public typealias HierarchicalShapeStyle = TokamakCore.HierarchicalShapeStyle

public typealias ForegroundStyle = TokamakCore.ForegroundStyle
public typealias BackgroundStyle = TokamakCore.BackgroundStyle

public typealias Material = TokamakCore.Material

public typealias Gradient = TokamakCore.Gradient
public typealias LinearGradient = TokamakCore.LinearGradient
public typealias RadialGradient = TokamakCore.RadialGradient
public typealias EllipticalGradient = TokamakCore.EllipticalGradient
public typealias AngularGradient = TokamakCore.AngularGradient

// MARK: Primitive values

public typealias Color = TokamakCore.Color
public typealias Font = TokamakCore.Font

#if !canImport(CoreGraphics)
public typealias CGAffineTransform = TokamakCore.CGAffineTransform
#endif

public typealias Angle = TokamakCore.Angle
public typealias Axis = TokamakCore.Axis
public typealias UnitPoint = TokamakCore.UnitPoint

public typealias Edge = TokamakCore.Edge

public typealias Prominence = TokamakCore.Prominence

public typealias GraphicsContext = TokamakCore.GraphicsContext

public typealias TimelineSchedule = TokamakCore.TimelineSchedule
public typealias TimelineScheduleMode = TokamakCore.TimelineScheduleMode
public typealias AnimationTimelineSchedule = TokamakCore.AnimationTimelineSchedule
public typealias EveryMinuteTimelineSchedule = TokamakCore.EveryMinuteTimelineSchedule
public typealias ExplicitTimelineSchedule = TokamakCore.ExplicitTimelineSchedule
public typealias PeriodicTimelineSchedule = TokamakCore.PeriodicTimelineSchedule

public typealias HorizontalAlignment = TokamakCore.HorizontalAlignment
public typealias VerticalAlignment = TokamakCore.VerticalAlignment

// MARK: Views

public typealias Alignment = TokamakCore.Alignment
public typealias Button = TokamakCore.Button
public typealias Canvas = TokamakCore.Canvas
public typealias ControlGroup = TokamakCore.ControlGroup
public typealias ControlSize = TokamakCore.ControlSize
public typealias DatePicker = TokamakCore.DatePicker
public typealias DisclosureGroup = TokamakCore.DisclosureGroup
public typealias Divider = TokamakCore.Divider
public typealias ForEach = TokamakCore.ForEach
public typealias GeometryReader = TokamakCore.GeometryReader
public typealias GridItem = TokamakCore.GridItem
public typealias Group = TokamakCore.Group
public typealias HStack = TokamakCore.HStack
public typealias Image = TokamakCore.Image
public typealias LazyHGrid = TokamakCore.LazyHGrid
public typealias LazyVGrid = TokamakCore.LazyVGrid
public typealias Link = TokamakCore.Link
public typealias List = TokamakCore.List
public typealias NavigationLink = TokamakCore.NavigationLink
public typealias NavigationView = TokamakCore.NavigationView
public typealias OutlineGroup = TokamakCore.OutlineGroup
public typealias Picker = TokamakCore.Picker
public typealias ProgressView = TokamakCore.ProgressView
public typealias ScrollView = TokamakCore.ScrollView
public typealias Section = TokamakCore.Section
public typealias SecureField = TokamakCore.SecureField
public typealias Slider = TokamakCore.Slider
public typealias Spacer = TokamakCore.Spacer
public typealias Text = TokamakCore.Text
public typealias TextEditor = TokamakCore.TextEditor
public typealias TextField = TokamakCore.TextField
public typealias TimelineView = TokamakCore.TimelineView
public typealias Toggle = TokamakCore.Toggle
public typealias VStack = TokamakCore.VStack
public typealias ZStack = TokamakCore.ZStack

// MARK: Special Views

public typealias View = TokamakCore.View
public typealias AnyView = TokamakCore.AnyView
public typealias EmptyView = TokamakCore.EmptyView

// MARK: Layout

public typealias Layout = TokamakCore.Layout
public typealias AnyLayout = TokamakCore.AnyLayout
public typealias LayoutProperties = TokamakCore.LayoutProperties
public typealias LayoutSubviews = TokamakCore.LayoutSubviews
public typealias LayoutSubview = TokamakCore.LayoutSubview
public typealias LayoutValueKey = TokamakCore.LayoutValueKey
public typealias ProposedViewSize = TokamakCore.ProposedViewSize
public typealias ViewSpacing = TokamakCore.ViewSpacing

// MARK: Toolbars

public typealias ToolbarItem = TokamakCore.ToolbarItem
public typealias ToolbarItemGroup = TokamakCore.ToolbarItemGroup
public typealias ToolbarItemPlacement = TokamakCore.ToolbarItemPlacement
public typealias ToolbarContentBuilder = TokamakCore.ToolbarContentBuilder

// MARK: Text

public typealias TextAlignment = TokamakCore.TextAlignment

// MARK: App & Scene

public typealias App = TokamakCore.App
public typealias _AppConfiguration = TokamakCore._AppConfiguration
public typealias Scene = TokamakCore.Scene
public typealias WindowGroup = TokamakCore.WindowGroup
public typealias ScenePhase = TokamakCore.ScenePhase
public typealias AppStorage = TokamakCore.AppStorage
public typealias SceneStorage = TokamakCore.SceneStorage

// MARK: Misc

public typealias ViewBuilder = TokamakCore.ViewBuilder

// MARK: Animation

public typealias Animation = TokamakCore.Animation
public typealias Transaction = TokamakCore.Transaction

public typealias Animatable = TokamakCore.Animatable
public typealias AnimatablePair = TokamakCore.AnimatablePair
public typealias EmptyAnimatableData = TokamakCore.EmptyAnimatableData

public typealias AnimatableModifier = TokamakCore.AnimatableModifier

public typealias AnyTransition = TokamakCore.AnyTransition

public func withTransaction<Result>(
_ transaction: Transaction,
_ body: () throws -> Result
) rethrows -> Result {
try TokamakCore.withTransaction(transaction, body)
}

public func withAnimation<Result>(
_ animation: Animation? = .default,
_ body: () throws -> Result
) rethrows -> Result {
try TokamakCore.withAnimation(animation, body)
}

// FIXME: I would put this inside TokamakCore, but for
// some reason it doesn't get exported with the typealias
public extension Text {
static func + (lhs: Self, rhs: Self) -> Self {
_concatenating(lhs: lhs, rhs: rhs)
}
}

public typealias PreviewProvider = TokamakCore.PreviewProvider
Loading
Loading