Thanks to visit codestin.com
Credit goes to lib.rs

#desktop #gui-widgets #windows #canvas #widgets

widgetkit

Modular Rust framework for building desktop widgets

4 releases (2 breaking)

Uses new Rust 2024

0.3.0 Apr 27, 2026
0.2.1 Apr 12, 2026
0.2.0 Apr 10, 2026
0.1.0 Apr 4, 2026

#795 in GUI

MIT license

60KB
1K SLoC

WidgetKit


language: English, Russian


Version Platform Renderer Status

Modular Rust library for building small desktop widgets.

Current scope: software 2D rendering on Windows with window configuration, content-driven sizing, and layout measurement foundations behind the public Canvas API.

Core assembly: Widget + Canvas + WindowsHost + WidgetApp.

For the full release history, see CHANGELOG.md.

Overview

  • Canvas — stable drawing API
  • demand-driven redraw and layout invalidation
  • WindowConfig and Windows host flags for frameless, transparent, resizable, visible, and always-on-top windows
  • SizePolicy with fixed and content-driven sizing
  • LayoutCtx::measure_text(...) for preferred-size calculations
  • software 2D renderer backed by an internal render pipeline

Quick Start

use widgetkit::prelude::*;

fn main() -> widgetkit::Result<()> {
    WidgetApp::new()
        .widget("clock", ClockWidget)
        .host(
            WindowsHost::new()
                .size_policy(SizePolicy::ContentWithLimits {
                    min: Some(Size::new(280.0, 112.0)),
                    max: Some(Size::new(520.0, 180.0)),
                })
                .frameless(true)
                .transparent(true)
                .always_on_top(true),
        )
        .renderer(SoftwareRenderer::new())
        .run()
}

Example Widget

use widgetkit::prelude::*;

struct MyWidget;

struct MyState {
    label: String,
}

impl Widget for MyWidget {
    type State = MyState;
    type Message = ();

    fn mount(&mut self, _ctx: &mut MountCtx<Self>) -> Self::State {
        MyState {
            label: "Hello WidgetKit".to_string(),
        }
    }

    fn preferred_size(&self, state: &Self::State, ctx: &LayoutCtx<Self>) -> Size {
        let label = ctx.measure_text(&state.label, TextStyle::new().size(16.0));
        ctx.constrain(Size::new(label.width + 48.0, label.height + 48.0))
    }

    fn render(&self, state: &Self::State, canvas: &mut Canvas, ctx: &RenderCtx<Self>) {
        let size = ctx.surface_size();

        canvas.clear(Color::rgba(0, 0, 0, 0));
        canvas.round_rect(
            Rect::xywh(8.0, 8.0, size.width - 16.0, size.height - 16.0),
            16.0,
            Color::rgb(30, 36, 48),
        );
        canvas.text(
            Point::new(24.0, 28.0),
            &state.label,
            TextStyle::new().size(16.0),
            Color::rgb(127, 160, 255),
        );
    }
}

Examples

cargo run --example clock --features "windows canvas"
cargo run --example pulse --features "windows canvas"

With the Tokio-backed task runtime:

cargo run --example clock --features "windows canvas runtime-tokio"

Features

  • canvas
  • windows
  • runtime-tokio
[dependencies]
widgetkit = { version = "0.3.0", default-features = false, features = ["windows", "canvas"] }

Workspace Layout

widgetkit/
  crates/
    widgetkit
    widgetkit-core
    widgetkit-runtime
    widgetkit-render
    widgetkit-host-windows
  • widgetkit - top-level facade crate
  • widgetkit-core - geometry, colors, ids, errors, host events
  • widgetkit-runtime - lifecycle, scheduler, tasks, layout/redraw coordination
  • widgetkit-render - Canvas, text styles, measurement, software renderer
  • widgetkit-host-windows - Windows host built on winit and softbuffer

Roadmap

  • declarative UI and layout
  • richer input model
  • image pipeline stabilization
  • GPU renderer backend
  • hybrid and web-backed integration paths

License

MIT

Dependencies

~0–18MB
~217K SLoC