Gumbo FxSpinner - Functional and Design Specification
Glossary
scale - the scale of a FxSpinner is the set of allowed numbers that the value property can take on. The allowed numbers are the multiples of the valueInterval property between the maximum and minimum, and also includes the maximum and minimum. For example, if
- minimum = -1
- maximum = 10
- valueInterval = 3
Then, the scale would be {-1,3,6,9,10}.
value wrapping - When the current value is at the maximum, stepping to the next value will set the current value to the minimum and vice versa.
Summary and Background
This specification describes the proposed new FxSpinner class which extends FxRange in Gumbo.
FxSpinner extends from FxRange and adds two buttons that allows someone to step the current value through a set of allowed values. FxNumericStepper will extend from FxSpinner. The primary motivations for adding this new class were:
- To allow more generic display components and more complex behavior than the Halo NumericStepper allowed.
- To have FxNumericStepper adhere to accessibility standards.
By having the more abstract FxSpinner class, developers can be more flexible with the types of displays allowed. One can imagine having a FxSpinner controlling tabs or a menu by assigning different values to tabs or menu items. Also, NumericStepper was the only basic component that did not support accessibility. FxSpinner remedies this problem by allowing FxNumericStepper to be a spinner with the additional element of a FxTextInput.
Usage Scenarios
- Base class for some Gumbo controls such as FxNumericStepper.
- Base class or separate part for custom controls that utilize selection from an ordered set. Use cases include:
- Modified FxNumericStepper with different input/display
- Tabbing control (assign tabs to values)
- Mobile menu (assign menu items to values)
Detailed Description
Behavior
FxSpinner controls a value through its two buttons, incrementButton and decrementButton. These buttons use stepSize to increment or decrement the values.
SkinParts
FxSpinner is composed of two buttons:
- incrementButton increases the value by stepSize, if possible, when pressed.
- decrementButton decreases the value by stepSize, if possible, when pressed.
Inherited Properties
value, minimum, maximum, valueInterval - See FxRange.
stepSize - When the step() method is called, whether programmatically or through the buttons, the value must be a multiple of stepSize. However, stepSize must be a multiple of valueInterval unless valueInterval is 0 as in FxRange.
- Note: Correct behavior is only implemented for stepSize >= 0.
New Properties
valueWrap - enables or disables value wrapping. The default is false.
Methods
These are the methods to override to customize FxSpinner's behavior:
- roundValue() - To change the rounding calculation.
- step() - To change the stepping behavior.
Events
Whenever the value changes, a valueCommit event is dispatched (inherited from FxRange). Whenever the value changes because of user interaction, a change event is dispatched.
Keyboard Behavior
- Up increments the value
- Down decrements the value.
API Description
package mx.components
{
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
import mx.events.FlexEvent;
import mx.managers.IFocusManagerComponent;
/**
* Dispatched when the value of the FxSpinner control changes
* as a result of user interaction.
*
* @eventType mx.events.Event
*/
[Event(name="change", type="mx.events.Event")]
/**
* A FxSpinner is used to select a value from an
* ordered set. It uses two buttons that increase or
* decrease the current value based on the current
* <code>stepSize</code>.
*
* <p>This control extends the FxRange class and
* is the base class for controls that select a value
* from an ordered set such as the FxNumericStepper control.</p>
*
* <p>A FxSpinner consists of two required buttons,
* one to increase the value and one to decrease the
* value. </p>
*
* <p>FxSpinner has the addition property of
* <code>valueWrap</code> which enables value wrapping.</p>
*
* @see mx.components.baseClasses.FxRange
* @see mx.components.FxNumericStepper
*/
public class FxSpinner extends FxRange implements IFocusManagerComponent
{
include "../core/Version.as";
/**
* Constructor.
*/
public function FxSpinner():void
[SkinPart]
/**
* <code>incrementButton</code> is a SkinPart that defines
* a button that, when pressed, will cause <code>value</code>
* to increment by <code>stepSize</code>.
*/
public var incrementButton:Button;
[SkinPart]
/**
* <code>decrementButton</code> is a SkinPart that defines
* a button that, when pressed, will cause <code>value</code>
* to decrement by <code>stepSize</code>.
*/
public var decrementButton:Button;
/**
* Enable/disable this component. This also enables/disables any of the
* skin parts for this component.
*/
override public function set enabled(value:Boolean):void;
/**
* <code>valueWrap</code> determines the behavior of stepping
* beyond the maximum or minimum value. If
* <code>valueWrap</code> is true when stepping beyond an
* extreme, it will set <code>value</code> to the opposite
* extreme.
*
* @default false
*/
public function get valueWrap():Boolean;
public function set valueWrap(value:Boolean):void;
/**
* @private
*/
override protected function partAdded(partName:String, instance:*):void:
/**
* @private
*/
override protected function partRemoved(partName:String, instance:*):void;
/**
* Make the skins reflect the enabled state of the Spinner.
*/
protected function enableSkinParts(value:Boolean):void:
/**
* @private
* Adds complex behavior to step in order to adhere to
* multiples of stepSize (including maximum and minimum).
*/
override public function step(increase:Boolean = true):void;
/**
* Handle a click on the incrementButton. This should
* increment <code>value</code> by <code>stepSize</code>.
*/
protected function incrementButton_buttonDownHandler(event:Event):void;
/**
* Handle a click on the decrementButton. This should
* decrement <code>value</code> by <code>stepSize</code>.
*/
protected function decrementButton_buttonDownHandler(event:Event):void;
/**
* Handles keyboard input. Up arrow increments. Down arrow
* decrements. Home and End keys set the value to maximum
* and minimum respectively.
*/
override protected function keyDownHandler(event:KeyboardEvent):void;
}
}
B Features
none so far
Additional Implementation Details
none
Prototype Work
Prototype of FxSpinner has shown that it can be a very lightweight base class for FxNumericStepper and other custom controls.
Compiler Work
none
Web Tier Compiler Impact
none
Flex Feature Dependencies
FxSpinner depends on FxRange as its base class.
Backwards Compatibility
Syntax changes
None - New Class
Accessibility
Provides accessibility for FxNumericStepper and similar controls.
Issues and Recommendations
- Should there be more descriptive events? For distinguishing between keyboard and mouse?
|
 |
In the example provided at the top of the page, shouldn't the resulting scale be {-1, 2, 5, 8, 10}? In the example, the first step is 4, not 3.