I'm trying to create a string view of state, so when called:
fmt.Printf("%s", panel.State)
It'll will print out something like:
Hi
⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️
⚪️⚫️⚪️⚫️⚪️⚪️⚫️⚪️⚪️⚪️
⚪️⚫️⚪️⚫️⚪️⚪️⚪️⚪️⚪️⚪️
⚪️⚫️⚫️⚫️⚪️⚪️⚫️⚪️⚪️⚪️
⚪️⚫️⚪️⚫️⚪️⚪️⚫️⚪️⚪️⚪️
⚪️⚫️⚪️⚫️⚪️⚪️⚫️⚪️⚪️⚪️
⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️⚪️
Is it possible to add a method on a nested field, then have access to it's parent struct, something like:
type Panel struct {
Width int
Height int
Message string
State [][]bool
}
func (state Panel.State) String() string {
line := state.parent.Message + "
"
for x := 0; x < state.parent.Width; x++ {
for y := 0; y < state.parent.Height; y++ {
cell = state[x][y]
if cell {
line += "⚫️"
} else {
line += "⚪️"
}
}
line += "
"
}
return line
}