Checkbox
Checkboxes make a great way to toggle options
A checkbox is actually a type of button, so the input type we’ll be using is NSSwitchButton.
Radio Button
Radio Buttons are a great way to make u user choose exactly one option
Although a radio button kinda looks like a checkbox, the code behind is a bit more advanced. To craft a radio button we have to create an instance of NSButton with a button type of NSRadioButton. However, radio buttons are used to select 1 option out of a selection so we have to group radio buttons in order for them to make sense.
You would expect that we would make a radio button for every option and position that radio button on the dialog, but the actual flow will be quite different. Instead, we are going to define a NSMatrix that will contain our cells (aka radio buttons). By placing these radio buttons in a NSMatrix, the radio buttons will be able to ‘work together’. This means that the user can never select more than 1 radio button, just like how radio buttons are supposed to work.
Displaying the dialog
We just initialized a dialog window inside the function createWindows(), so to display the dialog, we simply have to call this window. If you’d want to open the dialog when the user clicks a menu item, you could refer to this second function in your manifest.json file. If you’re getting confused you can find the whole piece of code at the bottom of this article.
I have created a function getUserInput() that calls the dialog and also handles the response. Don’t worry about this though, we’ll figure out how to do that in part 2 of the series.
Function to call the dialog
Coming up in part 2
Congratulations, you now have a nice looking custom dialog window for your Sketch plugin. We’re not done yet, though. The dialog window may look finished, but unless we find a way to get and process the data provided by our user, the dialog is completely pointless. Fortunately, we’ll show you exactly how to do this in part 2 of the series. See you guys then!
You can now make this!