chore: remove unused variables
This commit is contained in:
parent
9b80e81c47
commit
fcd5bd1109
18
colors.lua
18
colors.lua
|
@ -6,12 +6,13 @@ local floor = math.floor
|
|||
local max = math.max
|
||||
local min = math.min
|
||||
local random = math.random
|
||||
local gcolor = require("gears.color")
|
||||
local gcolor = require "gears.color"
|
||||
local parse_color = gcolor.parse_color
|
||||
|
||||
-- Returns a value that is clipped to interval edges if it falls outside the interval
|
||||
local function clip(num, min_num, max_num) return
|
||||
max(min(num, max_num), min_num) end
|
||||
local function clip(num, min_num, max_num)
|
||||
return max(min(num, max_num), min_num)
|
||||
end
|
||||
|
||||
-- Converts the given hex color to normalized rgba
|
||||
local function hex2rgb(color)
|
||||
|
@ -60,8 +61,12 @@ end
|
|||
local function hsv2hex(H, S, V)
|
||||
S = S / 100
|
||||
V = V / 100
|
||||
if H > 360 then H = 360 end
|
||||
if H < 0 then H = 0 end
|
||||
if H > 360 then
|
||||
H = 360
|
||||
end
|
||||
if H < 0 then
|
||||
H = 0
|
||||
end
|
||||
local C = V * S
|
||||
local X = C * (1 - math.abs(((H / 60) % 2) - 1))
|
||||
local m = V - C
|
||||
|
@ -87,7 +92,8 @@ end
|
|||
local function relative_luminance(color)
|
||||
local r, g, b = hex2rgb(color)
|
||||
local function from_sRGB(u)
|
||||
return u <= 0.0031308 and 25 * u / 323 or ((200 * u + 11) / 211) ^ (12 / 5)
|
||||
return u <= 0.0031308 and 25 * u / 323
|
||||
or ((200 * u + 11) / 211) ^ (12 / 5)
|
||||
end
|
||||
return 0.2126 * from_sRGB(r) + 0.7152 * from_sRGB(g) + 0.0722 * from_sRGB(b)
|
||||
end
|
||||
|
|
13
init.lua
13
init.lua
|
@ -9,11 +9,7 @@ Author: mu-tex
|
|||
License: MIT
|
||||
Repository: https://github.com/mut-ex/awesome-wm-nice
|
||||
]]
|
||||
-- ============================================================
|
||||
-- local ret, helpers = pcall(require, "helpers")
|
||||
-- local debug = ret and helpers.debug or function() end
|
||||
-- => Awesome WM
|
||||
-- ============================================================
|
||||
|
||||
local awful = require "awful"
|
||||
local atooltip = awful.tooltip
|
||||
local abutton = awful.button
|
||||
|
@ -44,7 +40,6 @@ local gtimer_weak_start_new = gtimer.weak_start_new
|
|||
local math = math
|
||||
local max = math.max
|
||||
local abs = math.abs
|
||||
local rad = math.rad
|
||||
local floor = math.floor
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
|
@ -54,7 +49,6 @@ local ipairs = ipairs
|
|||
-- => LGI
|
||||
-- ============================================================
|
||||
local lgi = require "lgi"
|
||||
local cairo = lgi.cairo
|
||||
local gdk = lgi.require("Gdk", "3.0")
|
||||
local get_default_root_window = gdk.get_default_root_window
|
||||
local pixbuf_get_from_surface = gdk.pixbuf_get_from_surface
|
||||
|
@ -415,7 +409,6 @@ local function create_titlebar_button(c, name, button_callback, property)
|
|||
end
|
||||
|
||||
local function get_titlebar_mouse_bindings(c)
|
||||
local client_color = c._nice_base_color
|
||||
local shade_enabled = _private.win_shade_enabled
|
||||
-- Add functionality for double click to (un)maximize, and single click and hold to move
|
||||
local clicks = 0
|
||||
|
@ -458,7 +451,6 @@ local function get_titlebar_mouse_bindings(c)
|
|||
set_color_rule(c, c._nice_base_color)
|
||||
_private.add_window_decorations(c)
|
||||
end)
|
||||
local picked_color
|
||||
add_item("Manually Pick Color", function()
|
||||
_G.mousegrabber.run(function(m)
|
||||
if m.buttons[1] then
|
||||
|
@ -932,7 +924,7 @@ local function validate_mb_bindings()
|
|||
local mb_specified = { false, false, false, false, false }
|
||||
local mb
|
||||
local mb_conflict_test
|
||||
for i, action_mb in ipairs(action_mbs) do
|
||||
for _, action_mb in ipairs(action_mbs) do
|
||||
mb = _private[action_mb]
|
||||
if mb then
|
||||
assert(mb >= 1 and mb <= 5, "Invalid mouse button specified!")
|
||||
|
@ -948,7 +940,6 @@ local function validate_mb_bindings()
|
|||
)
|
||||
)
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
412
shapes.lua
412
shapes.lua
|
@ -2,242 +2,272 @@
|
|||
-- Provides utility functions for handling cairo shapes and geometry
|
||||
-- ============================================================
|
||||
--
|
||||
local lgi = require("lgi")
|
||||
local colors = require("awesome-wm-nice.colors")
|
||||
local lgi = require "lgi"
|
||||
local colors = require "awesome-wm-nice.colors"
|
||||
local hex2rgb = colors.hex2rgb
|
||||
local darken = colors.darken
|
||||
local cairo = lgi.cairo
|
||||
local math = math
|
||||
local rad = math.rad
|
||||
local floor = math.floor
|
||||
local min = math.min
|
||||
|
||||
-- Returns a shape function for a rounded rectangle with independently configurable corner radii
|
||||
local function rounded_rect(args)
|
||||
local r1 = args.tl or 0
|
||||
local r2 = args.bl or 0
|
||||
local r3 = args.br or 0
|
||||
local r4 = args.tr or 0
|
||||
return function(cr, width, height)
|
||||
cr:new_sub_path()
|
||||
cr:arc(width - r1, r1, r1, rad(-90), rad(0))
|
||||
cr:arc(width - r2, height - r2, r2, rad(0), rad(90))
|
||||
cr:arc(r3, height - r3, r3, rad(90), rad(180))
|
||||
cr:arc(r4, r4, r4, rad(180), rad(270))
|
||||
cr:close_path()
|
||||
end
|
||||
local r1 = args.tl or 0
|
||||
local r2 = args.bl or 0
|
||||
local r3 = args.br or 0
|
||||
local r4 = args.tr or 0
|
||||
return function(cr, width, height)
|
||||
cr:new_sub_path()
|
||||
cr:arc(width - r1, r1, r1, rad(-90), rad(0))
|
||||
cr:arc(width - r2, height - r2, r2, rad(0), rad(90))
|
||||
cr:arc(r3, height - r3, r3, rad(90), rad(180))
|
||||
cr:arc(r4, r4, r4, rad(180), rad(270))
|
||||
cr:close_path()
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns a circle of the specified size filled with the specified color
|
||||
local function circle_filled(color, size)
|
||||
color = color or "#fefefa"
|
||||
local surface = cairo.ImageSurface.create("ARGB32", size, size)
|
||||
local cr = cairo.Context.create(surface)
|
||||
cr:arc(size / 2, size / 2, size / 2, rad(0), rad(360))
|
||||
cr:set_source_rgba(hex2rgb(color))
|
||||
cr.antialias = cairo.Antialias.BEST
|
||||
cr:fill()
|
||||
-- cr:arc(
|
||||
-- size / 2, size / 2, size / 2 - 0.5, rad(135), rad(270))
|
||||
-- cr:set_source_rgba(hex2rgb(darken(color, 25)))
|
||||
-- cr.line_width = 1
|
||||
-- cr:stroke()
|
||||
color = color or "#fefefa"
|
||||
local surface = cairo.ImageSurface.create("ARGB32", size, size)
|
||||
local cr = cairo.Context.create(surface)
|
||||
cr:arc(size / 2, size / 2, size / 2, rad(0), rad(360))
|
||||
cr:set_source_rgba(hex2rgb(color))
|
||||
cr.antialias = cairo.Antialias.BEST
|
||||
cr:fill()
|
||||
-- cr:arc(
|
||||
-- size / 2, size / 2, size / 2 - 0.5, rad(135), rad(270))
|
||||
-- cr:set_source_rgba(hex2rgb(darken(color, 25)))
|
||||
-- cr.line_width = 1
|
||||
-- cr:stroke()
|
||||
|
||||
return surface
|
||||
return surface
|
||||
end
|
||||
|
||||
-- Returns a vertical gradient pattern going from cololr_1 -> color_2
|
||||
local function duotone_gradient_vertical(color_1, color_2, height, offset_1, offset_2)
|
||||
local fill_pattern = cairo.Pattern.create_linear(0, 0, 0, height)
|
||||
local r, g, b, a
|
||||
r, g, b, a = hex2rgb(color_1)
|
||||
fill_pattern:add_color_stop_rgba(offset_1 or 0, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color_2)
|
||||
fill_pattern:add_color_stop_rgba(offset_2 or 1, r, g, b, a)
|
||||
return fill_pattern
|
||||
local function duotone_gradient_vertical(
|
||||
color_1,
|
||||
color_2,
|
||||
height,
|
||||
offset_1,
|
||||
offset_2
|
||||
)
|
||||
local fill_pattern = cairo.Pattern.create_linear(0, 0, 0, height)
|
||||
local r, g, b, a
|
||||
r, g, b, a = hex2rgb(color_1)
|
||||
fill_pattern:add_color_stop_rgba(offset_1 or 0, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color_2)
|
||||
fill_pattern:add_color_stop_rgba(offset_2 or 1, r, g, b, a)
|
||||
return fill_pattern
|
||||
end
|
||||
|
||||
-- Returns a horizontal gradient pattern going from cololr_1 -> color_2
|
||||
local function duotone_gradient_horizontal(color, width)
|
||||
local fill_pattern = cairo.Pattern.create_linear(0, 0, width, 0)
|
||||
local r, g, b, a
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(0, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(0.5, r, g, b, a)
|
||||
r, g, b, a = hex2rgb("#00000000")
|
||||
fill_pattern:add_color_stop_rgba(0.6, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(0.7, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(1, r, g, b, a)
|
||||
return fill_pattern
|
||||
local fill_pattern = cairo.Pattern.create_linear(0, 0, width, 0)
|
||||
local r, g, b, a
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(0, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(0.5, r, g, b, a)
|
||||
r, g, b, a = hex2rgb "#00000000"
|
||||
fill_pattern:add_color_stop_rgba(0.6, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(0.7, r, g, b, a)
|
||||
r, g, b, a = hex2rgb(color)
|
||||
fill_pattern:add_color_stop_rgba(1, r, g, b, a)
|
||||
return fill_pattern
|
||||
end
|
||||
|
||||
-- Flips the given surface around the specified axis
|
||||
local function flip(surface, axis)
|
||||
local width = surface:get_width()
|
||||
local height = surface:get_height()
|
||||
local flipped = cairo.ImageSurface.create("ARGB32", width, height)
|
||||
local cr = cairo.Context.create(flipped)
|
||||
local source_pattern = cairo.Pattern.create_for_surface(surface)
|
||||
if axis == "horizontal" then
|
||||
source_pattern.matrix = cairo.Matrix({ xx = -1, yy = 1, x0 = width })
|
||||
elseif axis == "vertical" then
|
||||
source_pattern.matrix = cairo.Matrix({ xx = 1, yy = -1, y0 = height })
|
||||
elseif axis == "both" then
|
||||
source_pattern.matrix = cairo.Matrix({
|
||||
xx = -1,
|
||||
yy = -1,
|
||||
x0 = width,
|
||||
y0 = height,
|
||||
})
|
||||
end
|
||||
cr.source = source_pattern
|
||||
cr:rectangle(0, 0, width, height)
|
||||
cr:paint()
|
||||
local width = surface:get_width()
|
||||
local height = surface:get_height()
|
||||
local flipped = cairo.ImageSurface.create("ARGB32", width, height)
|
||||
local cr = cairo.Context.create(flipped)
|
||||
local source_pattern = cairo.Pattern.create_for_surface(surface)
|
||||
if axis == "horizontal" then
|
||||
source_pattern.matrix = cairo.Matrix { xx = -1, yy = 1, x0 = width }
|
||||
elseif axis == "vertical" then
|
||||
source_pattern.matrix = cairo.Matrix { xx = 1, yy = -1, y0 = height }
|
||||
elseif axis == "both" then
|
||||
source_pattern.matrix = cairo.Matrix {
|
||||
xx = -1,
|
||||
yy = -1,
|
||||
x0 = width,
|
||||
y0 = height,
|
||||
}
|
||||
end
|
||||
cr.source = source_pattern
|
||||
cr:rectangle(0, 0, width, height)
|
||||
cr:paint()
|
||||
|
||||
return flipped
|
||||
return flipped
|
||||
end
|
||||
|
||||
-- Draws the left corner of the titlebar
|
||||
local function create_corner_top_left(args)
|
||||
local radius = args.radius
|
||||
local height = args.height
|
||||
local surface = cairo.ImageSurface.create("ARGB32", radius, height)
|
||||
local cr = cairo.Context.create(surface)
|
||||
-- Create the corner shape and fill it with a gradient
|
||||
local radius_offset = 1 -- To soften the corner
|
||||
cr:move_to(0, height)
|
||||
cr:line_to(0, radius - radius_offset)
|
||||
cr:arc(radius + radius_offset, radius + radius_offset, radius, rad(180), rad(270))
|
||||
cr:line_to(radius, height)
|
||||
cr:close_path()
|
||||
cr.source = args.background_source
|
||||
cr.antialias = cairo.Antialias.BEST
|
||||
cr:fill()
|
||||
-- Next add the subtle 3D look
|
||||
local function add_stroke(nargs)
|
||||
local arc_radius = nargs.radius
|
||||
local offset_x = nargs.offset_x
|
||||
local offset_y = nargs.offset_y
|
||||
cr:new_sub_path()
|
||||
cr:move_to(offset_x, height)
|
||||
cr:line_to(offset_x, arc_radius + offset_y)
|
||||
cr:arc(arc_radius + offset_x, arc_radius + offset_y, arc_radius, rad(180), rad(270))
|
||||
cr.source = nargs.source
|
||||
cr.line_width = nargs.width
|
||||
cr.antialias = cairo.Antialias.BEST
|
||||
cr:stroke()
|
||||
end
|
||||
-- Outer dark stroke
|
||||
add_stroke({
|
||||
offset_x = args.stroke_offset_outer,
|
||||
offset_y = args.stroke_offset_outer,
|
||||
radius = radius + 0.5,
|
||||
source = args.stroke_source_outer,
|
||||
width = args.stroke_width_outer,
|
||||
})
|
||||
-- Inner light stroke
|
||||
add_stroke({
|
||||
offset_x = args.stroke_offset_inner,
|
||||
offset_y = args.stroke_offset_inner,
|
||||
radius = radius,
|
||||
width = args.stroke_width_inner,
|
||||
source = args.stroke_source_inner,
|
||||
})
|
||||
local radius = args.radius
|
||||
local height = args.height
|
||||
local surface = cairo.ImageSurface.create("ARGB32", radius, height)
|
||||
local cr = cairo.Context.create(surface)
|
||||
-- Create the corner shape and fill it with a gradient
|
||||
local radius_offset = 1 -- To soften the corner
|
||||
cr:move_to(0, height)
|
||||
cr:line_to(0, radius - radius_offset)
|
||||
cr:arc(
|
||||
radius + radius_offset,
|
||||
radius + radius_offset,
|
||||
radius,
|
||||
rad(180),
|
||||
rad(270)
|
||||
)
|
||||
cr:line_to(radius, height)
|
||||
cr:close_path()
|
||||
cr.source = args.background_source
|
||||
cr.antialias = cairo.Antialias.BEST
|
||||
cr:fill()
|
||||
-- Next add the subtle 3D look
|
||||
local function add_stroke(nargs)
|
||||
local arc_radius = nargs.radius
|
||||
local offset_x = nargs.offset_x
|
||||
local offset_y = nargs.offset_y
|
||||
cr:new_sub_path()
|
||||
cr:move_to(offset_x, height)
|
||||
cr:line_to(offset_x, arc_radius + offset_y)
|
||||
cr:arc(
|
||||
arc_radius + offset_x,
|
||||
arc_radius + offset_y,
|
||||
arc_radius,
|
||||
rad(180),
|
||||
rad(270)
|
||||
)
|
||||
cr.source = nargs.source
|
||||
cr.line_width = nargs.width
|
||||
cr.antialias = cairo.Antialias.BEST
|
||||
cr:stroke()
|
||||
end
|
||||
-- Outer dark stroke
|
||||
add_stroke {
|
||||
offset_x = args.stroke_offset_outer,
|
||||
offset_y = args.stroke_offset_outer,
|
||||
radius = radius + 0.5,
|
||||
source = args.stroke_source_outer,
|
||||
width = args.stroke_width_outer,
|
||||
}
|
||||
-- Inner light stroke
|
||||
add_stroke {
|
||||
offset_x = args.stroke_offset_inner,
|
||||
offset_y = args.stroke_offset_inner,
|
||||
radius = radius,
|
||||
width = args.stroke_width_inner,
|
||||
source = args.stroke_source_inner,
|
||||
}
|
||||
|
||||
return surface
|
||||
return surface
|
||||
end
|
||||
|
||||
-- Draws the middle of the titlebar
|
||||
local function create_edge_top_middle(args)
|
||||
local client_color = args.color
|
||||
local height = args.height
|
||||
local width = args.width
|
||||
local surface = cairo.ImageSurface.create("ARGB32", width, height)
|
||||
local cr = cairo.Context.create(surface)
|
||||
-- Create the background shape and fill it with a gradient
|
||||
cr:rectangle(0, 0, width, height)
|
||||
cr.source = args.background_source
|
||||
cr:fill()
|
||||
-- Then add the light and dark strokes for that 3D look
|
||||
local function add_stroke(stroke_width, stroke_offset, stroke_color)
|
||||
cr:new_sub_path()
|
||||
cr:move_to(0, stroke_offset)
|
||||
cr:line_to(width, stroke_offset)
|
||||
cr.line_width = stroke_width
|
||||
cr:set_source_rgb(hex2rgb(stroke_color))
|
||||
cr:stroke()
|
||||
end
|
||||
-- Inner light stroke
|
||||
add_stroke(args.stroke_width_inner, args.stroke_offset_inner, args.stroke_color_inner)
|
||||
-- Outer dark stroke
|
||||
add_stroke(args.stroke_width_outer, args.stroke_offset_outer, args.stroke_color_outer)
|
||||
local height = args.height
|
||||
local width = args.width
|
||||
local surface = cairo.ImageSurface.create("ARGB32", width, height)
|
||||
local cr = cairo.Context.create(surface)
|
||||
-- Create the background shape and fill it with a gradient
|
||||
cr:rectangle(0, 0, width, height)
|
||||
cr.source = args.background_source
|
||||
cr:fill()
|
||||
-- Then add the light and dark strokes for that 3D look
|
||||
local function add_stroke(stroke_width, stroke_offset, stroke_color)
|
||||
cr:new_sub_path()
|
||||
cr:move_to(0, stroke_offset)
|
||||
cr:line_to(width, stroke_offset)
|
||||
cr.line_width = stroke_width
|
||||
cr:set_source_rgb(hex2rgb(stroke_color))
|
||||
cr:stroke()
|
||||
end
|
||||
-- Inner light stroke
|
||||
add_stroke(
|
||||
args.stroke_width_inner,
|
||||
args.stroke_offset_inner,
|
||||
args.stroke_color_inner
|
||||
)
|
||||
-- Outer dark stroke
|
||||
add_stroke(
|
||||
args.stroke_width_outer,
|
||||
args.stroke_offset_outer,
|
||||
args.stroke_color_outer
|
||||
)
|
||||
|
||||
return surface
|
||||
return surface
|
||||
end
|
||||
|
||||
local function create_edge_left(args)
|
||||
local height = args.height
|
||||
local width = 2
|
||||
-- height = height or 1080
|
||||
local surface = cairo.ImageSurface.create("ARGB32", width, height)
|
||||
local cr = cairo.Context.create(surface)
|
||||
cr:rectangle(0, 0, 2, args.height)
|
||||
cr:set_source_rgb(hex2rgb(args.client_color))
|
||||
cr:fill()
|
||||
-- Inner light stroke
|
||||
cr:new_sub_path()
|
||||
cr:move_to(args.stroke_offset_inner, 0) -- 1/5
|
||||
cr:line_to(args.stroke_offset_inner, height)
|
||||
cr.line_width = args.stroke_width_inner -- 1.5
|
||||
cr:set_source_rgb(hex2rgb(args.inner_stroke_color))
|
||||
cr:stroke()
|
||||
-- Outer dark stroke
|
||||
cr:new_sub_path()
|
||||
cr:move_to(args.stroke_offset_outer, 0)
|
||||
cr:line_to(args.stroke_offset_outer, height)
|
||||
cr.line_width = args.stroke_width_outer -- 1
|
||||
cr:set_source_rgb(hex2rgb(args.stroke_color_outer))
|
||||
cr:stroke()
|
||||
local height = args.height
|
||||
local width = 2
|
||||
-- height = height or 1080
|
||||
local surface = cairo.ImageSurface.create("ARGB32", width, height)
|
||||
local cr = cairo.Context.create(surface)
|
||||
cr:rectangle(0, 0, 2, args.height)
|
||||
cr:set_source_rgb(hex2rgb(args.client_color))
|
||||
cr:fill()
|
||||
-- Inner light stroke
|
||||
cr:new_sub_path()
|
||||
cr:move_to(args.stroke_offset_inner, 0) -- 1/5
|
||||
cr:line_to(args.stroke_offset_inner, height)
|
||||
cr.line_width = args.stroke_width_inner -- 1.5
|
||||
cr:set_source_rgb(hex2rgb(args.inner_stroke_color))
|
||||
cr:stroke()
|
||||
-- Outer dark stroke
|
||||
cr:new_sub_path()
|
||||
cr:move_to(args.stroke_offset_outer, 0)
|
||||
cr:line_to(args.stroke_offset_outer, height)
|
||||
cr.line_width = args.stroke_width_outer -- 1
|
||||
cr:set_source_rgb(hex2rgb(args.stroke_color_outer))
|
||||
cr:stroke()
|
||||
|
||||
return surface
|
||||
return surface
|
||||
end
|
||||
|
||||
local function set_font(cr, font)
|
||||
cr:set_font_size(font.size)
|
||||
cr:select_font_face(font.font or "Inter", font.italic and 1 or 0, font.bold and 1 or 0)
|
||||
cr:set_font_size(font.size)
|
||||
cr:select_font_face(
|
||||
font.font or "Inter",
|
||||
font.italic and 1 or 0,
|
||||
font.bold and 1 or 0
|
||||
)
|
||||
end
|
||||
|
||||
local function text_label(args)
|
||||
local surface = cairo.ImageSurface.create("ARGB32", 1, 1)
|
||||
local cr = cairo.Context.create(surface)
|
||||
set_font(cr, args.font)
|
||||
local text = args.text
|
||||
local kern = args.font.kerning or 0
|
||||
local ext = cr:text_extents(text)
|
||||
surface = cairo.ImageSurface.create("ARGB32", ext.width + string.len(text) * kern, ext.height)
|
||||
cr = cairo.Context.create(surface)
|
||||
set_font(cr, args.font)
|
||||
cr:move_to(0, ext.height)
|
||||
cr:set_source_rgb(hex2rgb(args.color))
|
||||
-- cr:show_text(text)
|
||||
text:gsub(".", function(c)
|
||||
-- do something with c
|
||||
cr:show_text(c)
|
||||
cr:rel_move_to(kern, 0)
|
||||
end)
|
||||
return surface
|
||||
local surface = cairo.ImageSurface.create("ARGB32", 1, 1)
|
||||
local cr = cairo.Context.create(surface)
|
||||
set_font(cr, args.font)
|
||||
local text = args.text
|
||||
local kern = args.font.kerning or 0
|
||||
local ext = cr:text_extents(text)
|
||||
surface = cairo.ImageSurface.create(
|
||||
"ARGB32",
|
||||
ext.width + string.len(text) * kern,
|
||||
ext.height
|
||||
)
|
||||
cr = cairo.Context.create(surface)
|
||||
set_font(cr, args.font)
|
||||
cr:move_to(0, ext.height)
|
||||
cr:set_source_rgb(hex2rgb(args.color))
|
||||
-- cr:show_text(text)
|
||||
text:gsub(".", function(c)
|
||||
-- do something with c
|
||||
cr:show_text(c)
|
||||
cr:rel_move_to(kern, 0)
|
||||
end)
|
||||
return surface
|
||||
end
|
||||
|
||||
return {
|
||||
rounded_rect = rounded_rect,
|
||||
circle_filled = circle_filled,
|
||||
duotone_gradient_vertical = duotone_gradient_vertical,
|
||||
flip = flip,
|
||||
create_corner_top_left = create_corner_top_left,
|
||||
create_edge_top_middle = create_edge_top_middle,
|
||||
create_edge_left = create_edge_left,
|
||||
text_label = text_label,
|
||||
rounded_rect = rounded_rect,
|
||||
circle_filled = circle_filled,
|
||||
duotone_gradient_vertical = duotone_gradient_vertical,
|
||||
flip = flip,
|
||||
create_corner_top_left = create_corner_top_left,
|
||||
create_edge_top_middle = create_edge_top_middle,
|
||||
create_edge_left = create_edge_left,
|
||||
text_label = text_label,
|
||||
}
|
||||
|
|
28
table.lua
28
table.lua
|
@ -1,15 +1,20 @@
|
|||
--[[
|
||||
Courtesy of: http://lua-users.org/wiki/SaveTableToFile
|
||||
]] local function exportstring(s) return string.format("%q", s) end
|
||||
]]
|
||||
local function exportstring(s)
|
||||
return string.format("%q", s)
|
||||
end
|
||||
|
||||
-- The Save Function
|
||||
local function save(tbl, filename)
|
||||
local charS, charE = " ", "\n"
|
||||
local file, err = io.open(filename, "wb")
|
||||
if err then return err end
|
||||
if err then
|
||||
return err
|
||||
end
|
||||
|
||||
-- Initialize variables for save procedure
|
||||
local tables, lookup = {tbl}, {[tbl] = 1}
|
||||
local tables, lookup = { tbl }, { [tbl] = 1 }
|
||||
file:write("return {" .. charE)
|
||||
|
||||
for idx, t in ipairs(tables) do
|
||||
|
@ -36,8 +41,7 @@ local function save(tbl, filename)
|
|||
|
||||
for i, v in pairs(t) do
|
||||
-- escape handled values
|
||||
if (not thandled[i]) then
|
||||
|
||||
if not thandled[i] then
|
||||
local str = ""
|
||||
local stype = type(i)
|
||||
-- handle index
|
||||
|
@ -72,21 +76,25 @@ local function save(tbl, filename)
|
|||
end
|
||||
file:write("}," .. charE)
|
||||
end
|
||||
file:write("}")
|
||||
file:write "}"
|
||||
file:close()
|
||||
end
|
||||
|
||||
-- The Load Function
|
||||
local function load(sfile)
|
||||
local ftables, err = loadfile(sfile)
|
||||
if err then return _, err end
|
||||
if err then
|
||||
return nil, err
|
||||
end
|
||||
local tables = ftables()
|
||||
for idx = 1, #tables do
|
||||
local tolinki = {}
|
||||
for i, v in pairs(tables[idx]) do
|
||||
if type(v) == "table" then tables[idx][i] = tables[v[1]] end
|
||||
if type(v) == "table" then
|
||||
tables[idx][i] = tables[v[1]]
|
||||
end
|
||||
if type(i) == "table" and tables[i[1]] then
|
||||
table.insert(tolinki, {i, tables[i[1]]})
|
||||
table.insert(tolinki, { i, tables[i[1]] })
|
||||
end
|
||||
end
|
||||
-- link indices
|
||||
|
@ -97,4 +105,4 @@ local function load(sfile)
|
|||
return tables[1]
|
||||
end
|
||||
|
||||
return {save = save, load = load}
|
||||
return { save = save, load = load }
|
||||
|
|
Loading…
Reference in New Issue