diff options
Diffstat (limited to '.config/awesome/ui/statusbar/panel/widgets/calendar.lua')
-rw-r--r-- | .config/awesome/ui/statusbar/panel/widgets/calendar.lua | 172 |
1 files changed, 122 insertions, 50 deletions
diff --git a/.config/awesome/ui/statusbar/panel/widgets/calendar.lua b/.config/awesome/ui/statusbar/panel/widgets/calendar.lua index 8933543..ddbffc0 100644 --- a/.config/awesome/ui/statusbar/panel/widgets/calendar.lua +++ b/.config/awesome/ui/statusbar/panel/widgets/calendar.lua @@ -1,58 +1,123 @@ local awful = require "awful" local phosphor = require "assets.phosphor" local qbind = require "quarrel.bind" +local qcolor = require "quarrel.color" local qmarkup = require "quarrel.markup" local qui = require "quarrel.ui" -local qvars = require "quarrel.vars" local wibox = require "wibox" local weekday_map = { 7, 1, 2, 3, 4, 5, 6 } local calendar = wibox.widget(qui.styled { widget = wibox.container.background, + bg = qcolor.palette.bg.high, { widget = wibox.container.margin, - margins = qvars.big_padding, + margins = qui.BORDER_WIDTH, { { { - widget = wibox.container.place, - qui.icon { - icon = phosphor.caret_left_bold, + layout = wibox.layout.grid, + forced_num_rows = 7, + forced_num_cols = 7, + -- spacing = (qui.PADDING) / 2, + border_width = { + inner = qui.BORDER_WIDTH, + outer = 0, }, + border_color = qcolor.palette.border.variant, + id = "grid", }, { - widget = wibox.container.place, - { - widget = wibox.widget.textbox, - text = "January 2024", - }, + widget = wibox.container.background, + bg = qcolor.palette.border(), + forced_width = qui.BORDER_WIDTH, }, + layout = wibox.layout.fixed.horizontal, + }, + { + widget = wibox.container.margin, + margins = qui.BIG_PADDING, { - widget = wibox.container.place, - qui.icon { - icon = phosphor.caret_right_bold, + { + widget = wibox.container.place, + fill_horizontal = true, + { + widget = wibox.widget.textbox, + text = "05\n25", + }, }, + nil, + qui.styled { + widget = wibox.container.background, + bg = qcolor.palette.bg.highest, + { + { + widget = wibox.container.margin, + margins = qui.PADDING, + { + widget = wibox.container.place, + qui.icon { + icon = phosphor.caret_up_bold, + widget = { + forced_height = qui.CHAR_HEIGHT / 2, + forced_width = qui.CHAR_HEIGHT / 2, + }, + }, + }, + }, + { + widget = wibox.container.background, + bg = qcolor.palette.border.variant, + forced_height = qui.BORDER_WIDTH, + }, + { + widget = wibox.container.margin, + margins = qui.PADDING, + { + widget = wibox.container.place, + qui.icon { + icon = phosphor.caret_down_bold, + widget = { + forced_height = qui.CHAR_HEIGHT / 2, + forced_width = qui.CHAR_HEIGHT / 2, + }, + }, + }, + }, + layout = wibox.layout.fixed.vertical, + -- spacing = qui.PADDING + }, + }, + layout = wibox.layout.align.vertical, }, - layout = wibox.layout.align.horizontal, - expand = "outside", - }, - { - layout = wibox.layout.grid, - forced_num_rows = 7, - forced_num_cols = 7, - spacing = qvars.padding, - id = "grid", }, - layout = wibox.layout.fixed.vertical, - spacing = qvars.big_padding, + layout = wibox.layout.fixed.horizontal, }, }, }) +local grid = calendar:get_children_by_id("grid")[1] + -- Logic heavily inspired by https://github.com/Sinomor/dotfiles/blob/e409f9a84bf40daf1e39c0179ec749232ed827c9/home/.config/awesome/ui/control/moment/calendar.lua#L134-L173 function calendar:compute_grid(year, month) - local calendar_table = { {}, {}, {}, {}, {}, {} } + local calendar_table = { + { + { "Mo", false, true }, + { "Tu", false, true }, + { "We", false, true }, + { "Th", false, true }, + { "Fr", false, true }, + { "Sa", false, true }, + { "Su", false, true }, + }, + {}, + {}, + {}, + {}, + {}, + {}, + } local current = os.date("*t", os.time()) local first_day = os.date("*t", os.time { year = year, month = month, day = 1 }) local last_day = os.date("*t", os.time { year = year, month = month + 1, day = 0 }) @@ -68,14 +133,14 @@ function calendar:compute_grid(year, month) for offset = prev_offset, 1, -1 do local day = prev_days.day - offset + 1 table.insert( - calendar_table[1], + calendar_table[2], { day, day == current.day and prev_month == current.month and prev_year == current.year, false } ) end end do - local row = 1 + local row = 2 local weekday = weekday_map[first_day.wday] for day = 1, days do table.insert( @@ -108,14 +173,22 @@ function calendar:compute_grid(year, month) for i, row in ipairs(calendar_table) do for j, col in ipairs(row) do - local widget = self:get_children_by_id("grid")[1]:get_widgets_at(i + 1, j)[1] - widget.widget.widget.text = col[1] + local widget = grid:get_widgets_at(i, j)[1] + widget.widget.widget.widget.text = col[1] if col[2] then - widget.bg = qvars.colors.yellow - widget.fg = qvars.colors.bg + widget.bg = qcolor.palette.yellow() + widget.fg = qcolor.palette.bg() + elseif j % 6 == 0 or j % 7 == 0 then + widget.bg = col[3] and qcolor.palette.bg.highest or qcolor.palette.bg.high else - widget.bg = qvars.colors.bg - widget.fg = col[3] and qvars.colors.fg or qvars.colors.dim.fg + widget.bg = col[3] and qcolor.palette.bg.high or qcolor.palette.bg() + end + + if i == 1 then + widget.fg = qcolor.palette.fg() + elseif not col[2] then + -- widget.fg = col[3] and qcolor.palette.fg() or qcolor.palette.fg.low + widget.fg = qcolor.palette.fg.low end end end @@ -125,32 +198,31 @@ local cells = {} local function cell(content) local widget = wibox.widget { widget = wibox.container.background, - shape = qvars.shape, + bg = qcolor.palette.bg.high, + -- shape = qui.shape, { - widget = wibox.container.place, - forced_height = qvars.char_height * 1.5, - forced_width = qvars.char_height * 1.5, + widget = wibox.container.margin, + margins = qui.PADDING * 1.5, { - widget = wibox.widget.textbox, - markup = content, + widget = wibox.container.place, + forced_height = qui.CHAR_HEIGHT, + forced_width = qui.CHAR_HEIGHT, + { + widget = wibox.widget.textbox, + markup = content, + }, }, }, } table.insert(cells, widget) end -cell "Mo" -cell "Tu" -cell "We" -cell "Th" -cell "Fr" -cell(qmarkup("Sa", { bold = true })) -cell(qmarkup("Su", { bold = true })) - -for _ = 1, 42 do +for _ = 1, 49 do cell() end -calendar:get_children_by_id("grid")[1]:add(table.unpack(cells)) -calendar:compute_grid(2024, 1) +grid:add(table.unpack(cells)) +local current_time = os.date "*t" +calendar:compute_grid(current_time.year, current_time.month) +grid:add_row_border(2, qui.BORDER_WIDTH, { color = qcolor.palette.border() }) return calendar |