This is a read-only mirror of Please direct any pull-request, issue or discussion to the main repo.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

--- Local drawing helpers
-- @module yui.core
-- @copyright 2022, The DoubleFourteen Code Forge
-- @author Lorenzo Cogotti, Andrea Pasquini
local core = {}
-- Helpers for drawing
function core.verticalOffsetForAlign(valign, font, h)
if valign == 'top' then
return 0
elseif valign == 'bottom' then
return h - font:getHeight()
-- else: 'middle'
return (h - font:getHeight()) / 2
function core.themeForWidget(widget)
local uiTheme = widget.ui.theme
local theme = widget.theme or uiTheme
local color = theme.color or uiTheme.color
local font = theme.font or uiTheme.font or
local cornerRadius = theme.cornerRadius or uiTheme.cornerRadius
return color, font, cornerRadius
function core.colorForWidgetState(widget, color)
color = color or widget.theme.color or widget.ui.theme.color
if then
elseif widget:isFocused() then
return color.hovered
return color.normal
function core.drawBox(x,y,w,h, color, cornerRadius)
w = math.max(cornerRadius/2, w)
if h < cornerRadius/2 then
y,h = y - (cornerRadius - h), cornerRadius/2
end'fill', x,y, w,h, cornerRadius)
return core