calendar only.Expand description
A calendar of entries with day, week, month, year, schedule and four-day views, and triggers that tell the app when an entry is created, is due or is about to be.
The header has a Today button, arrows, the period in words and a menu
of the Views. Day, week and four days put days side by side
against the hours; the month is a grid of weeks with whole-day entries
as bars and timed ones as a dot, a time and a title; the year is
twelve small months; and the schedule lists the month’s entries with
each day’s date beside them.
State holds the Entries, the View, the period on show and
the selection. Its update applies an Event and
returns an Output for the things an app acts on: an entry was
opened, a new one was asked for, an entry changed, another period came
on show. The calendar never reads the clock; today’s date and the
current time are passed in.
use iced::Element;
use iced_cube::data::calendar::{self, Entry, EntryId, Output, calendar};
use jiff::Timestamp;
#[derive(Debug, Clone)]
enum Message {
Calendar(calendar::Event),
}
struct App {
calendar: calendar::State,
}
impl App {
fn new(now: Timestamp) -> Self {
Self {
calendar: calendar::State::at(now, calendar::Entries::system()),
}
}
fn update(&mut self, message: Message) {
let Message::Calendar(event) = message;
match self.calendar.update(event) {
// The user pressed a day twice or dragged out a time.
Some(Output::Requested(draft)) => {
let id = self.calendar.entries().next_id();
let entry = Entry::at(id, "New entry", draft.when);
let _ = self.calendar.update(calendar::Event::Insert(entry));
}
Some(Output::Opened { entry, .. }) => println!("open {entry:?}"),
_ => {}
}
}
fn view(&self) -> Element<'_, Message> {
calendar(&self.calendar).on_event(Message::Calendar).into()
}
}§Entries
An Entry is timed, from one instant up to another, or covers whole
days. It can repeat daily, weekly, monthly or yearly. Timed
entries are stored as instants and shown in the time zone of the
Entries collection, so changing the time zone moves what is drawn
and not what is stored.
§Selecting and activating
The first press on a day, a time slot or an entry selects it. A press on what is already selected activates it: an entry is opened, and a day or a slot asks for a new entry there. Two quick presses therefore open or create, and so do two taps on a touch screen. In the week and day views a drag on empty space asks for an entry of that length, a drag on an entry moves it, and a drag on its top or lower edge changes when it starts or ends.
The calendar only asks; the app decides what to show. editor is a
ready-made form for that: title, all day, start and end date and time,
how often it repeats and when that stops, colour, location and notes.
§Triggers
See schedule for telling the app when entries are created, due or
almost due, including the ones missed while the app was not running.
§Keyboard
Shortcuts resolve through a Keymap of
Actions; see default_keymap and crate::keys.
Re-exports§
pub use entry::Change;pub use entry::Changed;pub use entry::Draft;pub use entry::Emphasis;pub use entry::Entries;pub use entry::Entry;pub use entry::EntryId;pub use entry::Occurrence;pub use entry::Paint;pub use entry::Tone;pub use entry::When;pub use entry::instant;pub use repeat::Ends;pub use repeat::Frequency;pub use repeat::Repeat;pub use jiff;
Modules§
- editor
- A form for creating or changing an entry: its title, whether it lasts all day, when it starts and ends, how it repeats and when the repeats stop, its colour, where it is and any notes.
- entry
- Calendar entries and the collection that holds them.
- layout
- Where things go: the weeks of a month, the lanes of bars across days and the side by side columns of overlapping entries in a day.
- repeat
- Repeating entries: how often, and expanding them into occurrences.
- rules
- The calendar’s date rules, with no GUI dependency: when something
happens (
When), how it repeats (Repeat), and the occurrences of a repeating span in a range of time (occurrences). - schedule
- Triggers: telling the app when something happens to an entry.
- style
- Colours of the calendar’s parts, resolved from the theme’s tokens.
Structs§
- Allow
- What the user may change through the calendar’s own gestures and shortcuts. Everything is allowed by default.
- Calendar
- A calendar builder. Convert it into an
Elementto render. - State
- The entries, the view, the period on show and the selection.
Enums§
- Action
- What a calendar keyboard shortcut does.
- Event
- Everything that changes the calendar.
- Output
- What the app may want to act on after an
Event. - Selection
- What is selected: at most one thing at a time.
- View
- How the entries are laid out.
Constants§
- DEFAULT_
HOUR_ HEIGHT - The height of an hour in the week and day views unless set.
- DOUBLE_
CLICK - How long after one press a second still makes a double click, unless the state sets another interval.
- FOUR_
DAYS - How many days
View::FourDaysshows. - GUTTER
- The width of the hour labels.
- HEADER_
BREAK - The width below which the header puts the navigation buttons on a second line.
- MIN_
HOUR_ HEIGHT - The least an hour can be set to in the week and day views.
- SLOT_
MINUTES - How long an entry asked for by pressing a time slot is.
- SNAP_
MINUTES - The step drags snap to, in minutes.
- VIEW_
MENU_ WIDTH - The width of the menu of views in the header.
Functions§
- bar_
label - What a bar says: the title, after the start time for a timed entry that begins on the bar’s first day.
- calendar
- Renders
state. Withouton_eventit renders disabled: nothing can be pressed or dragged. - day_id
- The id of a day’s cell in the month, or its heading over the hours, for finding it in tests and for drags that end on it.
- default_
keymap - The default calendar shortcuts:
- entry_
id - The id of an occurrence’s chip, bar or block in every view, for finding exactly one entry in tests and for operations on it.
- hour_
offset - How far down the hours
houris when the first hour on show isfirst_hourand each ishour_heighttall. - hours_
id - The id of the hours of the week and day views, whose bounds
point_atmeasures from. - is_line
- Whether a bar is a timed entry that starts and ends within one day, which the month shows as a dot, a time and a title with no fill.
- next_
button_ id - The id of the header’s button to the next period.
- point_
at - The point on screen of
minutepast midnight on thedayth column of hours, when the hours found byhours_idhaveboundsand showdayscolumns fromfirst_hour, each hourhour_heighttall. For driving a drag in a test without working out the layout by hand. The point is in the middle of the column. - previous_
button_ id - The id of the header’s button to the previous period.
- scroll_
id - The id of the scrollable around the hours, for scrolling to a time of day with iced’s scrollable operations.
- scroll_
to_ hour - Scrolls the week or day view so
houris at the top, such as to the start of the working day when the calendar opens. Pass the hour height the calendar was given, which isDEFAULT_HOUR_HEIGHTunless set, and run the task once the view is on screen. - span_
label - When an occurrence happens within its day: “All day”, or its start and end times.
- time_
label - A time of day, such as “09:30”.
- today_
button_ id - The id of the header’s Today button.
- view_
menu_ id - The id of the header’s menu of views.
- weekday_
label - A day’s short name in capitals, such as “MON”, or its first letter
when
narrow. - when_
label - When a span is, in words, for a dialog or a list: “Thu 19 Nov, 10:00 - 11:30” for a time on one day, and the first and last day otherwise.