Skip to main content

ButtonHighlightModel

Contains model information for the current button.

Usage with Blend!

function Button.new()
	local self = setmetatable(BaseObject.new(), Button)

	-- Store the button model in the actual button so we can ensure it cleans up
	-- this assumes only one render. We can also construct it in the Button.Render

	self._buttonModel = ButtonHighlightModel.new()
	self._maid:GiveTask(self._buttonModel)

	return self
end

function Button:Render()
	...
	return Blend.New "ImageButton" {
		...
		[Blend.Instance] = function(button)
			self._buttonModel:SetButton(button)
		end;
		BackgroundTransparency = Blend.Computed(self._buttonModel:ObservePercentPressed(), function(pressed)
			return 1 - pressed
		end);
	}
end

Properties

InteractionEnabledChanged

This item is read only and cannot be modified. Read Only
ButtonHighlightModel.InteractionEnabledChanged: Signal<boolean>

IsSelectedChanged

This item is read only and cannot be modified. Read Only
ButtonHighlightModel.IsSelectedChanged: Signal<boolean>

IsMouseOrTouchOverChanged

This item is read only and cannot be modified. Read Only
ButtonHighlightModel.IsMouseOrTouchOverChanged: Signal<boolean>

IsHighlightedChanged

This item is read only and cannot be modified. Read Only
ButtonHighlightModel.IsHighlightedChanged: Signal<boolean>

IsPressedChanged

This item is read only and cannot be modified. Read Only
ButtonHighlightModel.IsPressedChanged: Signal<boolean>

Functions

new

ButtonHighlightModel.new(
button?GuiBase,
onUpdatefunction?
) → ButtonHighlightModel

A model that dictates the current state of a button.

SetButton

ButtonHighlightModel:SetButton(buttonInstance) → ()

Sets the button for the highlight model.

IsPressed

ButtonHighlightModel:IsPressed() → boolean

Gets if the button is pressed

ObserveIsPressed

ButtonHighlightModel:ObserveIsPressed() → Observable<boolean>

Observes if the button is pressed

ObservePercentPressed

ButtonHighlightModel:ObservePercentPressed(accelerationnumber | nil) → Observable<number>

Observes how pressed down the button is

ObservePercentPressedTarget

ButtonHighlightModel:ObservePercentPressedTarget() → Observable<number>

Observes target for how pressed the button is

IsHighlighted

ButtonHighlightModel:IsHighlighted() → boolean

Returns true if highlighted

ObserveIsHighlighted

ButtonHighlightModel:ObserveIsHighlighted() → Observable<boolean>

Observes if we're highlighted

ObservePercentHighlightedTarget

ButtonHighlightModel:ObservePercentHighlightedTarget() → Observable<number>

Observes target for how highlighted the button is

ObservePercentHighlighted

ButtonHighlightModel:ObservePercentHighlighted(accelerationnumber | nil) → Observable<number>

Observes how highlighted the button is

IsSelected

ButtonHighlightModel:IsSelected() → boolean

Returns true if selected

ObserveIsSelected

ButtonHighlightModel:ObserveIsSelected() → Observable<boolean>

Returns an observable for if we're selected

IsMouseOrTouchOver

ButtonHighlightModel:IsMouseOrTouchOver() → Observable<boolean>

Gets if mouse or touch is over specifically. This can be used for hover effects.

ObserveIsMouseOrTouchOver

ButtonHighlightModel:ObserveIsMouseOrTouchOver() → Observable<boolean>

Observes if mouse or touch is over specifically. This can be used for hover effects.

SetIsChoosen

ButtonHighlightModel:SetIsChoosen(
isChoosenboolean,
doNotAnimateboolean
) → ()

Sets whether the model is choosen

IsChoosen

ButtonHighlightModel:IsChoosen() → boolean

Returns true if choosen

ObserveIsChoosen

ButtonHighlightModel:ObserveIsChoosen() → boolean

Observes if the instance is "choosen"

ObservePercentChoosenTarget

ButtonHighlightModel:ObservePercentChoosenTarget() → Observable<number>

Observes target for if the button is selected or not

ObservePercentChoosen

ButtonHighlightModel:ObservePercentChoosen(accelerationnumber | nil) → Observable<number>

Observes how choosen the button is

SetInteractionEnabled

ButtonHighlightModel:SetInteractionEnabled(interactionEnabledboolean) → ()

Sets whether interaction is enabled

IsInteractionEnabled

ButtonHighlightModel:IsInteractionEnabled() → boolean

Gets if interaction enabled

ObserveIsInteractionEnabled

ButtonHighlightModel:ObserveIsInteractionEnabled() → Observable<boolean>

Observes if interaction enabled

SetKeyDown

ButtonHighlightModel:SetKeyDown(
isKeyDownboolean,
doNotAnimateboolean--

Optional

) → ()

