mirror of
https://codeberg.org/1414codeforge/yui.git
synced 2025-06-05 22:19:11 +02:00
[*] Rework theme customization.
This commit allows more flexible and consistent theme overriding rules for each Widget. There are 3 levels of customization. 1. Global theme (yui.theme) this is the default theme for every Ui 2. Ui theme, this overrides the global theme and provides a default for every Widget of the Ui 3. Widget theme, this overrides the Ui theme for a single widget This commit also allows themes to specify a font field. This replaces the sparse color, font and cornerRadius field often provided by each Widget. Widgets and Uis may also partially override a theme by specifying only a few fields.
This commit is contained in:
10
slider.lua
10
slider.lua
@@ -24,7 +24,6 @@ Slider.__index = Slider
|
||||
-- @field vertical (boolean) true for vertical slider, false or nil for horizontal slider
|
||||
-- @field value (number) default value
|
||||
-- @field step (number) number of slider's steps
|
||||
-- @field cornerRadius (number) radius for rounded corners
|
||||
-- @table SliderAttributes
|
||||
|
||||
|
||||
@@ -33,8 +32,6 @@ Slider.__index = Slider
|
||||
function Slider:new(args)
|
||||
self = setmetatable(args, self)
|
||||
|
||||
self.color = self.color or core.theme.color
|
||||
self.cornerRadius = self.cornerRadius or core.theme.cornerRadius
|
||||
self.vertical = self.vertical or false
|
||||
self.min = self.min or 0
|
||||
self.max = self.max or 1
|
||||
@@ -87,7 +84,8 @@ end
|
||||
function Slider:draw()
|
||||
local x,y,w,h = self.x,self.y,self.w,self.h
|
||||
local r = math.min(w,h) / 2.1
|
||||
local c = self:colorForState()
|
||||
local color, _, cornerRadius = core.themeForWidget(self)
|
||||
local c = core.colorForWidgetState(self, color)
|
||||
local fraction = (self.value - self.min) / (self.max - self.min)
|
||||
|
||||
local xb, yb, wb, hb -- size of the progress bar
|
||||
@@ -99,8 +97,8 @@ function Slider:draw()
|
||||
xb, yb, wb, hb = x,y, w*fraction, h
|
||||
end
|
||||
|
||||
core.drawBox(x,y,w,h, c, self.cornerRadius)
|
||||
core.drawBox(xb,yb,wb,hb, {bg=c.fg}, self.cornerRadius)
|
||||
core.drawBox(x,y,w,h, c, cornerRadius)
|
||||
core.drawBox(xb,yb,wb,hb, { bg = c.fg }, cornerRadius)
|
||||
|
||||
if self:isFocused() then
|
||||
love.graphics.setColor(c.fg)
|
||||
|
Reference in New Issue
Block a user