pub struct Window {
pub from: usize,
pub count: usize,
pub of: Option<usize>,
}Expand description
A window onto a sequence: where it starts, how much it covers, and how long the sequence is when that is known.
The mechanism under two things the vocabulary deliberately keeps apart. A
carousel is a window of one frame over children that are all present; a
paged list is a window of a page over rows most of which were never fetched.
Those are different facts and they stay different types — Showing says
which child is up, Paging says where a reader is in a query — but the
arithmetic underneath is one piece of code, so a terminal and a browser
cannot come to disagree about which frame is last.
§Why of is optional and count is not
count is what is on screen and is therefore always known. of is the
length of the thing being windowed, and a host that cannot count says so by
leaving it empty for the life of the screen. It is never “not counted
yet”: see “First paint is final paint” in the crate header. A total that
turns up on a later pass widens the text that prints it.
§Clamping
Every derivation clamps rather than refusing, and a zero count answers
None rather than dividing. A window past the end is a bug in the host, and
a renderer that answered it by drawing nothing would report a region that
vanished, which is the hardest kind of bug to find from what is on screen.
Share::percent clamps for the same reason.
Fields§
§from: usizeThe index into the sequence where the window starts.
count: usizeHow many the window covers. One, for a carousel.
of: Option<usize>How long the sequence is, when the host can say.
Implementations§
Source§impl Window
impl Window
Sourcepub const fn new(from: usize, count: usize) -> Self
pub const fn new(from: usize, count: usize) -> Self
A window of count, starting at from, over a sequence of unknown
length.
Sourcepub const fn frame(at: usize, of: usize) -> Self
pub const fn frame(at: usize, of: usize) -> Self
One item of a sequence whose length is known. A carousel frame.
Sourcepub const fn index(self) -> Option<usize>
pub const fn index(self) -> Option<usize>
Which window this is, counting from zero.
None when count is zero, which is the only input with no answer
rather than a clamped one.
Sourcepub const fn windows(self) -> Option<usize>
pub const fn windows(self) -> Option<usize>
How many windows the sequence holds.
None unless both the length and a non-zero count are known. A
partial answer here would be a renderer drawing “of 0”.
Sourcepub const fn has_before(self) -> bool
pub const fn has_before(self) -> bool
Whether anything sits before this window.
Sourcepub const fn after(self) -> Option<usize>
pub const fn after(self) -> Option<usize>
How many sit after this window, when the length is known.
Here rather than in each renderer for Showing::selective’s reason:
three of them writing the same subtraction is how they come to disagree,
and this one has an underflow in it for whoever writes it fourth.