GtkCalendar

GtkCalendar

GtkCalendar is a GTK widget mirrored in XFrame in the “Display” section, built from the Container archetype (kind “Calendar”). A container: it holds and lays out child widgets (boxes, frames, notebooks, panes, dialogs' pages). Most containers draw only their frame and children.

Category: XFrame   Family: Gtk   Section: Display   Archetype: Container   Kind: Calendar   Default size: 260×200

GtkCalendar running under Xvfb
GtkCalendar running in an 800×600 window under Xvfb.

Properties

PropertyTypeDefaultRust setter
backgroundColor—set_style_name
foregroundColor—set_style_name
tooltip-textStr——
visibleBooltrueset_visible
enabledBooltrueset_enabled

“—” in the setter column means the Rust widget code has no setter for that property: it is set in the designer (Inspector) and carried in the saved design, not changed from Rust code.

Container archetype settings (Rust)

Settings on the shared Container struct in crates/xframe-widgets/src/archetypes.rs. One struct serves every kind of the archetype, so only the settings matching this kind apply to it (a calendar uses set_date, a notebook uses the tab settings, a grid uses the grid settings). “—” as a default means the data gives no Inspector default for that setting.

PropertyTypeDefaultRust setter
active-pageInt—set_active_page
label-xalignDouble—set_label_xalign
insetInt—set_inset
top-insetInt—set_top_inset
show-week-numbersBool—set_show_week_numbers
date(Int, Int, Int)—set_date
grid-colorColor—set_grid_color
selected-fill-colorColor—set_selected_fill_color
selected-text-colorColor—set_selected_text_color
today-colorColor—set_today_color
dim-text-colorColor—set_dim_text_color
weekends-colorColor—set_weekends_color
disabled-colorColor—set_disabled_color
tab-heightInt—set_tab_height
tab-positionInt—set_tab_position
tab-widthInt—set_tab_width
positionInt—set_position
min-sizeInt—set_min_size
resize-styleInt—set_resize_style
auto-snapBool—set_auto_snap
orientationInt—set_orientation
size-gripBool—set_size_grip
itemsList<Str>—set_items
headers-visibleBool—set_headers_visible
frozen-colsInt—set_frozen_cols
frozen-rowsInt—set_frozen_rows
default-col-widthInt—set_default_col_width
default-row-heightInt—set_default_row_height
grid-line-widthInt—set_grid_line_width
grid-size(Int, Int)—set_grid_size
header-heightInt—set_header_height

Working example

Minimal complete Rust program — this is the file examples/GtkCalendar.rs in lightgui_rust. Run it with:

cargo run -p xframe-demo --example GtkCalendar
//! GtkCalendar — minimal complete XFrame example.
//!
//! Run it from the workspace root:
//!     cargo run -p xframe-demo --example GtkCalendar
//! It opens an 800x600 window showing one GtkCalendar widget (press Esc
//! or `q`, or close the window, to quit). The widget is the real
//! `xframe-widgets` implementation for this registry kind, created by
//! `xframe_widgets::create("GtkCalendar")` inside `xframe_demo::run_widget`
//! — the same code path the `xframe-demo` binary uses.

use std::process::ExitCode;

fn main() -> ExitCode {
    match xframe_demo::run_widget("GtkCalendar", false, None, None) {
        Ok(code) => ExitCode::from(code as u8),
        Err(e) => {
            eprintln!("GtkCalendar example: {}", e);
            ExitCode::from(1)
        }
    }
}

Event handling

Every XFrame widget dispatches the same four input events through the Widget trait: button press, button release, pointer motion, and key press. The generated event loop routes a release to the widget that got the press (even if the pointer moved off it), motion to the pressed widget while dragging and otherwise to the topmost widget under the pointer, and keys only to the focused widget. A press that starts and ends inside an enabled widget fires its click handler (on_click); Return or Space fires it when the widget is focused.

SignalHandlerWhat it meansKind
switch-pageon_switch_pagePage switchedSwitchPage

No signal table exists for this exact kind in the event data; the signals above are those of its archetype.

Connect switch-page in the designer; the generated program wires each signal to a stub handler (on_<signal>) you fill in.

Calendar: date changes

The selected date lives in the widget as a (year, month, day) triple. Set it programmatically with set_date(y, m, d) — for example widget.set_date(2026, 12, 25). Clicking a day in the drawn month changes the selection; the widget redraws with the new day highlighted (selected fill) and today marked in its own colour. set_show_week_numbers(true) adds ISO week numbers in the gutter. The calendar colours (grid, selected fill/text, today, dim days, weekends, disabled) are fields on the container widget — set them before the first draw.

Font and labels

Change the displayed text at any time with set_text("...") — the widget redraws with the new label. The font comes from the active style: styles are registered on the StyleManager with add_style_ex(name, fill, outline, text, line, radius, line_width, font), and a widget switches style with set_style_name("dark"). So a font change is a style change: register a style with the font you want and apply it by name.

Styling: colours, border radius, line width, line colour

Styling is per-style, not per-widget: a Style carries fill_color, outline_color, line_color, text_color, radius (border radius), line_width, and font_name. Register a style with add_style_ex (argument order: fill, outline, text, line, radius, line width, font) and apply it with set_style_name("name") on any widget — the same widget can be square or rounded, thin- or thick-lined, just by switching style. The demo's default style uses radius 6 and line width 1; dark is the dark variant.


All Rust widgets · lightgui_rust on GitHub

Read more