Merge pull request #1912 from psychon/calendar_style

Calendar stuff
This commit is contained in:
Emmanuel Lepage Vallée 2017-07-10 10:04:47 -04:00 committed by GitHub
commit 5f5c0ac05a
2 changed files with 48 additions and 54 deletions

View File

@ -275,14 +275,14 @@ end
-- @tparam boolean args.week_numbers Show weeknumbers -- @tparam boolean args.week_numbers Show weeknumbers
-- @tparam boolean args.start_sunday Start week on Sunday -- @tparam boolean args.start_sunday Start week on Sunday
-- @tparam boolean args.long_weekdays Format the weekdays with three characters instead of two -- @tparam boolean args.long_weekdays Format the weekdays with three characters instead of two
-- @tparam table args.year_style Container style for the year calendar (see `cell_properties`) -- @tparam table args.style_year Container style for the year calendar (see `cell_properties`)
-- @tparam table args.month_style Container style for the month calendar (see `cell_properties`) -- @tparam table args.style_month Container style for the month calendar (see `cell_properties`)
-- @tparam table args.yearheader_style Cell style for the year calendar header (see `cell_properties`) -- @tparam table args.style_yearheader Cell style for the year calendar header (see `cell_properties`)
-- @tparam table args.header_style Cell style for the month calendar header (see `cell_properties`) -- @tparam table args.style_header Cell style for the month calendar header (see `cell_properties`)
-- @tparam table args.weekday_style Cell style for the weekday cells (see `cell_properties`) -- @tparam table args.style_weekday Cell style for the weekday cells (see `cell_properties`)
-- @tparam table args.weeknumber_style Cell style for the weeknumber cells (see `cell_properties`) -- @tparam table args.style_weeknumber Cell style for the weeknumber cells (see `cell_properties`)
-- @tparam table args.normal_style Cell style for the normal day cells (see `cell_properties`) -- @tparam table args.style_normal Cell style for the normal day cells (see `cell_properties`)
-- @tparam table args.focus_style Cell style for the current day cell (see `cell_properties`) -- @tparam table args.style_focus Cell style for the current day cell (see `cell_properties`)
-- @treturn wibox A wibox containing the calendar -- @treturn wibox A wibox containing the calendar
local function get_cal_wibox(caltype, args) local function get_cal_wibox(caltype, args)
args = args or {} args = args or {}
@ -337,14 +337,14 @@ end
-- @tparam boolean args.week_numbers Show weeknumbers -- @tparam boolean args.week_numbers Show weeknumbers
-- @tparam boolean args.start_sunday Start week on Sunday -- @tparam boolean args.start_sunday Start week on Sunday
-- @tparam boolean args.long_weekdays Format the weekdays with three characters instead of two -- @tparam boolean args.long_weekdays Format the weekdays with three characters instead of two
-- @tparam table args.month_style Container style for the month calendar (see `cell_properties`) -- @tparam table args.style_month Container style for the month calendar (see `cell_properties`)
-- @tparam table args.header_style Cell style for the month calendar header (see `cell_properties`) -- @tparam table args.style_header Cell style for the month calendar header (see `cell_properties`)
-- @tparam table args.weekday_style Cell style for the weekday cells (see `cell_properties`) -- @tparam table args.style_weekday Cell style for the weekday cells (see `cell_properties`)
-- @tparam table args.weeknumber_style Cell style for the weeknumber cells (see `cell_properties`) -- @tparam table args.style_weeknumber Cell style for the weeknumber cells (see `cell_properties`)
-- @tparam table args.normal_style Cell style for the normal day cells (see `cell_properties`) -- @tparam table args.style_normal Cell style for the normal day cells (see `cell_properties`)
-- @tparam table args.focus_style Cell style for the current day cell (see `cell_properties`) -- @tparam table args.style_focus Cell style for the current day cell (see `cell_properties`)
-- @treturn wibox A wibox containing the calendar -- @treturn wibox A wibox containing the calendar
-- @function awful.calendar.month -- @function awful.widget.calendar.month
function calendar_popup.month(args) function calendar_popup.month(args)
return get_cal_wibox("month", args) return get_cal_wibox("month", args)
end end
@ -370,17 +370,17 @@ end
-- @tparam boolean args.week_numbers Show weeknumbers -- @tparam boolean args.week_numbers Show weeknumbers
-- @tparam boolean args.start_sunday Start week on Sunday -- @tparam boolean args.start_sunday Start week on Sunday
-- @tparam boolean args.long_weekdays Format the weekdays with three characters instead of two -- @tparam boolean args.long_weekdays Format the weekdays with three characters instead of two
-- @tparam table args.year_style Container style for the year calendar (see `cell_properties`) -- @tparam table args.style_year Container style for the year calendar (see `cell_properties`)
-- @tparam table args.month_style Container style for the month calendar (see `cell_properties`). -- @tparam table args.style_month Container style for the month calendar (see `cell_properties`).
-- This field can also be called `monthheader_style`. -- This field can also be called `style_monthheader`.
-- @tparam table args.yearheader_style Cell style for the year calendar header (see `cell_properties`) -- @tparam table args.style_yearheader Cell style for the year calendar header (see `cell_properties`)
-- @tparam table args.header_style Cell style for the month calendar header (see `cell_properties`) -- @tparam table args.style_header Cell style for the month calendar header (see `cell_properties`)
-- @tparam table args.weekday_style Cell style for the weekday cells (see `cell_properties`) -- @tparam table args.style_weekday Cell style for the weekday cells (see `cell_properties`)
-- @tparam table args.weeknumber_style Cell style for the weeknumber cells (see `cell_properties`) -- @tparam table args.style_weeknumber Cell style for the weeknumber cells (see `cell_properties`)
-- @tparam table args.normal_style Cell style for the normal day cells (see `cell_properties`) -- @tparam table args.style_normal Cell style for the normal day cells (see `cell_properties`)
-- @tparam table args.focus_style Cell style for the current day cell (see `cell_properties`) -- @tparam table args.style_focus Cell style for the current day cell (see `cell_properties`)
-- @treturn wibox A wibox containing the calendar -- @treturn wibox A wibox containing the calendar
-- @function awful.calendar.year -- @function awful.widget.calendar.year
function calendar_popup.year(args) function calendar_popup.year(args)
return get_cal_wibox("year", args) return get_cal_wibox("year", args)
end end

