Post

Replies

Boosts

Views

Activity

Tile & Scale an Image
Working on a macOS app. I need to display user-added images as a background to the view, with all of: Tiling (auto repeat in both axes) Scaling (user-configured scale of the image) Offset (user-configured offset) I've been able to achieve scaling and offset with: Image(nsImage: nsImage) .scaleEffect(mapImage.scale) .offset(mapImage.offset) .frame(width: scaledImageSize.width, height: scaledImageSize.height) But when I try to incorporate tiling into that with .resizable(resizingMode: .tile) everything breaks. Is there a way to position the "anchor" of an image, scale it, and tile it in both axes to fill a container view?
1
0
492
Nov ’24
Auxiliary window control in Mac SwiftUI & SwiftData app
I've got a Mac Document App using SwiftUI and SwiftData. All is working well with the models editing, etc. There's a feature I need to implement, and can't seem to make it work. From the main window of the app, I need to be able to launch an auxilliary window containing a view-only representation of the model being edited. The required workflow is something like this: Open a document (SwiftData) Select a sub-model of the document Launch the aux window to display the view of the model data (must be in a separate window, because it will be on a different physical display) Continue making edits to the sub-model, as they are reflected in the other window So, below is the closest I've been able to come, and it's still not working at all. What happens with this code: Click on the "Present" button, the encounter-presentation Window opens, but never loads the data model or the view. It's just an empty window. This is the spot in the main view where the auxiliary window will be launched: @State var presenting: Presentation? = nil var presentingThisEncounter: Bool { presenting?.encounter.id == encounter.id } @Environment(\.openWindow) var openWindow ... if presentingThisEncounter { Button(action: { presenting = nil }) { Label("Stop", systemImage: "stop.fill") .padding(.horizontal, 4) } .preference(key: PresentationPreferenceKey.self, value: presenting) } else { Button(action: { presenting = Presentation(encounter: encounter, display: activeDisplay) openWindow(id: "encounter-presentation") }) { Label("Present", systemImage: "play.fill") .padding(.horizontal, 4) } .preference(key: PresentationPreferenceKey.self, value: nil) } Presentation is declared as: class Presentation: Observable, Equatable { Here's the contents of the App, where the DocumentGroup & model is instantiated, and the aux window is managed: @State var presentation: Presentation? var body: some Scene { DocumentGroup(editing: .encounterList, migrationPlan: EncounterListMigrationPlan.self) { ContentView() .onPreferenceChange(PresentationPreferenceKey.self) { self.presentation = $0 } } Window("Presentation", id: "encounter-presentation") { VStack { if let presentation = presentation { PresentingView(presentation: presentation) } } } } And the definition of PresentationPreferenceKey: struct PresentationPreferenceKey: PreferenceKey { static var defaultValue: Presentation? static func reduce(value: inout Presentation?, nextValue: () -> Presentation?) { value = nextValue() } }
2
0
637
Oct ’24
Side-by-side sections in UICollectionViewCompositionalLayout?
I'm scratching my head trying to figure out how to use the new Compositional layout approach to achieve a layout like the following:+-----------+ +--------------------------+ | section 0 | | section 2 | |-----------| |--------------------------| | | | | |-----------| |--------------------------| | | | | |-----------| |--------------------------| | | | | +-----------+ |--------------------------| | | +-----------+ |--------------------------| | section 1 | | | |-----------| |--------------------------| | | | | |-----------| +--------------------------+ | | |-----------| +--------------------------+ | | | section 3 | +-----------+ |--------------------------| | | |--------------------------| | | +--------------------------+It seems that sections can only flow top to bottom? Am I stuck using the old approach of building a custom layout manually? Or am I missing something?
Topic: UI Frameworks SubTopic: UIKit Tags:
8
0
4.6k
Jun ’21
Tile & Scale an Image
Working on a macOS app. I need to display user-added images as a background to the view, with all of: Tiling (auto repeat in both axes) Scaling (user-configured scale of the image) Offset (user-configured offset) I've been able to achieve scaling and offset with: Image(nsImage: nsImage) .scaleEffect(mapImage.scale) .offset(mapImage.offset) .frame(width: scaledImageSize.width, height: scaledImageSize.height) But when I try to incorporate tiling into that with .resizable(resizingMode: .tile) everything breaks. Is there a way to position the "anchor" of an image, scale it, and tile it in both axes to fill a container view?
Replies
1
Boosts
0
Views
492
Activity
Nov ’24
Auxiliary window control in Mac SwiftUI & SwiftData app
I've got a Mac Document App using SwiftUI and SwiftData. All is working well with the models editing, etc. There's a feature I need to implement, and can't seem to make it work. From the main window of the app, I need to be able to launch an auxilliary window containing a view-only representation of the model being edited. The required workflow is something like this: Open a document (SwiftData) Select a sub-model of the document Launch the aux window to display the view of the model data (must be in a separate window, because it will be on a different physical display) Continue making edits to the sub-model, as they are reflected in the other window So, below is the closest I've been able to come, and it's still not working at all. What happens with this code: Click on the "Present" button, the encounter-presentation Window opens, but never loads the data model or the view. It's just an empty window. This is the spot in the main view where the auxiliary window will be launched: @State var presenting: Presentation? = nil var presentingThisEncounter: Bool { presenting?.encounter.id == encounter.id } @Environment(\.openWindow) var openWindow ... if presentingThisEncounter { Button(action: { presenting = nil }) { Label("Stop", systemImage: "stop.fill") .padding(.horizontal, 4) } .preference(key: PresentationPreferenceKey.self, value: presenting) } else { Button(action: { presenting = Presentation(encounter: encounter, display: activeDisplay) openWindow(id: "encounter-presentation") }) { Label("Present", systemImage: "play.fill") .padding(.horizontal, 4) } .preference(key: PresentationPreferenceKey.self, value: nil) } Presentation is declared as: class Presentation: Observable, Equatable { Here's the contents of the App, where the DocumentGroup & model is instantiated, and the aux window is managed: @State var presentation: Presentation? var body: some Scene { DocumentGroup(editing: .encounterList, migrationPlan: EncounterListMigrationPlan.self) { ContentView() .onPreferenceChange(PresentationPreferenceKey.self) { self.presentation = $0 } } Window("Presentation", id: "encounter-presentation") { VStack { if let presentation = presentation { PresentingView(presentation: presentation) } } } } And the definition of PresentationPreferenceKey: struct PresentationPreferenceKey: PreferenceKey { static var defaultValue: Presentation? static func reduce(value: inout Presentation?, nextValue: () -> Presentation?) { value = nextValue() } }
Replies
2
Boosts
0
Views
637
Activity
Oct ’24
Side-by-side sections in UICollectionViewCompositionalLayout?
I'm scratching my head trying to figure out how to use the new Compositional layout approach to achieve a layout like the following:+-----------+ +--------------------------+ | section 0 | | section 2 | |-----------| |--------------------------| | | | | |-----------| |--------------------------| | | | | |-----------| |--------------------------| | | | | +-----------+ |--------------------------| | | +-----------+ |--------------------------| | section 1 | | | |-----------| |--------------------------| | | | | |-----------| +--------------------------+ | | |-----------| +--------------------------+ | | | section 3 | +-----------+ |--------------------------| | | |--------------------------| | | +--------------------------+It seems that sections can only flow top to bottom? Am I stuck using the old approach of building a custom layout manually? Or am I missing something?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
8
Boosts
0
Views
4.6k
Activity
Jun ’21