A class for creating customizable views associated with one value for designing your own UI and/or for data visualization.
A ValueView stores a value and will draw a representation of that value in whatever way you choose. Similarly, for a view that interacts with multiple values, there is ValuesView.
The view:
ValueView and ValuesView aren't quite plug-and-play: they're is meant to be subclassed to author a new view/value representation. You'll also subclass ValueViewLayers which define drawing layers with user-assignable properties.
There's a guide to get you up and running: Subclassing ValueView, which explains how to sublcass ValueView, though the process is the same for ValuesView.
There are also two fully functional classes to use and reference:
Create a new ValueView.
parent |
A Window or View, in which to embed this view. If |
bounds |
A Rect describing the bounds of this view within its parent. If parent is |
spec |
A ControlSpec that will control the range and warping of your value. -input is the unmapped -value. If NOTE: : The step of the provided ControlSpec will determine the step resolution of the rotary when changing the value with a mouse or arrow key (default is 0 , i.e. highest step resolution possible). See RotaryView: Example: radio dial. |
initVal |
The initial -value when the view is first drawn. |
A ValueView.
Get/set the value held by the view, which is the mapped counterpart of the -input (via the -spec).
The new value and corresponding -input will be broadcast to dependents, via \value
and \iinput
messages, respectively, every time either is set, unless -broadcastNewOnly is true
, in which case the values are only broadcast if they differ from their previous state.
val |
A Number. The number will either be constrained or wrapped within the view's -spec, depending on the state of -wrap (default is |
Get/set the input held by the view, which is the unmapped counterpart of the -value (via the -spec), i.e. a value from (0..1). This is useful for updating other UI elements which are often set through normalized values, like Sliders.
The new input and corresponding -value will be broadcast to dependents, via \input
and \value
messages, respectively, every time either is set, unless -broadcastNewOnly is true
, in which case the values are only broadcast if they differ from their previous state.
normValue |
A Number in the range |
Get/set the action to be performed by the view when -valueAction, -inputAction, or -doAction are called.
actionFunc |
A Function which will be passed |
Get/set the ControlSpec used to both map the -input and constrain the -value. Note: the step of the provided controlSpec will determine the step resolution of the view when changing the value with a mouse or arrow key (default is 0
, i.e. highest step resolution possible).
controlSpec |
A ControlSpec. |
updateValue |
A Boolean specifying whether the -value(and -input) should be updated when the new controlSpec is set. Default is |
Set the value of the view and perform the -action. This also updates the -input by unmapping from the -spec.
val |
A Number in the range of the -spec. Out-of-range values will be clipped to the range of the -spec, unless -wrap is |
Set the input value of the view and perform the -action. This also updates the -value by mapping through the -spec.
normValue |
A Number in the range of (0..1). Out-of-range inputs will be clipped to the range, unless -wrap is |
Perform the -action. Usually called through -valueAction or -inputAction.
newValue |
A Boolean determining whether the actions is performed. Default is |
Get/set the Boolean which determines if the -action is performed only when a newly set value differs from its previous state. This applies when calling -valueAction, -inputAction, or -doAction. Default is true
(repeated actions are suppressed). See RotaryView: Example: radio dial.
Get/set the Boolean determining whether dependents are notified when the -input or -value is set but hasn't changed from its previous value. An advantage is that there's less throughput if your view's (unchanged) state is updated rapidly. The disadvantage is that if a new dependent is added, it won't necessarily know the state of the view until the value changes (in which case it would need to access this view's -value and/or -input when it's initialized).
Default is false
, i.e. the value and input are always broadcast when set even if the values haven't changed.
Dependents can listen for .changed messages with the keys \value
and \input
.
A Boolean determining whether setting out-of-range values are wrapped within the -spec or clipped to its range. Default is false
(values are clipped).
Get/set the Boolean indicating whether the value changes with mouse scrolling. Default is true
.
Get/set the step amount when scrolling. Default is 100.reciprocal
.
Get/set the x scroll direction. 1
is left to right scrolling (default), -1
is the reverse.
Get/set the y scroll direction. -1
is "natural" scrolling (default), 1
is the reverse.
Get/set the sensitivity of mouse interaction (and output resolution) by specifying the number of pixels over which the whole view's value range can be covered. Default is 200
, i.e. the entire range of possible values will be covered in 200 pixels of movement. This can also be set by -valuePerPixel.
Get/set the sensitivity of mouse interaction (and output resolution) by specifying the value change per pixel when interacting with the view through mouse movement. Default is spec.range / 200
, i.e. the entire range of possible values will be covered in 200 pixels of movement. This can also be set by -rangeInPixels.
Get/set the step amount of each arrow key press, as a percentage of the range of the spec. E.g. keyStep of 30.reciprocal
(the default) means it takes 30 key strokes to cover the full value range (warped according to the -spec).
Get/set the step direction of Left/Right arrow keys. 1
= right increments, left decrements (default). -1
= left increments, right decrements.
Get/set the step direction of Up/Down arrow keys. 1
= up increments, down decrements (default). -1
= down increments, up decrements.
Get/set the Function performed as the mouse moves over the view after being pressed. The function is passed [this, x, y, modifiers]
as arguments (see View: Mouse actions).
Get/set the Function performed when the mouse is pressed in the view. The function is passed [v, x, y, modifiers, buttonNumber, clickCount]
as arguments (see View: Mouse actions).
Get/set the Function performed when the mouse button is released. The function is passed [this, x, y, modifiers, buttonNumber]
as arguments (see View: Mouse actions).
Set the Function to be executed when the view closes.
func |
A Function. It will be passed this view as an argument. |
Refresh the view. If -limitRefresh is true
the view will only update at -maxRefreshRate.
Get/set the Boolean indicating whether the refresh rate should be limited to -maxRefreshRate.
Get/set the maximum refresh rate of the view when -limitRefresh is true
.
hz |
A Number that is the max refresh rate of the view. |
A Boolean determining whether the view is refreshed when drawing layer properties are set. Default is true
Return the UserView used internally.
Return the drawing layer objects used by this view. Useful for recalling what drawing layers have been designed for the view, though each layer is more likely more conveniently accessed by its instance variable name (which should be designed into the class—see source code for this class).
See RotaryView: Examples.