Creates a button with a lot of tweaks.
Name | Type | Attributes | Description |
---|---|---|---|
options |
object |
<optional> |
Button options. |
options.defaultView |
string | Texture | Container | Sprite | Graphics |
Container-based view that is shown when non of the button events are active.
|
|
options.hoverView |
string | Texture | Container | Sprite | Graphics |
Container-based view that is shown when the mouse hovers over the button.
|
|
options.pressedView |
string | Texture | Container | Sprite | Graphics |
Container-based view, shown when the mouse press on the component.
|
|
options.disabledView |
string | Texture | Container | Sprite | Graphics |
Container-based view shown when the button is disabled.
|
|
options.icon |
string | Texture | Container | Sprite | Graphics |
Container-based view for the button icon. |
|
options.text |
Text |
Text-based view for the button text. |
|
options.padding |
number |
Padding of the button text and icon views. If button text or icon does not fit active view + padding it will scale down to fit. |
|
options.offset |
Point |
Offset of the button state views. |
|
options.textOffset |
Point |
Offset of the text view. |
|
options.iconOffset |
Point |
Offset of the icon view. |
|
options.scale |
number |
Scale of the button. Scale will be applied to a main container, when all animations scales will be applied to the inner view. |
|
options.defaultTextScale |
number |
Base text scaling to take into account when fitting inside the button. |
|
options.defaultIconScale |
number |
Base icon scaling to take into account when fitting inside the button. |
|
options.defaultTextAnchor |
number |
Base text anchor to take into account when fitting and placing inside the button. |
|
options.defaultIconAnchor |
number |
Base icon anchor to take into account when fitting and placing inside the button. |
|
options.anchor |
number |
Anchor point of the button. |
|
options.anchorX |
number |
Horizontal anchor point of the button. |
|
options.anchorY |
number |
Vertical anchor point of the button. |
|
options.nineSliceSprite |
Array |
NineSliceSprite values for views ([number, number, number, number]).
|
|
options.animations |
Animations that will be played when the button state changes. |
Example
const button = new FancyButton({
defaultView: `button.png`,
hoverView: `button_hover.png`,
pressedView: `button_pressed.png`,
text: 'Click me!',
animations: {
hover: {
props: {
scale: {
x: 1.1,
y: 1.1,
}
},
duration: 100,
},
pressed: {
props: {
scale: {
x: 0.9,
y: 0.9,
}
},
duration: 100,
}
}
});
button.onPress.connect(() => console.log('Button pressed!'));
Extends
Members
Offset of the button state views. If state views have different sizes, this option can help adjust them.
Padding of the button text view. If button text does not fit active view + padding it will scale down to fit.
Offset of the text view. Can be set to any state of the button.
Anchor point of the button.
Sets the fitting mode for the button's content.
Returns the fitting mode for the button's content, defaulting to 'default'.
Sets the base anchor for the icon view to take into account when fitting and placing inside the button.
Returns the icon view base anchor.
Sets the base scale for the icon view to take into account when fitting inside the button.
Returns the icon view base scale.
Sets the base anchor for the text view to take into account when fitting and placing inside the button.
Returns the text view base anchor.
Sets the base scale for the text view to take into account when fitting inside the button.
Returns the text view base scale.
Sets the default view of the button.
Returns the default view of the button.
Sets the disabled view of the button.
Returns the disabled view of the button.
Setter, that prevents all button events from firing.
Sets height of a FancyButtons state views. If nineSliceSprite is set, then height will be set to nineSliceSprites of a views. If nineSliceSprite is not set, then height will control components height as Container.
Gets height of a FancyButton.
Sets the hover view of the button.
Returns the hover view of the button.
Offset of the icon view. Can be set to any state of the button.
Sets the iconView of the button.
Returns the icon view of the button.
Sets the button offset.
Returns the button offset.
Sets the button padding.
Returns the button padding.
Sets the pressed view of the button.
Returns the pressed view of the button.
State of the button. Possible valuers are: 'default', 'hover', 'pressed', 'disabled'
Updates the text of the button and updates its scaling basing on the new size.
Returns the text string of the button text element.
Sets the button text offset.
Returns the button text offset.
Sets the textView of the button.
Returns the text view of the button.
Sets width of a FancyButtons state views. If nineSliceSprite is set, then width will be set to nineSliceSprites of a views. If nineSliceSprite is not set, then width will control components width as Container.
Gets width of a FancyButton.
Base icon anchor to take into account when fitting and placing inside the button
Base icon scaling to take into account when fitting inside the button
Base text anchor to take into account when fitting and placing inside the button
Base text scaling to take into account when fitting inside the button
FancyButton options.
Methods
Removes button view by type
Name | Type | Description |
---|---|---|
viewType |
'defaultView' | 'hoverView' | 'pressedView' | 'disabledView' |
type of the view to remove |
Updates button state and shows the according views.
Updates positions and offsets of the views.
Plays animations if they are set.
Name | Type | Default | Description |
---|---|---|---|
newState |
State | ||
force |
boolean | false |
Adjusts icon view position and scale.
Name | Type | Description |
---|---|---|
state |
State |
Adjusts text view position and scale.
Name | Type | Description |
---|---|---|
state |
State |
Manage button text view.
Name | Type | Description |
---|---|---|
text |
string | Text |
can be a string, Text, BitmapText ot HTMLText (Container-based element). |
Returns active view for the state.
Name | Type | Description |
---|---|---|
state |
State |
Returns:
Type | Description |
---|---|
Container | undefined |
Starts animation for the current button state if configured.
Name | Type | Description |
---|---|---|
state |
State |
Manages views offsets if it's set.
Name | Type | Description |
---|---|---|
view |
Container | |
state |
State | |
offset |
Offset |
Reset views positions according to the button anchor setting. We have to set the anchor position for each view individually, as each of them can be a different type of view (container without anchor, sprite with anchor, etc) we have to reset all anchors to 0,0 and then set the positions manually.
Helper method to update or cleanup button views.
Name | Type | Description |
---|---|---|
viewType |
'defaultView' | 'hoverView' | 'pressedView' | 'disabledView' |
type of the view to update |
view |
string | Texture | Container | unknown |
new view |