Add `Image` implementation to the GTK renderer (#343)
* Add rudimentary Image support * Added Image implementation and sample image * Updated sample and scaled down image * Removed commented code * Update main.swift Co-authored-by: Morten Bek Ditlevsen <morten@ka-ching.dk>
This commit is contained in:
parent
99bcfd12b9
commit
6ef59293f5
|
@ -96,7 +96,8 @@ let package = Package(
|
||||||
),
|
),
|
||||||
.target(
|
.target(
|
||||||
name: "TokamakGTKDemo",
|
name: "TokamakGTKDemo",
|
||||||
dependencies: ["TokamakGTK"]
|
dependencies: ["TokamakGTK"],
|
||||||
|
resources: [.copy("logo-header.png")]
|
||||||
),
|
),
|
||||||
.target(
|
.target(
|
||||||
name: "TokamakStaticHTML",
|
name: "TokamakStaticHTML",
|
||||||
|
|
|
@ -93,6 +93,7 @@ public typealias GeometryReader = TokamakCore.GeometryReader
|
||||||
public typealias GridItem = TokamakCore.GridItem
|
public typealias GridItem = TokamakCore.GridItem
|
||||||
public typealias Group = TokamakCore.Group
|
public typealias Group = TokamakCore.Group
|
||||||
public typealias HStack = TokamakCore.HStack
|
public typealias HStack = TokamakCore.HStack
|
||||||
|
public typealias Image = TokamakCore.Image
|
||||||
public typealias LazyHGrid = TokamakCore.LazyHGrid
|
public typealias LazyHGrid = TokamakCore.LazyHGrid
|
||||||
public typealias LazyVGrid = TokamakCore.LazyVGrid
|
public typealias LazyVGrid = TokamakCore.LazyVGrid
|
||||||
public typealias List = TokamakCore.List
|
public typealias List = TokamakCore.List
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright 2020 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 Morten Bek Ditlevsen on 14/12/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
import CGTK
|
||||||
|
import Foundation
|
||||||
|
import TokamakCore
|
||||||
|
|
||||||
|
extension Image: AnyWidget {
|
||||||
|
func new(_ application: UnsafeMutablePointer<GtkApplication>) -> UnsafeMutablePointer<GtkWidget> {
|
||||||
|
let proxy = _ImageProxy(self)
|
||||||
|
let imagePath = proxy.path ?? proxy.name
|
||||||
|
let img = gtk_image_new_from_file(imagePath)!
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
|
func update(widget: Widget) {
|
||||||
|
if case let .widget(w) = widget.storage {
|
||||||
|
let proxy = _ImageProxy(self)
|
||||||
|
let imagePath = proxy.path ?? proxy.name
|
||||||
|
|
||||||
|
w.withMemoryRebound(to: GtkImage.self, capacity: 1) {
|
||||||
|
gtk_image_set_from_file($0, imagePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
|
@ -49,6 +49,7 @@ struct TokamakGTKDemo: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup("Test Scene") {
|
WindowGroup("Test Scene") {
|
||||||
List {
|
List {
|
||||||
|
Image("logo-header.png", bundle: Bundle.module, label: Text("Tokamak Demo"))
|
||||||
Counter()
|
Counter()
|
||||||
PickerDemo()
|
PickerDemo()
|
||||||
ForEach(1..<100) {
|
ForEach(1..<100) {
|
||||||
|
|
Loading…
Reference in New Issue