visually disable disabled checkboxes
This commit is contained in:
parent
56e4f93db8
commit
68851a6b30
@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
|
|||||||
|
|
||||||
local core = {}
|
local core = {}
|
||||||
|
|
||||||
core.version = "2.4.5"
|
core.version = "2.4.6"
|
||||||
|
|
||||||
core.flasher = flasher
|
core.flasher = flasher
|
||||||
core.events = events
|
core.events = events
|
||||||
|
|||||||
@ -6,6 +6,7 @@ local element = require("graphics.element")
|
|||||||
---@class checkbox_args
|
---@class checkbox_args
|
||||||
---@field label string checkbox text
|
---@field label string checkbox text
|
||||||
---@field box_fg_bg cpair colors for checkbox
|
---@field box_fg_bg cpair colors for checkbox
|
||||||
|
---@field disable_fg_bg? cpair text colors when disabled
|
||||||
---@field default? boolean default value
|
---@field default? boolean default value
|
||||||
---@field callback? function function to call on press
|
---@field callback? function function to call on press
|
||||||
---@field parent graphics_element
|
---@field parent graphics_element
|
||||||
@ -35,20 +36,27 @@ return function (args)
|
|||||||
local function draw()
|
local function draw()
|
||||||
e.w_set_cur(1, 1)
|
e.w_set_cur(1, 1)
|
||||||
|
|
||||||
|
local fgd, bkg = args.box_fg_bg.fgd, args.box_fg_bg.bkg
|
||||||
|
|
||||||
|
if (not e.enabled) and type(args.disable_fg_bg) == "table" then
|
||||||
|
fgd = args.disable_fg_bg.bkg
|
||||||
|
bkg = args.disable_fg_bg.fgd
|
||||||
|
end
|
||||||
|
|
||||||
if e.value then
|
if e.value then
|
||||||
-- show as selected
|
-- show as selected
|
||||||
e.w_set_fgd(args.box_fg_bg.bkg)
|
e.w_set_fgd(bkg)
|
||||||
e.w_set_bkg(args.box_fg_bg.fgd)
|
e.w_set_bkg(fgd)
|
||||||
e.w_write("\x88")
|
e.w_write("\x88")
|
||||||
e.w_set_fgd(args.box_fg_bg.fgd)
|
e.w_set_fgd(fgd)
|
||||||
e.w_set_bkg(e.fg_bg.bkg)
|
e.w_set_bkg(e.fg_bg.bkg)
|
||||||
e.w_write("\x95")
|
e.w_write("\x95")
|
||||||
else
|
else
|
||||||
-- show as unselected
|
-- show as unselected
|
||||||
e.w_set_fgd(e.fg_bg.bkg)
|
e.w_set_fgd(e.fg_bg.bkg)
|
||||||
e.w_set_bkg(args.box_fg_bg.bkg)
|
e.w_set_bkg(bkg)
|
||||||
e.w_write("\x88")
|
e.w_write("\x88")
|
||||||
e.w_set_fgd(args.box_fg_bg.bkg)
|
e.w_set_fgd(bkg)
|
||||||
e.w_set_bkg(e.fg_bg.bkg)
|
e.w_set_bkg(e.fg_bg.bkg)
|
||||||
e.w_write("\x95")
|
e.w_write("\x95")
|
||||||
end
|
end
|
||||||
@ -57,16 +65,18 @@ return function (args)
|
|||||||
-- write label text
|
-- write label text
|
||||||
local function draw_label()
|
local function draw_label()
|
||||||
if e.enabled and e.is_focused() then
|
if e.enabled and e.is_focused() then
|
||||||
e.w_set_cur(3, 1)
|
|
||||||
e.w_set_fgd(e.fg_bg.bkg)
|
e.w_set_fgd(e.fg_bg.bkg)
|
||||||
e.w_set_bkg(e.fg_bg.fgd)
|
e.w_set_bkg(e.fg_bg.fgd)
|
||||||
e.w_write(args.label)
|
elseif (not e.enabled) and type(args.disable_fg_bg) == "table" then
|
||||||
|
e.w_set_fgd(args.disable_fg_bg.fgd)
|
||||||
|
e.w_set_bkg(args.disable_fg_bg.bkg)
|
||||||
else
|
else
|
||||||
e.w_set_cur(3, 1)
|
|
||||||
e.w_set_fgd(e.fg_bg.fgd)
|
e.w_set_fgd(e.fg_bg.fgd)
|
||||||
e.w_set_bkg(e.fg_bg.bkg)
|
e.w_set_bkg(e.fg_bg.bkg)
|
||||||
e.w_write(args.label)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
e.w_set_cur(3, 1)
|
||||||
|
e.w_write(args.label)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handle mouse interaction
|
-- handle mouse interaction
|
||||||
@ -98,20 +108,20 @@ return function (args)
|
|||||||
draw()
|
draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handle focus
|
|
||||||
e.on_focused = draw_label
|
|
||||||
e.on_unfocused = draw_label
|
|
||||||
|
|
||||||
-- handle enable
|
|
||||||
e.on_enabled = draw_label
|
|
||||||
e.on_disabled = draw_label
|
|
||||||
|
|
||||||
-- element redraw
|
-- element redraw
|
||||||
function e.redraw()
|
function e.redraw()
|
||||||
draw()
|
draw()
|
||||||
draw_label()
|
draw_label()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- handle focus
|
||||||
|
e.on_focused = draw_label
|
||||||
|
e.on_unfocused = draw_label
|
||||||
|
|
||||||
|
-- handle enable
|
||||||
|
e.on_enabled = e.redraw
|
||||||
|
e.on_disabled = e.redraw
|
||||||
|
|
||||||
---@class Checkbox:graphics_element
|
---@class Checkbox:graphics_element
|
||||||
local Checkbox, id = e.complete(true)
|
local Checkbox, id = e.complete(true)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user