pub struct Meter<'a> {
pub done: u32,
pub total: u32,
pub tone: Tone,
pub label: Option<&'a str>,
}Expand description
How much of a set is done.
Added 0.10.0. Nine sites across the two webview apps drew a bar and nothing
here named one, so every described screen concatenated the two numbers into
its heading text instead: “Subtasks 3/7”, “Time Tracking 45m tracked / 30m
est, over”. Every fact survives that and the reading does not, which is the
same loss RowPart::Tokens closed when a toned status badge became prose.
§Why a pair and not a percentage
Both numbers, not the percentage the apps compute from them. The percentage
was the obvious shape and it had already been tried: goingson’s
Task::time_progress divides, rounds, and then clamps to 100, which throws
away the one case the bar exists to show — 45 minutes tracked against a
30-minute estimate. It carries a separate is_over_estimate boolean beside
it to recover the fact the clamp dropped. A pair keeps the over-run without a
companion flag, and percent is still one call away for a
renderer that wants it.
The pair is also what the apps already have at every site. All seven
determinate bars write the ratio into the accessible layer and never the
percentage: title="3/7 subtasks", aria-label="3 of 7 subtasks completed",
a milestone’s own 3/7 span. Given 43 nothing can recover “3 of 7”, so a
percentage member would have made label mandatory at every
call site, which is the concatenated text this member removes, moved one
layer down.
§What this is not
The progress of an operation. Two of the nine sites are that — goingson’s
focus timer, Balanced Breakfast’s feed fetch — and they get nothing here, on
purpose. Both are imperative controllers over a live handle, driven by a tick
or an event stream, and a description is built once and dropped. Holding one
would mean growing a way to update a description between renders, which is a
different feature. Readiness::Pending and a Notice::Toast carry the
honest part.
The two cases are distinguishable in the markup rather than by taste: every determinate bar in both apps carries a tone, and neither operation bar carries one. Two codebases drew that line the same way without coordinating.
Fields§
§done: u32How much is done. May exceed total, and that is the
case worth drawing.
total: u32How much there is to do. Zero means there is no set, not that the set is complete.
tone: ToneWhat the proportion means right now.
Carried rather than derived, because no renderer can work it out. The
same 90% is Tone::Success on a subtask rollup and Tone::Danger on
a time estimate, and goingson picks between them from is_over_estimate,
a fact about the data and not about the number.
label: Option<&'a str>What is being counted, if the bar says so: “subtasks”, “tasks”.
The noun, not the ratio. A renderer builds “3 of 7 subtasks” from this and the two numbers; handing it the assembled string would put the sentence order in the description, where a terminal at one line and a tooltip want different ones.
Implementations§
Source§impl<'a> Meter<'a>
impl<'a> Meter<'a>
Sourcepub const fn percent(&self) -> u8
pub const fn percent(&self) -> u8
How full the bar is, 0 to 100, clamped.
For drawing, which is the only thing a clamped number is good for. Ask
overflowing before reporting it as a fact, or this
is time_progress’s bug again with the clamp moved.
An empty set reads as 0. Nothing is done, because there is nothing to do and no bar to fill; the apps guard on the count before drawing at all.
Sourcepub const fn overflowing(&self) -> bool
pub const fn overflowing(&self) -> bool
Whether more is done than there was to do.
The fact percent destroys, kept reachable so a
renderer can mark the over-run rather than drawing a full bar and
implying it landed exactly.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Whether there is a set at all.
A meter over nothing is sayable on purpose, for the same reason a field with no options is: it is what an app with an unloaded count actually has, and a renderer that shows an empty bar says so on screen rather than dividing by zero.