This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ControlGrid { | |
var buttons : Dictionary<String, NSButton> | |
let mapping = [ | |
"e": (1, 0.5), | |
"se": (1, 1), | |
"s": (0.5, 1), | |
"sw": (0, 1), | |
"w": (0, 0.5), | |
"nw": (0, 0), | |
"n": (0.5, 0), | |
"ne": (1, 0), | |
] | |
init(size: NSSize) { | |
buttons = Dictionary<String, NSButton>() | |
// all views appear to have a reference to the same frame | |
for (name, loc) in mapping { | |
for y in [0, 0.5, 1] { | |
for x in [0, 0.5, 1] { | |
if x == y && x == 0.5 { | |
break; | |
} | |
var rect = NSRect(x: size.width * x, y: size.height * y, width: 20, height: 20) | |
buttons[name] = NSButton(frame:rect) | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment