LogoObsidian

Checkboxes

Checkboxes are used to toggle features in Obsidian

Playground

Enable Speed Hack

Usage

You can create a Checkbox by calling the AddCheckbox method on a Groupbox.

You can override the default :AddToggle method to make a checkbox element instead by doing:

Library.ForceCheckbox = true

Arguments

local MyToggle = Groupbox:AddCheckbox("MyToggle", {
    Text = "Enable Speed Hack",
    Default = true,
})
Arg IdxArgument DescriptionTypeDefault
1Index/ID of the togglestringnil
2Toggle configuration tabletablenil

Configuration Table

Prop

Type

Methods

You can use the following methods to interact with the toggle:

SetValue

Sets the toggle value.

Checkbox:SetValue(boolean)
Arg IdxArgument DescriptionTypeDefault
1The new value of the togglebooleannil

SetText

Updates the toggle's text.

Checkbox:SetText(text)
Arg IdxArgument DescriptionTypeDefault
1The new text of the togglestringnil

SetDisabled

Enables or disables the toggle.

Checkbox:SetDisabled(boolean)
Arg IdxArgument DescriptionTypeDefault
1Whether to disable the togglebooleannil

SetVisible

Shows or hides the toggle.

Checkbox:SetVisible(boolean)
Arg IdxArgument DescriptionTypeDefault
1Whether to show the togglebooleannil

OnChanged

Adds another callback function to the toggle. This is the recommended way to listen for changes in the toggle.

Checkbox:OnChanged(function)
Arg IdxArgument DescriptionTypeDefault
1The callback functionfunctionnil

Example

local Options = Library.Options
local Toggles = Library.Toggles
 
-- Setup UI elements first
local MyToggle = Groupbox:AddCheckbox("MyToggle", {
    Text = "Enable Speed Hack",
    Default = true,
})
 
-- Then after creating all UI elements, add callbacks
-- MyToggle:OnChanged(...) also works
Toggles.MyToggle:OnChanged(function(state)
    print("Toggle state changed to " .. tostring(state))
end)

On this page