Back

CreateSwitchSettings

Hello World
Content:
- Methods

Creates a switchable settings that can be toggled on and off.

sws = MUI.CreateSwitchSettings( text, width, height, value, color, backColor ) → Object

Example - Basic

cfg.Light
cfg.MUI

function OnStart()
{
    color = MUI.colors.teal
    app.InitializeUIKit(color.teal)

    lay = MUI.CreateLayout("Linear", "FillXY,VCenter")

        skb = MUI.CreateSwitchSettings("Enable Sound", 1)
        skb.SetOnTouch(OnTouch)
        lay.AddChild(skb)

    app.AddLayout(lay)
}

function OnTouch(text, value)
{
    app.ShowPopup(text+" : "+value)
}
Copy All       Run      

Example - More Settings

cfg.Dark
cfg.MUI

function OnStart()
{
    color = MUI.colors.teal
    app.InitializeUIKit(color.teal)

    lay = MUI.CreateLayout("Linear", "FillXY,VCenter")

        var settings = [
            "Enable sound",
            "Enable dark mode",
            "Disable full screen"
        ]

        for(var i=0; i<settings.length; i++)
        {
            skb = MUI.CreateSwitchSettings(settings[i], 1)
            skb.SetOnTouch(OnTouch)
            lay.AddChild(skb)
            lay.AddChild(MUI.CreateDivider())
        }

    app.AddLayout(lay)
}

function OnTouch(text, value)
{
    app.ShowPopup(text+" : "+value)
}
Copy All       Run      

Methods

The following methods are available on the SwitchSettings object:

Focus()
GetAbsHeight() → Number: integer
GetAbsWidth() → Number: integer
GetHeight( options ) → Number
GetLeft( options ) → Number
GetParent() → app object
GetPosition( options ) → Object: { left, top, right, bottom }
GetTop( options ) → Number
GetType() → String: “Seekbar”
GetValue() → Boolean
GetWidth( options ) → Number
Gone()
IsEnabled() → Boolean
IsOverlap( obj, depth ) → Boolean
IsVisible() → Boolean
Boolean
app object
Number
String
Number: fraction (0..1)
Number: integer
Number: milliseconds
String:
  hexadecimal: “#rrggbb”, “#aarrggbb”
  colourName: “red”, “green”, ...
String: “NewsPaper” or “Jelly” or “Flash” or “RubberBand” or “Swing” or “TaDa” or “Bounce” or “Fall” or “FallRotate” or
String: “px”
String: “screen”, “px”
String: “Show” or “Hide” or “Gone”
String: “Linear.None” or “Quadratic.In/Out” or “Cubic.In/Out” or “Quartic.In/Out” or “Quintic.In/Out” or “Sinusoidal.In/Out” or “Exponential.In/Out” or “Circular.In/Out” or “Elastic.In/Out” or “Back.In/Out” or “Bounce.In/Out”
Object: { x, y, w, w, sw, sh, rot }
function( type )
function( text, value )
function()
sws.Animate
Animates the control.

There are
    “in”-Animations which are used to show objects from hidden state
    “out”-animations which are used to hide objects in visible state and
    “static”-animations which keep the visible state.
sws.ClearFocus
Removes the focus of the control so that the user no longer has immediate access to it.
sws.Focus
Set the focus to the control so that the user can interact with it immediately.
sws.GetAbsHeight
Get the absolute height of the control in pixels.
sws.GetAbsWidth
Get the absolute width of the control in pixels.
sws.GetHeight
Get the height of the control as screen height relative float or in pixels with the px option.
sws.GetLeft
Get the distance from the control to the left parent border as width relative float or in pixels with the px option.
sws.GetParent
Returns the parent control object where the object was added to - commonly a layout.
sws.GetPosition
Returns data about the position and size of the control.
If the screen option is given the position on the screen will be returned. Otherwise relative to the parent control.
The px options turns the relative values into pixels.
sws.GetTop
Get the distance from the control to the upper parent border as height relative float or in pixels with the px option.
sws.GetType
Get type
sws.GetValue
Get the current value of the switch
sws.GetWidth
Get the width of the control as screen width relative float or in pixels with the px option.
sws.Gone
Hides the control without consuming any more layout space as if it were never there.
sws.IsEnabled
Returns whether the control is currently useable by the user.
sws.IsOverlap
Returns whether the control overlaps with another by a given distance.
sws.IsVisible
Returns whether the control is currently visible to the user, ignoring overlaying controls.
sws.SetEnabled
En/Disable the control physically and visually so that the user can/can not access the control. Events like OnTouch will still be fired.
sws.SetOnTouch
Calls a function when switch is click
sws.SetPosition
Defines the position and size for the control if the parent is an absolute layout.
sws.SetValue
Sets the value of the switch
sws.SetVisibility
Change the visibility of the control to one of the available modes:
Show: visible
Hide: invisible but still consuming space
Gone: invisible and not consuming space
sws.Tween
Performs an animation on the control.
The target object is for the position, size and rotation that the control has at the end of the animation.

The type specifies the behavior and the speed of the animation. Separated by a dot, you must also specify whether you want to apply this behavior to the beginning (In), end (Out), or to both (InOut) times of the animation.

With the amount of repeats you can control how many times you want to play the animation.

If you have jojo activated, the animation will alternate between forward and backward playback, so that if the repetition value is odd, the control will be at the start position again at the end of the animation.

Finally the callback function will be called after the animation has finished. Well, it's about time!