ENH use new text api

This commit is contained in:
Nathan Dwarshuis 2021-07-18 21:10:59 -04:00
parent be63d5b13b
commit 5102b41e7b
2 changed files with 22 additions and 21 deletions

2
core

@ -1 +1 @@
Subproject commit 3fff6b06be21330a2b42c61c273ea2bd9bf782b0 Subproject commit 7047ffe126f5866720d4932bcf538e9f72b4a02d

View File

@ -9,6 +9,7 @@ local FillRect = require 'FillRect'
local CompoundDial = require 'CompoundDial' local CompoundDial = require 'CompoundDial'
local Arc = require 'Arc' local Arc = require 'Arc'
local Text = require 'Text' local Text = require 'Text'
local Table = require 'Table'
local CompoundBar = require 'CompoundBar' local CompoundBar = require 'CompoundBar'
local CriticalText = require 'CriticalText' local CriticalText = require 'CriticalText'
local TextColumn = require 'TextColumn' local TextColumn = require 'TextColumn'
@ -64,7 +65,7 @@ M.normal_font_spec = M.make_font_spec(FONT, NORMAL_FONT_SIZE, false)
M.label_font_spec = M.make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false) M.label_font_spec = M.make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false)
local _text_row_style = function(x_align, color) local _text_row_style = function(x_align, color)
return Startup.text_style(M.normal_font_spec, color, x_align, 'center') return Text.style(M.normal_font_spec, color, x_align, 'center')
end end
M.left_text_style = _text_row_style('left', Theme.INACTIVE_TEXT_FG) M.left_text_style = _text_row_style('left', Theme.INACTIVE_TEXT_FG)
@ -72,7 +73,7 @@ M.left_text_style = _text_row_style('left', Theme.INACTIVE_TEXT_FG)
M.right_text_style = _text_row_style('right', Theme.PRIMARY_FG) M.right_text_style = _text_row_style('right', Theme.PRIMARY_FG)
local _bare_text = function(pt, text, style) local _bare_text = function(pt, text, style)
return Startup.plainText(pt, text, style) return Text.build_plain(pt, text, style)
end end
local _left_text = function(pt, text) local _left_text = function(pt, text)
@ -90,10 +91,10 @@ M.Header = function(x, y, w, s)
local bottom_y = y + HEADER_HEIGHT local bottom_y = y + HEADER_HEIGHT
local underline_y = y + HEADER_UNDERLINE_OFFSET local underline_y = y + HEADER_UNDERLINE_OFFSET
return { return {
text = Startup.plainText( text = Text.build_plain(
Startup.make_point(x, y), Startup.make_point(x, y),
s, s,
Startup.text_style( Text.style(
M.make_font_spec(FONT, HEADER_FONT_SIZE, true), M.make_font_spec(FONT, HEADER_FONT_SIZE, true),
Theme.HEADER_FG, Theme.HEADER_FG,
'left', 'left',
@ -156,12 +157,12 @@ end
M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, update_freq, format) M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, update_freq, format)
return { return {
label = _left_text(Startup.make_point(x, y), label), label = _left_text(Startup.make_point(x, y), label),
value = Startup.formattedThresholdText( value = CriticalText.build_formatted(
Startup.make_point(x + w, y), Startup.make_point(x + w, y),
nil, nil,
M.right_text_style, M.right_text_style,
format, format,
Startup.threshold_text_style(Theme.CRITICAL_FG, 80) CriticalText.style(Theme.CRITICAL_FG, 80)
), ),
plot = M.initThemedLabelPlot( plot = M.initThemedLabelPlot(
x, x,
@ -257,7 +258,7 @@ M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing,
label, min_domain, update_freq) label, min_domain, update_freq)
return { return {
label = _left_text(Startup.make_point(x, y), label), label = _left_text(Startup.make_point(x, y), label),
value = Startup.formatted_text( value = Text.build_formatted(
Startup.make_point(x + w, y), Startup.make_point(x + w, y),
0, 0,
M.right_text_style, M.right_text_style,
@ -310,17 +311,17 @@ end
M.initTextRing = function(x, y, r, fmt, limit) M.initTextRing = function(x, y, r, fmt, limit)
return { return {
ring = M.initRing(x, y, r), ring = M.initRing(x, y, r),
value = Startup.formattedThresholdText( value = CriticalText.build_formatted(
Startup.make_point(x, y), Startup.make_point(x, y),
nil, nil,
Startup.text_style( Text.style(
M.normal_font_spec, M.normal_font_spec,
Theme.PRIMARY_FG, Theme.PRIMARY_FG,
'center', 'center',
'center' 'center'
), ),
fmt, fmt,
Startup.threshold_text_style(Theme.CRITICAL_FG, limit) CriticalText.style(Theme.CRITICAL_FG, limit)
), ),
} }
end end
@ -375,7 +376,7 @@ end
M.compound_bar = function(x, y, w, pad, labels, spacing, thickness, threshold) M.compound_bar = function(x, y, w, pad, labels, spacing, thickness, threshold)
return { return {
labels = Startup.TextColumn( labels = TextColumn.build(
Startup.make_point(x, y), Startup.make_point(x, y),
labels, labels,
M.left_text_style, M.left_text_style,
@ -454,17 +455,17 @@ end
M.initTextRowCrit = function(x, y, w, label, append_end, limit) M.initTextRowCrit = function(x, y, w, label, append_end, limit)
return{ return{
label = _left_text(Startup.make_point(x, y), label), label = _left_text(Startup.make_point(x, y), label),
value = Startup.formattedThresholdText( value = CriticalText.build_formatted(
Startup.make_point(x + w, y), Startup.make_point(x + w, y),
nil, nil,
Startup.text_style( Text.style(
M.normal_font_spec, M.normal_font_spec,
Theme.PRIMARY_FG, Theme.PRIMARY_FG,
'right', 'right',
'center' 'center'
), ),
append_end, append_end,
Startup.threshold_text_style(Theme.CRITICAL_FG, limit) CriticalText.style(Theme.CRITICAL_FG, limit)
) )
} }
end end
@ -497,14 +498,14 @@ end
M.initTextRows_color = function(x, y, w, spacing, labels, color, format) M.initTextRows_color = function(x, y, w, spacing, labels, color, format)
return { return {
labels = Startup.TextColumn( labels = TextColumn.build(
Startup.make_point(x, y), Startup.make_point(x, y),
labels, labels,
M.left_text_style, M.left_text_style,
nil, nil,
spacing spacing
), ),
values = Startup.initTextColumnN( values = TextColumn.build_n(
Startup.make_point(x + w, y), Startup.make_point(x + w, y),
#labels, #labels,
_text_row_style('right', color), _text_row_style('right', color),
@ -554,7 +555,7 @@ end
M.default_table_font_spec = M.make_font_spec(FONT, TABLE_FONT_SIZE, false) M.default_table_font_spec = M.make_font_spec(FONT, TABLE_FONT_SIZE, false)
M.default_table_style = Startup.table_style( M.default_table_style = Table.style(
Rect.style( Rect.style(
TABLE_LINE_THICKNESS, TABLE_LINE_THICKNESS,
Theme.BORDER_FG Theme.BORDER_FG
@ -564,12 +565,12 @@ M.default_table_style = Startup.table_style(
Theme.BORDER_FG, Theme.BORDER_FG,
CAIRO_LINE_CAP_BUTT CAIRO_LINE_CAP_BUTT
), ),
Startup.table_header_style( Table.header_style(
M.default_table_font_spec, M.default_table_font_spec,
Theme.PRIMARY_FG, Theme.PRIMARY_FG,
TABLE_HEADER_PAD TABLE_HEADER_PAD
), ),
Startup.table_body_style( Table.body_style(
M.default_table_font_spec, M.default_table_font_spec,
Theme.INACTIVE_TEXT_FG, Theme.INACTIVE_TEXT_FG,
TABLE_BODY_FORMAT TABLE_BODY_FORMAT
@ -583,7 +584,7 @@ M.default_table_style = Startup.table_style(
) )
M.initTable = function(x, y, w, h, n, labels) M.initTable = function(x, y, w, h, n, labels)
return Startup.Table( return Table.build(
Startup.make_box(x, y, w, h), Startup.make_box(x, y, w, h),
n, n,
labels, labels,