REF use common text types

This commit is contained in:
Nathan Dwarshuis 2021-07-10 17:13:17 -04:00
parent 95d7abbd9e
commit e2f622fd22
4 changed files with 112 additions and 106 deletions

2
core

@ -1 +1 @@
Subproject commit 74aa89b9f069b46559b8652d7627dfc4b34efd58 Subproject commit a2c1c089c9933b191c5ef4fd1569b3ede80acdd3

View File

@ -17,18 +17,6 @@ local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND
local HEADER_UNDERLINE_OFFSET = -20 local HEADER_UNDERLINE_OFFSET = -20
local HEADER_UNDERLINE_THICKNESS = 3 local HEADER_UNDERLINE_THICKNESS = 3
local _bare_text = function(pt, text, font_spec, pattern, x_align)
return _G_Widget_.Text(pt, text, font_spec, pattern, x_align, 'center', nil, nil)
end
local _left_text = function(pt, text, font_spec, pattern)
return _bare_text(pt, text, font_spec, pattern, 'left')
end
local _right_text = function(pt, text, font_spec, pattern)
return _bare_text(pt, text, font_spec, pattern, 'right')
end
M.make_font_spec = function(f, s, bold) M.make_font_spec = function(f, s, bold)
return { return {
family = f, family = f,
@ -41,6 +29,33 @@ end
M.normal_font_spec = M.make_font_spec(_G_Patterns_.FONT, 13, false) M.normal_font_spec = M.make_font_spec(_G_Patterns_.FONT, 13, false)
M.label_font_spec = M.make_font_spec(_G_Patterns_.FONT, 8, false) M.label_font_spec = M.make_font_spec(_G_Patterns_.FONT, 8, false)
M.left_text_style = _G_Widget_.text_style(
M.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG,
'left',
'center'
)
M.right_text_style = _G_Widget_.text_style(
M.normal_font_spec,
_G_Patterns_.PRIMARY_FG,
'right',
'center'
)
local _bare_text = function(pt, text, style)
local fmt = _G_Widget_.text_format(false, false, false)
return _G_Widget_.Text(pt, text, style, fmt)
end
local _left_text = function(pt, text)
return _bare_text(pt, text, M.left_text_style)
end
local _right_text = function(pt, text)
return _bare_text(pt, text, M.right_text_style)
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- header -- header
@ -65,12 +80,13 @@ M.Header = function(x, y, w, s)
text = _G_Widget_.Text( text = _G_Widget_.Text(
_G_Widget_.make_point(x, y), _G_Widget_.make_point(x, y),
s, s,
_G_Widget_.text_style(
M.make_font_spec(_G_Patterns_.FONT, HEADER_FONT_SIZE, true), M.make_font_spec(_G_Patterns_.FONT, HEADER_FONT_SIZE, true),
_G_Patterns_.HEADER_FG, _G_Patterns_.HEADER_FG,
'left', 'left',
'top', 'top'
nil, ),
nil _G_Widget_.text_format(false, false, false)
), ),
bottom_y = bottom_y, bottom_y = bottom_y,
-- underline = _G_Widget_.Line{ -- underline = _G_Widget_.Line{
@ -128,23 +144,23 @@ M.initPercentPlot = function(x, y, w, h, spacing, label)
-- text_color = _G_Patterns_.INACTIVE_TEXT_FG, -- text_color = _G_Patterns_.INACTIVE_TEXT_FG,
-- font_spec = M.normal_font_spec, -- font_spec = M.normal_font_spec,
-- }, -- },
label = _left_text( label = _left_text(_G_Widget_.make_point(x, y), label),
_G_Widget_.make_point(x, y),
label,
M.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG
),
value = _G_Widget_.CriticalText( value = _G_Widget_.CriticalText(
_G_Widget_.make_point(x + w, y), _G_Widget_.make_point(x + w, y),
nil, nil,
_G_Widget_.text_style(
M.normal_font_spec, M.normal_font_spec,
_G_Patterns_.PRIMARY_FG, _G_Patterns_.PRIMARY_FG,
_G_Patterns_.CRITICAL_FG,
80,
'right', 'right',
'center', 'center'
nil, ),
'%' _G_Widget_.text_format(
false,
'%',
false
),
_G_Patterns_.CRITICAL_FG,
80
), ),
-- value = _G_Widget_.CriticalText{ -- value = _G_Widget_.CriticalText{
-- x = x + w, -- x = x + w,
@ -210,9 +226,7 @@ M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label)
-- }, -- },
label = _left_text( label = _left_text(
_G_Widget_.make_point(x, y), _G_Widget_.make_point(x, y),
label, label
M.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG
), ),
-- value = _G_Widget_.Text{ -- value = _G_Widget_.Text{
-- x = x + w, -- x = x + w,
@ -223,9 +237,7 @@ M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label)
-- }, -- },
value = _right_text( value = _right_text(
_G_Widget_.make_point(x + w, y), _G_Widget_.make_point(x + w, y),
label, label
M.normal_font_spec,
_G_Patterns_.PRIMARY_FG
), ),
plot = M.initThemedScalePlot(x, y + spacing, w, h, f), plot = M.initThemedScalePlot(x, y + spacing, w, h, f),
} }
@ -284,14 +296,19 @@ M.initTextRing = function(x, y, r, append_end, limit)
value = _G_Widget_.CriticalText( value = _G_Widget_.CriticalText(
_G_Widget_.make_point(x, y), _G_Widget_.make_point(x, y),
nil, nil,
_G_Widget_.text_style(
M.normal_font_spec, M.normal_font_spec,
_G_Patterns_.PRIMARY_FG, _G_Patterns_.PRIMARY_FG,
'center',
'center'
),
_G_Widget_.text_format(
false,
append_end,
false
),
_G_Patterns_.CRITICAL_FG, _G_Patterns_.CRITICAL_FG,
limit, limit
'center',
'center',
nil,
append_end
), ),
} }
end end
@ -342,9 +359,7 @@ M.initTextRow = function(x, y, w, label)
-- }, -- },
label = _left_text( label = _left_text(
_G_Widget_.make_point(x, y), _G_Widget_.make_point(x, y),
label, label
M.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG
), ),
-- value = _G_Widget_.Text{ -- value = _G_Widget_.Text{
-- x = x + w, -- x = x + w,
@ -356,9 +371,7 @@ M.initTextRow = function(x, y, w, label)
-- } -- }
value = _right_text( value = _right_text(
_G_Widget_.make_point(x + w, y), _G_Widget_.make_point(x + w, y),
nil, nil
M.normal_font_spec,
_G_Patterns_.PRIMARY_FG
), ),
} }
end end
@ -391,9 +404,7 @@ M.initTextRowCrit = function(x, y, w, label, append_end, limit)
-- }, -- },
label = _left_text( label = _left_text(
_G_Widget_.make_point(x, y), _G_Widget_.make_point(x, y),
label, label
M.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG
), ),
-- value = _G_Widget_.CriticalText{ -- value = _G_Widget_.CriticalText{
-- x = x + w, -- x = x + w,
@ -410,14 +421,19 @@ M.initTextRowCrit = function(x, y, w, label, append_end, limit)
value = _G_Widget_.CriticalText( value = _G_Widget_.CriticalText(
_G_Widget_.make_point(x + w, y), _G_Widget_.make_point(x + w, y),
nil, nil,
_G_Widget_.text_style(
M.normal_font_spec, M.normal_font_spec,
_G_Patterns_.PRIMARY_FG, _G_Patterns_.PRIMARY_FG,
_G_Patterns_.CRITICAL_FG,
limit,
'right', 'right',
'center', 'center'
nil, ),
append_end _G_Widget_.text_format(
false,
append_end,
false
),
_G_Patterns_.CRITICAL_FG,
limit
) )
} }
end end
@ -447,15 +463,10 @@ M.initTextRows = function(x, y, w, spacing, labels)
-- font_spec = M.normal_font_spec, -- font_spec = M.normal_font_spec,
-- table.unpack(labels), -- table.unpack(labels),
_G_Widget_.make_point(x, y), _G_Widget_.make_point(x, y),
spacing, labels,
nil, M.left_text_style,
M.normal_font_spec, _G_Widget_.text_format(false, false, false),
_G_Patterns_.INACTIVE_TEXT_FG, spacing
'left',
'center',
nil,
nil,
labels
), ),
-- values = _G_Widget_.TextColumn{ -- values = _G_Widget_.TextColumn{
-- x = x + w, -- x = x + w,
@ -469,15 +480,10 @@ M.initTextRows = function(x, y, w, spacing, labels)
-- } -- }
values = _G_Widget_.initTextColumnN( values = _G_Widget_.initTextColumnN(
_G_Widget_.make_point(x + w, y), _G_Widget_.make_point(x + w, y),
spacing, #labels,
nil, M.right_text_style,
M.normal_font_spec, _G_Widget_.text_format(false, false, false),
_G_Patterns_.PRIMARY_FG, spacing
'right',
'center',
nil,
nil,
#labels
) )
} }
end end