View File

@ -123,13 +123,12 @@ local properties = { "date", "font", "spacing", "week_numbers", "start_sunday",
-- @tparam boolean center Center the text horizontally -- @tparam boolean center Center the text horizontally
-- @treturn wibox.widget.textbox -- @treturn wibox.widget.textbox
local function make_cell(text, font, center) local function make_cell(text, font, center)
return base.make_widget_declarative { local w = textbox()
markup = text, w:set_markup(text)
align = center and "center" or "right", w:set_align(center and "center" or "right")
valign = 'center', w:set_valign("center")
font = font, w:set_font(font)
widget = textbox return w
}
end end
--- Create a grid layout with the month calendar --- Create a grid layout with the month calendar
@ -144,14 +143,13 @@ local function create_month(props, date)
local num_columns = props.week_numbers and 8 or 7 local num_columns = props.week_numbers and 8 or 7
-- Create grid layout -- Create grid layout
local layout = base.make_widget_declarative{ local layout = grid()
layout = grid, layout:set_expand(true)
expand = true, layout:set_expand(true)
homogeneous = true, layout:set_homogeneous(true)
spacing = props.spacing, layout:set_spacing(props.spacing)
forced_num_rows = num_rows, layout:set_forced_num_rows(num_rows)
forced_num_cols = num_columns, layout:set_forced_num_cols(num_columns)
}
local start_row = 3 local start_row = 3
local start_column = num_columns - 6 local start_column = num_columns - 6
@ -229,14 +227,12 @@ end
-- @treturn widget Grid layout -- @treturn widget Grid layout
local function create_year(props, date) local function create_year(props, date)
-- Create a grid widget with the 12 months -- Create a grid widget with the 12 months
local in_layout = base.make_widget_declarative{ local in_layout = grid()
layout = grid, in_layout:set_expand(true)
expand = true, in_layout:set_homogeneous(true)
homogeneous = true, in_layout:set_spacing(2*props.spacing)
spacing = 2*props.spacing, in_layout:set_forced_num_cols(4)
forced_num_cols = 4, in_layout:set_forced_num_rows(3)
forced_num_rows = 3,
}
local month_date local month_date
local current_date = os.date("*t") local current_date = os.date("*t")
@ -253,12 +249,10 @@ local function create_year(props, date)
-- Create a vertical layout -- Create a vertical layout
local flag, text = "yearheader", string.format("%s", date.year) local flag, text = "yearheader", string.format("%s", date.year)
local year_header = props.fn_embed(make_cell(text, props.font, true), flag, date) local year_header = props.fn_embed(make_cell(text, props.font, true), flag, date)
local out_layout = base.make_widget_declarative{ local out_layout = vertical()
year_header, out_layout:set_spacing(2*props.spacing) -- separate header from calendar grid
in_layout, out_layout:add(year_header)
spacing = 2*props.spacing, -- separate header from calendar grid out_layout:add(in_layout)
layout = vertical
}
return props.fn_embed(out_layout, "year", date) return props.fn_embed(out_layout, "year", date)
end end