Skip to main content

Timeline

Struct Timeline 

Source
pub struct Timeline<Msg> { /* private fields */ }
Expand description

A day as a strip: blocks of colour for what filled it, the empty track for the gaps between them — breaks, sleep, time not recorded.

The day is 24 hours from day_starts_at, midnight by default. Blocks are placed on it by time: a block covers the cells its stretch falls in, and a block shorter than a cell still takes one cell, so a two-minute task is never lost on a whole-day strip. Blocks without a tone take the accent; two blocks of the same tone that touch are told apart by a quieter first cell on the later one, a seam of tone rather than a line. A block wide enough for its name with a cell of air on each side writes the name inside itself.

Overlapping blocks stand in lanes: each block takes the first lane, from the top, in which nothing overlaps it, so a strip is one row tall for a day of consecutive blocks and grows a row for each block that runs at the same time as another. An area shorter than the lanes puts the lanes that do not fit into its last row, where the later block is drawn over the earlier and the selected block is always drawn on top.

Midnight. A day that starts at 18:00 runs to 18:00 the next day, so a block from 23:00 to 01:30 is one block in it. In a day that starts at midnight the same block is cut at the end of the day; its part after midnight belongs to the next day’s strip, where the caller gives it from 00:00. A range is placed in the same day, so a night from 22:00 to 06:00 is a range of a day that starts before 22:00.

Zoom is the visible range, which the caller owns: range shows a stretch of the day across the whole width, and with on_zoom the timeline asks for a new one — + and - step through a day, 12, 6 and 3 hours and one hour around the selected block, 0 goes back to the whole day, and the mouse wheel zooms around the pointer once the timeline holds the focus (a click gives it), so scrolling a page past a timeline never gets caught in it. Selecting a block outside a zoomed range moves the range to it.

A timeline is a picture until it is given on_select. Then the block under the pointer and the selected block step towards the text colour, ←/→ (or h/l) walk the blocks in time order, Home and End go to the first and the last, and a click selects the block under it. readout adds a row that writes the block being read — the one under the pointer, else the selected one — as its name, its times and its length, so the pointer and the keyboard read the same words. Nothing moves or resizes when a block is hovered or selected: a timeline is a narrow strip, not a list, so it never slides.

Open edges and faint blocks. A block marked open_end or open_start fades towards the track over its last or first two cells, a tone transition rather than a glyph, and the readout writes what the open edge means. A faint block stands halfway between its tone and the track. On a terminal with few colours every fading cell and every faint tone is kept apart from the track, so a block never looks shorter than it is.

axis adds a row of hours under the strip, an Axis placed with the same arithmetic as the blocks. An area too short for every row gives up the axis first, then the readout, then lanes. The strip is made of colour, so it reads the same in every glyph mode; on a terminal with few colours a tone that would merge with the track or with its own hovered step is pushed further until the two differ.

Style keys: timeline (track for the empty day, fill for a block without a tone, hover and selected for the tones a block steps towards), timeline:focus (selected while the keyboard is on the timeline), timeline-readout (fg for the name, detail for the times and the length), and axis for the hours.

Implementations§

Source§

impl<Msg: 'static> Timeline<Msg>

Source

pub fn new(blocks: impl IntoIterator<Item = TimeBlock>) -> Self

A whole-day timeline of blocks, a day that starts at midnight.

Source

pub fn day_starts_at(self, time: TimeOfDay) -> Self

Starts the day at time instead of midnight, e.g. 18:00 for a night shift, so blocks across midnight stay whole.

Source

pub fn range(self, from: TimeOfDay, to: TimeOfDay) -> Self

Shows only the stretch from from to to across the whole width: into the next day when to is not after from, the whole day when the two are the same. The range is kept inside the day, so a range that runs past the day’s end stops there.

Source

pub fn axis(self) -> Self

Adds a row of hours under the strip.

Source

pub fn readout(self) -> Self

Adds a row that writes the block being read: its name, its times and its length.

Source

pub fn selected(self, index: Option<usize>) -> Self

The selected block, as an index into the blocks given.

Source

pub fn disabled(self, disabled: bool) -> Self

Greys the timeline out: it cannot be focused, hovered, selected or zoomed.

Source

pub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self

Message for moving the selection to a block, carrying its index into the blocks given; turns the pointer and keyboard handling on.

Source

pub fn on_zoom( self, message: impl Fn(TimeOfDay, TimeOfDay) -> Msg + 'static, ) -> Self

Message asking for a new visible range, from and to in the sense of range; turns zooming on.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for Timeline<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Timeline<Msg>

§

impl<Msg> !Send for Timeline<Msg>

§

impl<Msg> !Sync for Timeline<Msg>

§

impl<Msg> !UnwindSafe for Timeline<Msg>

§

impl<Msg> Freeze for Timeline<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Freeze, Option<Box<dyn Fn(TimeOfDay, TimeOfDay) -> Msg>>: Freeze,

§

impl<Msg> Unpin for Timeline<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Unpin, Option<Box<dyn Fn(TimeOfDay, TimeOfDay) -> Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for Timeline<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: UnsafeUnpin, Option<Box<dyn Fn(TimeOfDay, TimeOfDay) -> Msg>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.