Skip to content

StackOverflowMATLABchat/nbuttondlg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MATLAB FEX Minimum Version

nbuttondlg

NBUTTONDLG(Question, ButtonLabels) creates a modal dialog box that sizes to accomodate a generic number of buttons. The number of buttons is determined by the number of elements in ButtonLabels, provided as an array of string-likes understood by string. The name of the button that is pressed is returned as a string. If the dialog window is closed without a valid selection the return value is empty.

NBUTTONDLG should theoretically support an infinite number of buttons. The default parameters are optimized for 4 buttons.

NBUTTONDLG uses UIWAIT to suspend execution until the user responds.

Installation

No installation necessary. Clone the repository or download the files and execute directly in MATLAB.

Usage

Example:

user_choice = nbuttondlg('What is your favorite color?', ...
                        {'Red', 'Green', 'Blue', 'Yellow'} ...
             );
if ~isempty(user_choice)
    fprintf('Your favorite color is %s!\n', user_choice);
else
    fprintf('You have no favorite color :(\n')
end

nbuttondlg

Parameter/Value Pairs

The Question and ButtonLabel inputs can be followed by parameter/value pairs to specify additional properties of the dialog box. For example, NBUTTONDLG(Question, ButtonLabels, 'DialogTitle', 'This is a Title!') will create a dialog box with the specified Question and ButtonLabels and replace the default figure title with 'This is a Title!'

Property Name Data Type Description Default
BorderSize Integer Spacing, in pixels, between dialog box edges and button edges 20
ButtonWidth Integer Width, in pixels, of all buttons 80
ButtonHeight Integer Height, in pixels, of all buttons 40
ButtonSpacing Integer Spacing, in pixels, between all buttons 20
PromptTextHeight Integer Height, in pixels, of the question text box 20
DialogTitle String-like Dialog box figure title 'Please Select an Option'
DefaultButton Integer or String-like Default highlighted button.1 1
CancelButton Boolean Include a cancel button.2 false
  1. An attempt will be made to match a string-like input to a value in ButtonLabels. If no match is found, or the integer value is greater than the number of buttons, the default value will be used.
  2. If true, a 'Cancel' button label is added to ButtonLabels. If Cancel is selected, NBUTTONDLG behaves as if it were closed without selection.

About

A Generic Implementation of QUESTDLG

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages