From e2f622fd22b5f62a1b9ab689ec4323a316c43f2e Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sat, 10 Jul 2021 17:13:17 -0400 Subject: [PATCH] REF use common text types --- core | 2 +- drawing/Common.lua | 162 +++++++++++++++++++++-------------------- drawing/FileSystem.lua | 18 ++--- drawing/Memory.lua | 36 ++++----- 4 files changed, 112 insertions(+), 106 deletions(-) diff --git a/core b/core index 74aa89b..a2c1c08 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 74aa89b9f069b46559b8652d7627dfc4b34efd58 +Subproject commit a2c1c089c9933b191c5ef4fd1569b3ede80acdd3 diff --git a/drawing/Common.lua b/drawing/Common.lua index 6f79256..7b92ed4 100644 --- a/drawing/Common.lua +++ b/drawing/Common.lua @@ -17,18 +17,6 @@ local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND local HEADER_UNDERLINE_OFFSET = -20 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) return { family = f, @@ -41,6 +29,33 @@ end 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.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 @@ -65,12 +80,13 @@ M.Header = function(x, y, w, s) text = _G_Widget_.Text( _G_Widget_.make_point(x, y), s, - M.make_font_spec(_G_Patterns_.FONT, HEADER_FONT_SIZE, true), - _G_Patterns_.HEADER_FG, - 'left', - 'top', - nil, - nil + _G_Widget_.text_style( + M.make_font_spec(_G_Patterns_.FONT, HEADER_FONT_SIZE, true), + _G_Patterns_.HEADER_FG, + 'left', + 'top' + ), + _G_Widget_.text_format(false, false, false) ), bottom_y = bottom_y, -- underline = _G_Widget_.Line{ @@ -128,23 +144,23 @@ M.initPercentPlot = function(x, y, w, h, spacing, label) -- text_color = _G_Patterns_.INACTIVE_TEXT_FG, -- font_spec = M.normal_font_spec, -- }, - label = _left_text( - _G_Widget_.make_point(x, y), - label, - M.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG - ), + label = _left_text(_G_Widget_.make_point(x, y), label), value = _G_Widget_.CriticalText( _G_Widget_.make_point(x + w, y), nil, - M.normal_font_spec, - _G_Patterns_.PRIMARY_FG, + _G_Widget_.text_style( + M.normal_font_spec, + _G_Patterns_.PRIMARY_FG, + 'right', + 'center' + ), + _G_Widget_.text_format( + false, + '%', + false + ), _G_Patterns_.CRITICAL_FG, - 80, - 'right', - 'center', - nil, - '%' + 80 ), -- value = _G_Widget_.CriticalText{ -- x = x + w, @@ -210,9 +226,7 @@ M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label) -- }, label = _left_text( _G_Widget_.make_point(x, y), - label, - M.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG + label ), -- value = _G_Widget_.Text{ -- x = x + w, @@ -223,9 +237,7 @@ M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label) -- }, value = _right_text( _G_Widget_.make_point(x + w, y), - label, - M.normal_font_spec, - _G_Patterns_.PRIMARY_FG + label ), 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( _G_Widget_.make_point(x, y), nil, - M.normal_font_spec, - _G_Patterns_.PRIMARY_FG, + _G_Widget_.text_style( + M.normal_font_spec, + _G_Patterns_.PRIMARY_FG, + 'center', + 'center' + ), + _G_Widget_.text_format( + false, + append_end, + false + ), _G_Patterns_.CRITICAL_FG, - limit, - 'center', - 'center', - nil, - append_end + limit ), } end @@ -342,9 +359,7 @@ M.initTextRow = function(x, y, w, label) -- }, label = _left_text( _G_Widget_.make_point(x, y), - label, - M.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG + label ), -- value = _G_Widget_.Text{ -- x = x + w, @@ -356,9 +371,7 @@ M.initTextRow = function(x, y, w, label) -- } value = _right_text( _G_Widget_.make_point(x + w, y), - nil, - M.normal_font_spec, - _G_Patterns_.PRIMARY_FG + nil ), } end @@ -391,9 +404,7 @@ M.initTextRowCrit = function(x, y, w, label, append_end, limit) -- }, label = _left_text( _G_Widget_.make_point(x, y), - label, - M.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG + label ), -- value = _G_Widget_.CriticalText{ -- x = x + w, @@ -410,14 +421,19 @@ M.initTextRowCrit = function(x, y, w, label, append_end, limit) value = _G_Widget_.CriticalText( _G_Widget_.make_point(x + w, y), nil, - M.normal_font_spec, - _G_Patterns_.PRIMARY_FG, + _G_Widget_.text_style( + M.normal_font_spec, + _G_Patterns_.PRIMARY_FG, + 'right', + 'center' + ), + _G_Widget_.text_format( + false, + append_end, + false + ), _G_Patterns_.CRITICAL_FG, - limit, - 'right', - 'center', - nil, - append_end + limit ) } end @@ -447,15 +463,10 @@ M.initTextRows = function(x, y, w, spacing, labels) -- font_spec = M.normal_font_spec, -- table.unpack(labels), _G_Widget_.make_point(x, y), - spacing, - nil, - M.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG, - 'left', - 'center', - nil, - nil, - labels + labels, + M.left_text_style, + _G_Widget_.text_format(false, false, false), + spacing ), -- values = _G_Widget_.TextColumn{ -- x = x + w, @@ -469,15 +480,10 @@ M.initTextRows = function(x, y, w, spacing, labels) -- } values = _G_Widget_.initTextColumnN( _G_Widget_.make_point(x + w, y), - spacing, - nil, - M.normal_font_spec, - _G_Patterns_.PRIMARY_FG, - 'right', - 'center', - nil, - nil, - #labels + #labels, + M.right_text_style, + _G_Widget_.text_format(false, false, false), + spacing ) } end diff --git a/drawing/FileSystem.lua b/drawing/FileSystem.lua index 9489de6..f1d3ec0 100644 --- a/drawing/FileSystem.lua +++ b/drawing/FileSystem.lua @@ -92,15 +92,15 @@ local labels = _G_Widget_.TextColumn( _G_INIT_DATA_.RIGHT_X, _BAR_Y_ ), - _SPACING_, - nil, - Common.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG, - 'left', - 'center', - nil, - nil, - {'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'} + {'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'}, + _G_Widget_.text_style( + Common.normal_font_spec, + _G_Patterns_.INACTIVE_TEXT_FG, + 'left', + 'center' + ), + _G_Widget_.text_format(false, false, false), + _SPACING_ ) _SPACING_ = nil diff --git a/drawing/Memory.lua b/drawing/Memory.lua index 840d338..20e073b 100644 --- a/drawing/Memory.lua +++ b/drawing/Memory.lua @@ -136,30 +136,30 @@ local cache = { _TEXT_LEFT_X_, _LINE_1_Y_ + _TEXT_SPACING_ ), - _TEXT_SPACING_, - nil, - Common.normal_font_spec, - _G_Patterns_.INACTIVE_TEXT_FG, - 'left', - 'center', - nil, - nil, - {'Page Cache', 'Buffers', 'Kernel Slab'} + {'Page Cache', 'Buffers', 'Kernel Slab'}, + _G_Widget_.text_style( + Common.normal_font_spec, + _G_Patterns_.INACTIVE_TEXT_FG, + 'left', + 'center' + ), + _G_Widget_.text_format(false, false, false), + _TEXT_SPACING_ ), percents = _G_Widget_.initTextColumnN( _G_Widget_.make_point( _RIGHT_X_, _LINE_1_Y_ + _TEXT_SPACING_ ), - _TEXT_SPACING_, - nil, - Common.normal_font_spec, - _G_Patterns_.SECONDARY_FG, - 'right', - 'center', - nil, - ' %', - 3 + 3, + _G_Widget_.text_style( + Common.normal_font_spec, + _G_Patterns_.SECONDARY_FG, + 'right', + 'center' + ), + _G_Widget_.text_format(false, '%', false), + _TEXT_SPACING_ ), }