Now for checkboxes. I covered these in the "Choosing files" thread, but this time some fitting is needed, plus the ability to set the initial state. So:
on makeCheckbox:checkTitle leftInset:theLeft bottom:theBottom maxWidth:theWidth initialState:initialState set theCheckbox to current application's NSButton's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, 18)) tell theCheckbox its setButtonType:(current application's NSSwitchButton) its setTitle:checkTitle its setState:initialState set theSize to its fittingSize() its setFrameSize:theSize end tell -- return theCheckbox, the top of theCheckbox, and its width return {theCheckbox, theBottom + 18, width of theSize} end makeCheckbox:leftInset:bottom:maxWidth:initialState:
Sometimes checkboxes also require labels, so it makes sense to have a handler that builds both together. This is similar to the way I handled a text field with a label to its left: there is a checkboxLeft parameter, and if this is less than the leftInset, the label is made to size, and the checkbox positioned after it, otherwise the checkbox is positioned according to checkboxLeft, and the label positioned next to it. To make the first case work, the actual width of the label needs to be known, which is why the handler above returns it. So:
on makeLabeledCheckbox:checkTitle leftInset:theLeft bottom:theBottom maxWidth:theWidth label:theLabel checkboxLeft:checkboxLeft checkState:checkState if checkboxLeft ≤ theLeft then set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:theWidth alignment:"left" multiLine:false set checkboxLeft to (newWidth + 6) set {theCheckbox, theTop, theWidth} to my makeCheckbox:checkTitle leftInset:checkboxLeft bottom:theBottom maxWidth:(theWidth - newWidth - 6) checkState:checkState else set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:(checkboxLeft - theLeft - 6) alignment:"right" multiLine:false set {theCheckbox, theTop, theWidth} to my makeCheckbox:checkTitle leftInset:checkboxLeft bottom:theBottom maxWidth:(theWidth - checkboxLeft) checkState:checkState end if return {theCheckbox, theLabel, theTop, checkboxLeft} end makeLabeledCheckbox:leftInset:bottom:maxWidth:label:checkboxLeft:checkState:
|