
// // Copyright (c) 2008, Brian Frank and Andy Frank // Licensed under the Academic Free License version 3.0 // // History: // 10 Jun 08 Brian Frank Creation // ** ** Button displays a push, toggle, check, or radio button with ** text and/or an image. Buttons can also be used as the ** children of a `ToolBar`. ** class Button : Widget { ** ** Callback function when button is pressed or selection is changed. ** |Event event| onAction ** ** Button mode defines the style: check, push, radio, or toggle. ** If the button is a child of a ToolBar then you can also use ** sep; plus radio and toggle mean the same thing. The default ** is push. This field cannot be changed once the button is ** constructed. ** const ButtonMode mode := ButtonMode.push ** ** The button's selection state (if check, radio, or toggle) ** Bool selected { get { return send(getSelectedId, null) } set { send(setSelectedId, val) } } internal static const Str getSelectedId := "getSelected" internal static const Str setSelectedId := "setSelected" ** ** Text of the button. Defaults to "". ** Str text := "" { set { @text = val; sync(textId) } } internal static const Str textId := "text" ** ** Image to display on button. Defaults to null. ** Image image := null { set { @image = val; sync(imageId) } } internal static const Str imageId := "image" ** ** Font for text. Defaults to null (system default). ** Font font := null { set { @font = val; sync(fontId) } } internal static const Str fontId := "font" ** ** Command associated with this button. Setting the ** command automatically maps the text, icon, enable state, ** and eventing to the command. ** Command command { set { @command?.unregister(this) @command = val if (val != null) { enabled = val.enabled text = val.name image = val.icon onAction = |Event e| { val.invoke(e) } val.register(this) } } } }