Skip to content

Commit

Permalink
New resize mechanism of browser view
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Dec 3, 2021
1 parent e4d9080 commit 73b963e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct ContentView: View {
@Environment(\.colorScheme) var deviceColorScheme: ColorScheme

@State private var browserIsMaximized = false
@State private var browserSize = SIMD2<Int>(400, 200)

#if os(macOS)
let leftPanelWidth : CGFloat = 200
Expand All @@ -72,12 +73,13 @@ struct ContentView: View {
//ParameterListView(document: document, updateView: $updateView)
// .frame(minWidth: leftPanelWidth, idealWidth: leftPanelWidth, maxWidth: leftPanelWidth)

VSplitView {
ZStack(alignment: .bottomLeading) {

MetalManiaView(document.model)
.frame(maxHeight: browserIsMaximized ? 0 : .infinity)

BrowserView(document: $document)
BrowserView(document, size: $browserSize)
.frame(maxWidth: browserIsMaximized ? .infinity : CGFloat(browserSize.x), maxHeight: browserIsMaximized ? .infinity : CGFloat(browserSize.y))

/*
ZStack(alignment: .topTrailing) {
Expand Down
58 changes: 50 additions & 8 deletions Shared/Views/BrowserView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ struct BrowserView: View {
]
) var shaders: FetchedResults<ShaderEntity>

@Binding var document : ShaderManiaDocument
var document : ShaderManiaDocument
var size : Binding<SIMD2<Int>>

@State var sizeBuffer : SIMD2<Int>

@State private var mode : Mode = .editor

Expand All @@ -42,6 +45,12 @@ struct BrowserView: View {

@State private var browserIsMaximized = false

init(_ document: ShaderManiaDocument, size: Binding<SIMD2<Int>>) {
self.document = document
self.size = size
_sizeBuffer = State(initialValue: SIMD2<Int>(self.size.wrappedValue.x, self.size.wrappedValue.y))
}

var body: some View {

VStack(alignment: .center, spacing: 0) {
Expand All @@ -59,8 +68,9 @@ struct BrowserView: View {
Image(systemName: mode == .editor ? "e.square.fill" : "e.square")
.imageScale(.large)
}
.buttonStyle(.borderless)
.buttonStyle(.plain)
.padding(.leading, 12)
.keyboardShortcut("1")

Button(action: {
mode = .browser
Expand All @@ -69,17 +79,19 @@ struct BrowserView: View {
Image(systemName: mode == .browser ? "b.square.fill" : "b.square")
.imageScale(.large)
}
.buttonStyle(.borderless)

.buttonStyle(.plain)
.keyboardShortcut("2")

Button(action: {
mode = .timeline
})
{
Image(systemName: mode == .timeline ? "t.square.fill" : "t.square")
.imageScale(.large)
}
.buttonStyle(.borderless)

.buttonStyle(.plain)
.keyboardShortcut("3")

Divider()

Text(selectedName)
Expand All @@ -89,16 +101,46 @@ struct BrowserView: View {

Button(action: {
browserIsMaximized.toggle()
document.model.browserIsMaximized.send(browserIsMaximized)
document.model.browserIsMaximized.send(browserIsMaximized)
})
{
Image(systemName: browserIsMaximized == false ? "arrow.up.left.and.arrow.down.right" : "arrow.down.right.and.arrow.up.left")
.imageScale(.large)
}
.buttonStyle(.borderless)
.buttonStyle(.plain)

Divider()

Button(action: {
})
{
Image(systemName: "arrow.up.and.down.and.arrow.left.and.right")
.imageScale(.large)
}
.buttonStyle(.plain)
.padding(.trailing, 8)
.disabled(browserIsMaximized)
.simultaneousGesture(
DragGesture(minimumDistance: 0)
.onChanged({ info in
let deltaX = Int(info.location.x - info.startLocation.x)
let deltaY = Int(info.startLocation.y - info.location.y)

if self.size.wrappedValue.x + deltaX > 200 {
self.size.wrappedValue.x += deltaX
}

if self.size.wrappedValue.y + deltaY > 100 {
self.size.wrappedValue.y += deltaY
}
})
.onEnded({ info in
sizeBuffer = SIMD2<Int>(self.size.wrappedValue.x, self.size.wrappedValue.y)
})
)
}
.frame(height: 25)
.background(Color.accentColor)

// Edit Asset name
.popover(isPresented: self.$showAssetNamePopover,
Expand Down

0 comments on commit 73b963e

Please sign in to comment.