How can I reformat the code of GridStack in the view body so I may duplicate it per row, such as 1 row of 2 columns, 2 rows of 8 columns, 4 rows of 18 columns, 2 rows of 15 columns?, I am cutting out the holes with this Hypothesis to shape an Interactive Periodic Table, refer to image attached.
@jnpdx has provided an example for display function per cell coordinate, along with this i will need an ontapgesture to operate the overlay of data per cell so I may send information to other menu fields.
@jnpdx so now right before the roundedrectangle in this edit and turn on the display function commented out, i need to some how over lay the custom data per cell instead of hydrogen on every cell plus create an ontapgesture to send globally to other menu fields in the application?
struct GridStack<Content: View>: View {
let rows: Int
let columns: Int
let content: (Int, Int) -> Content
//func shouldDisplayAtCoord(row: Int, column: Int) { if row == 0 && column > 1 { return true } }
var body: some View {
VStack {
ForEach(0 ..< rows, id: \.self) { row in
HStack {
ForEach(0 ..< columns, id: \.self) { column in
ZStack{
RoundedRectangle(cornerRadius: 5)
.fill(Color.brown)
.frame(width: 40, height: 50)
Image("RadicalDeepscale30").opacity(0.4)
content(row, column)
}
}
}
}
}
}
init(rows: Int, columns: Int, @ViewBuilder content: @escaping (Int, Int) -> Content) {
self.rows = rows
self.columns = columns
self.content = content
}
}
// An example view putting GridStack into practice.
struct DETEView: View {
var body: some View {
VStack(alignment: .center) {
Text("DART Edge Table of Elements")
.font(.largeTitle)
.bold()
//.colorInvert()
.padding(.top, 20)
.shadow(radius: 3)
}
VStack(alignment: .center) {
HStack(alignment: .center){
VStack(alignment: .center) {
GridStack(rows: 9, columns: 18) { row, col in
VStack(alignment: .leading){
HStack(alignment: .top) {
VStack(alignment: .leading) {
Text("1")
.font(.system(size: 9))
// .bold()
//.shadow(radius: 1)
}
}
HStack(alignment: .center) {
VStack(alignment: .center){
Text("H")
.font(.system(size: 12))
.bold()
//.shadow(radius: 1)
Text("Hydrogen")
.font(.system(size: 7))
//.bold()
// .shadow(radius: 1)
//.padding(.top, 1)
}
}
}
}
}
}
}.frame(width: 950, height: 670, alignment: .top).padding(.top, 20)
}
}