Skip to content

Instantly share code, notes, and snippets.

@PaulWoodIII
Created August 22, 2019 15:49
Show Gist options
  • Select an option

  • Save PaulWoodIII/cf1c43f3a018622097fd0a4d1cbe04a2 to your computer and use it in GitHub Desktop.

Select an option

Save PaulWoodIII/cf1c43f3a018622097fd0a4d1cbe04a2 to your computer and use it in GitHub Desktop.
bare minimum to simply display a representation of a binary search tree in SwiftUI with some graphical context
//
// BinarySearchView.swift
// WatchSort WatchKit Extension
//
// Created by Paul Wood on 8/22/19.
// Copyright © 2019 Paul Wood. All rights reserved.
//
import SwiftUI
import Combine
class BinarySearchAlgorithmDisplayable: ObservableObject {
public var objectWillChange = PassthroughSubject<Void, Never>()
}
struct BinarySearchNode {
var index: Int
var content: Int
var wasSearched: Bool
var isSearched: Bool
}
struct BinarySearchView: View {
fileprivate func IndexView(_ string: String) -> some View {
return Text(string)
.background(
RoundedRectangle(cornerRadius: 1.0)
.frame(minWidth: 20, idealWidth: 20,minHeight: 30, idealHeight: 30, alignment: .center)
.border(Color.white, width: 2)
.foregroundColor(Color.gray)
)
}
var body: some View {
VStack{
Spacer()
HStack{
IndexView("8")
}
Spacer()
HStack{
Spacer()
IndexView("04")
Spacer()
IndexView("12")
Spacer()
}
Spacer()
HStack{
Spacer()
IndexView("02")
Spacer()
IndexView("06")
Spacer()
IndexView("10")
Spacer()
IndexView("14")
Spacer()
}
Spacer()
HStack{
IndexView("01")
IndexView("03")
IndexView("05")
IndexView("07")
IndexView("09")
IndexView("11")
IndexView("13")
IndexView("15")
}
Spacer()
}.font(.system(size: 12, weight: .thin, design: .rounded))
.animation(.default)
}
}
struct BinarySearchView_Previews: PreviewProvider {
static var previews: some View {
BinarySearchView()
}
}
@PaulWoodIII
Copy link
Author

PaulWoodIII commented Aug 22, 2019

I can't really add many more elements due to the constraints on function builders right now but I think this is enough context to get the point across. things always get interesting after the 3rd object or 3rd layer of an algorithm you know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment