Canvatorium Visio Lab 5029
Volumes can have toolbars?
I need to stop reinventing the wheel
We can add the toolbar modifier to a RealityView and use the placement .bottomOrnament
RealityView { content, attachments in ... }
.toolbar {
ToolbarItemGroup(placement: .bottomOrnament) { ... }
}
Full lab code:
enum IndirectTransformModeString: String {
case none = "none"
case move = "move"
case rotate = "rotate"
case scale = "scale"
}
struct Lab5029: View {
@State private var transformMode: IndirectTransformModeString = .none
var body: some View {
ZStack(alignment: Alignment(horizontal: .center, vertical: .bottom)) {
RealityView { content, attachments in
if let root = try? await Entity(named: "GestureLab", in: realityKitContentBundle) {
root.position = [0, -0.45, 0]
root.scale = [2,2,2]
content.add(root)
if let attachmentEntity = attachments.entity(for: "Label") {
attachmentEntity.position = [0, -0.3, 0]
content.add(attachmentEntity)
}
}
} update: { content, attachments in
// Not using update in this lab
} attachments: {
// Create an attachment for the text label
Attachment(id: "Label") {
Text(transformMode.rawValue)
.font(.extraLargeTitle2)
.padding(18)
.background(.black)
.cornerRadius(12)
}
}
// We can use toolbars on Volumes? I need to stop reinventing the wheel ????♂️
.toolbar {
// .bottomOrnament seems to be the only placement that works
ToolbarItemGroup(placement: .bottomOrnament) {
Button {
transformMode = .none
} label: {
Image(systemName: "nosign")
}
.foregroundStyle(transformMode == .none ? .blue : .white)
Button {
transformMode = .move
} label: {
Image(systemName: "move.3d")
}
.foregroundStyle(transformMode == .move ? .blue : .white)
Button {
transformMode = .rotate
} label: {
Image(systemName: "rotate.3d")
}
.foregroundStyle(transformMode == .rotate ? .blue : .white)
Button {
transformMode = .scale
} label: {
Image(systemName: "scale.3d")
}
.foregroundStyle(transformMode == .scale ? .blue : .white)
}
}
}
}
}