Skip to content

Commit

Permalink
Change button theme when button is too short.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNexusAvenger committed Nov 22, 2024
1 parent 6307785 commit 7360ad9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ThemedFrame.luau
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ThemedFrame.Themes = DEFAULT_THEMES
ThemedFrame.__index = ThemedFrame
setmetatable(ThemedFrame, SimpleWrappedInstance)

export type SubTheme = "MainButton" | "GamepadIconBackground"
export type NexusButtonThemeEntry = {
Image: string,
SliceCenter: Rect,
Expand All @@ -71,7 +72,7 @@ export type NexusButtonTheme = {
}
export type ThemedFrame = {
Theme: string,
SubTheme: "MainButton" | "GamepadIconBackground",
SubTheme: SubTheme,
SliceScaleMultiplier: number,
} & typeof(setmetatable({}, ThemedFrame)) & SimpleWrappedInstance.SimpleWrappedInstance<ImageLabel>
export type NexusInstanceThemedFrame = NexusInstance.NexusInstance<ThemedFrame>
Expand Down
5 changes: 4 additions & 1 deletion src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

local HOVER_COLOR_MULTIPLIER = 0.7
local PRESS_COLOR_MULTIPLIER = 1 / 0.7
local CONTROLLER_SECTION_THEME_MINIMUM_ASPECT_RATIO = 1.2
local CONTROLLER_SECTION_COLOR = Color3.fromRGB(50, 50, 50)

local GuiService = game:GetService("GuiService")
Expand Down Expand Up @@ -254,7 +255,8 @@ function NexusButton.UpdateBorder(self: NexusInstanceNexusButton, Tween: boolean
--Get the border size.
if not self.BorderSize then return end
if not self.Theme then return end
local ButtonSizeY = self.BackgroundFrame.AbsoluteSize.Y
local ButtonSize = self.BackgroundFrame.AbsoluteSize
local ButtonSizeY = ButtonSize.Y
local BorderSize = (ButtonSizeY * self.BorderSize.Scale) + self.BorderSize.Offset
local BackgroundColor3 = self.BackgroundColor3
local BorderColor3 = self.BorderColor3
Expand Down Expand Up @@ -286,6 +288,7 @@ function NexusButton.UpdateBorder(self: NexusInstanceNexusButton, Tween: boolean
self.BorderFrame.ImageColor3 = BorderColor3
self.BorderFrame.Size = UDim2.new(1, 0, 1, BorderSize)
end
self.GamepadIcon.SubTheme = (((ButtonSize.X / ButtonSize.Y) < CONTROLLER_SECTION_THEME_MINIMUM_ASPECT_RATIO) and "MainButton" or "GamepadIconBackground") :: ThemedFrame.SubTheme
end

--[[
Expand Down

0 comments on commit 7360ad9

Please sign in to comment.