Skip to content

Commit

Permalink
feat: make editor & diagram mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
Build Pipeline committed Nov 18, 2022
1 parent 5efa557 commit 33f940e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions PlantUML/PlantUMLContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import PlantUMLKeyboard
import LineEditor

// [Managing Focus in SwiftUI List Views](https://peterfriese.dev/posts/swiftui-list-focus/)
//enum Focusable: Hashable {
// case none
// case row(id: String)
//}
// enum Focusable: Hashable {
// case none
// case row(id: String)
// }

typealias PlantUMLLineEditorView = LineEditorView<SyntaxStructure,PlantUMLKeyboardView>

Expand All @@ -28,7 +28,9 @@ struct PlantUMLContentView: View {
@Binding var document: PlantUMLDocument

@State private var isEditorVisible = true
@State private var isPreviewVisible = true
//@State private var isPreviewVisible = false
private var isDiagramVisible:Bool { !isEditorVisible}

@State private var isScaleToFit = true
@State private var fontSize = CGFloat(12)
@State var showLine:Bool = false
Expand All @@ -44,7 +46,7 @@ struct PlantUMLContentView: View {

}
Divider().background(Color.blue).padding()
if isPreviewVisible {
if isDiagramVisible {
if isScaleToFit {
PlantUMLDiagramView( url: diagram.buildURL() )
}
Expand All @@ -56,13 +58,20 @@ struct PlantUMLContentView: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
EditButton()
SaveButton()
fontSizeView()
toggleLineNumberView()
if isEditorVisible {
HStack {
SaveButton()
EditButton()
Divider().background(Color.blue).padding(10)
fontSizeView()
toggleLineNumberView()
}
}
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
ScaleToFitButton()
if isDiagramVisible {
ScaleToFitButton()
}
HStack( spacing: 0 ) {
ToggleEditorButton()
TogglePreviewButton()
Expand All @@ -85,15 +94,17 @@ struct PlantUMLContentView: View {
Button( action: { fontSize += 1 } ) {
Image( systemName: "textformat.size.larger")
}
.padding( EdgeInsets(top:0, leading: 5,bottom: 0, trailing: 0))
Divider().background(Color.blue)
Button( action: { fontSize -= 1} ) {
Image( systemName: "textformat.size.smaller")
}
.padding( EdgeInsets(top:0, leading: 5,bottom: 0, trailing: 0))
}
.overlay {
RoundedRectangle(cornerRadius: 16)
.stroke(.blue, lineWidth: 1)
}
// .overlay {
// RoundedRectangle(cornerRadius: 16)
// .stroke(.blue, lineWidth: 1)
// }
.padding()
}

Expand All @@ -114,16 +125,14 @@ struct PlantUMLContentView: View {

Button {
withAnimation {
isPreviewVisible.toggle()
if !isPreviewVisible && !isEditorVisible {
isEditorVisible.toggle()
}
// isPreviewVisible.toggle()
isEditorVisible.toggle()
}
}
label: {
Label( "Toggle Preview", systemImage: "rectangle.righthalf.inset.filled" )
.labelStyle(.iconOnly)
.foregroundColor( isPreviewVisible ? .blue : .gray)
.foregroundColor( isDiagramVisible ? .blue : .gray)

}
}
Expand All @@ -133,10 +142,6 @@ struct PlantUMLContentView: View {
Button {
withAnimation {
isEditorVisible.toggle()
if !isEditorVisible && !isPreviewVisible {
isPreviewVisible.toggle()
}

}
}
label: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/bsorrentino/PlantUML4iPad.git",
"state" : {
"branch" : "line_editor",
"revision" : "89f249c5f25f1125ea62b075dfa5507a2aa69a06"
"revision" : "223b6f403621940322b3bbc475d67f49e4cf56b1"
}
}
],
Expand Down

0 comments on commit 33f940e

Please sign in to comment.