View File

@ -92,15 +92,15 @@ local labels = _G_Widget_.TextColumn(
_G_INIT_DATA_.RIGHT_X, _G_INIT_DATA_.RIGHT_X,
_BAR_Y_ _BAR_Y_
), ),
_SPACING_, {'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'},
nil, _G_Widget_.text_style(
Common.normal_font_spec, Common.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG, _G_Patterns_.INACTIVE_TEXT_FG,
'left', 'left',
'center', 'center'
nil, ),
nil, _G_Widget_.text_format(false, false, false),
{'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'} _SPACING_
) )
_SPACING_ = nil _SPACING_ = nil

View File

@ -136,30 +136,30 @@ local cache = {
_TEXT_LEFT_X_, _TEXT_LEFT_X_,
_LINE_1_Y_ + _TEXT_SPACING_ _LINE_1_Y_ + _TEXT_SPACING_
), ),
_TEXT_SPACING_, {'Page Cache', 'Buffers', 'Kernel Slab'},
nil, _G_Widget_.text_style(
Common.normal_font_spec, Common.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG, _G_Patterns_.INACTIVE_TEXT_FG,
'left', 'left',
'center', 'center'
nil, ),
nil, _G_Widget_.text_format(false, false, false),
{'Page Cache', 'Buffers', 'Kernel Slab'} _TEXT_SPACING_
), ),
percents = _G_Widget_.initTextColumnN( percents = _G_Widget_.initTextColumnN(
_G_Widget_.make_point( _G_Widget_.make_point(
_RIGHT_X_, _RIGHT_X_,
_LINE_1_Y_ + _TEXT_SPACING_ _LINE_1_Y_ + _TEXT_SPACING_
), ),
_TEXT_SPACING_, 3,
nil, _G_Widget_.text_style(
Common.normal_font_spec, Common.normal_font_spec,
_G_Patterns_.SECONDARY_FG, _G_Patterns_.SECONDARY_FG,
'right', 'right',
'center', 'center'
nil, ),
' %', _G_Widget_.text_format(false, '%', false),
3 _TEXT_SPACING_
), ),
} }