Sets whether a key is down

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "A model that dictates the current state of a button.",
            "params": [
                {
                    "name": "button?",
                    "desc": "",
                    "lua_type": "GuiBase"
                },
                {
                    "name": "onUpdate",
                    "desc": "",
                    "lua_type": "function?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ButtonHighlightModel"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 58,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "SetButton",
            "desc": "Sets the button for the highlight model.",
            "params": [
                {
                    "name": "button",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 155,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsPressed",
            "desc": "Gets if the button is pressed",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 271,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObserveIsPressed",
            "desc": "Observes if the button is pressed",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 279,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObservePercentPressed",
            "desc": "Observes how pressed down the button is",
            "params": [
                {
                    "name": "acceleration",
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 289,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObservePercentPressedTarget",
            "desc": "Observes target for how pressed the button is",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 302,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsHighlighted",
            "desc": "Returns true if highlighted",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 316,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObserveIsHighlighted",
            "desc": "Observes if we're highlighted",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 325,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObservePercentHighlightedTarget",
            "desc": "Observes target for how highlighted the button is",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 333,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObservePercentHighlighted",
            "desc": "Observes how highlighted the button is",
            "params": [
                {
                    "name": "acceleration",
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 348,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsSelected",
            "desc": "Returns true if selected",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 357,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObserveIsSelected",
            "desc": "Returns an observable for if we're selected",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 366,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsMouseOrTouchOver",
            "desc": "Gets if mouse or touch is over specifically. This can be used\nfor hover effects.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 376,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObserveIsMouseOrTouchOver",
            "desc": "Observes if mouse or touch is over specifically. This can be used\nfor hover effects.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 386,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "SetIsChoosen",
            "desc": "Sets whether the model is choosen",
            "params": [
                {
                    "name": "isChoosen",
                    "desc": "",
                    "lua_type": "boolean"
                },
                {
                    "name": "doNotAnimate",
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 395,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsChoosen",
            "desc": "Returns true if choosen",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 406,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObserveIsChoosen",
            "desc": "Observes if the instance is \"choosen\"",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 415,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObservePercentChoosenTarget",
            "desc": "Observes target for if the button is selected or not",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 423,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObservePercentChoosen",
            "desc": "Observes how choosen the button is",
            "params": [
                {
                    "name": "acceleration",
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<number>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 438,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "SetInteractionEnabled",
            "desc": "Sets whether interaction is enabled",
            "params": [
                {
                    "name": "interactionEnabled",
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 451,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsInteractionEnabled",
            "desc": "Gets if interaction enabled",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 459,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "ObserveIsInteractionEnabled",
            "desc": "Observes if interaction enabled",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<boolean>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 467,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "SetKeyDown",
            "desc": "Sets whether a key is down",
            "params": [
                {
                    "name": "isKeyDown",
                    "desc": "",
                    "lua_type": "boolean"
                },
                {
                    "name": "doNotAnimate",
                    "desc": "Optional",
                    "lua_type": "boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 476,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "InteractionEnabledChanged",
            "desc": "",
            "lua_type": "Signal<boolean>",
            "readonly": true,
            "source": {
                "line": 83,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsSelectedChanged",
            "desc": "",
            "lua_type": "Signal<boolean>",
            "readonly": true,
            "source": {
                "line": 90,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsMouseOrTouchOverChanged",
            "desc": "",
            "lua_type": "Signal<boolean>",
            "readonly": true,
            "source": {
                "line": 97,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsHighlightedChanged",
            "desc": "",
            "lua_type": "Signal<boolean>",
            "readonly": true,
            "source": {
                "line": 104,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        },
        {
            "name": "IsPressedChanged",
            "desc": "",
            "lua_type": "Signal<boolean>",
            "readonly": true,
            "source": {
                "line": 113,
                "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
            }
        }
    ],
    "types": [],
    "name": "ButtonHighlightModel",
    "desc": "Contains model information for the current button.\n\nUsage with Blend!\n\n```lua\nfunction Button.new()\n\tlocal self = setmetatable(BaseObject.new(), Button)\n\n\t-- Store the button model in the actual button so we can ensure it cleans up\n\t-- this assumes only one render. We can also construct it in the Button.Render\n\n\tself._buttonModel = ButtonHighlightModel.new()\n\tself._maid:GiveTask(self._buttonModel)\n\n\treturn self\nend\n\nfunction Button:Render()\n\t...\n\treturn Blend.New \"ImageButton\" {\n\t\t...\n\t\t[Blend.Instance] = function(button)\n\t\t\tself._buttonModel:SetButton(button)\n\t\tend;\n\t\tBackgroundTransparency = Blend.Computed(self._buttonModel:ObservePercentPressed(), function(pressed)\n\t\t\treturn 1 - pressed\n\t\tend);\n\t}\nend\n```",
    "source": {
        "line": 35,
        "path": "src/buttonhighlightmodel/src/Client/ButtonHighlightModel.lua"
    }
}