Skip to content

Instantly share code, notes, and snippets.

@drd
Created July 19, 2014 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drd/e6548a57a44620634165 to your computer and use it in GitHub Desktop.
Save drd/e6548a57a44620634165 to your computer and use it in GitHub Desktop.
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