$ show linebender/druid
Druid is a cross-platform, data-driven GUI toolkit for Rust, providing a reactive widget system with immutable state management via the `Data` trait and composable `Lens` for data access. It supports multiple backends (macOS, Windows, GTK, X11, Wayland, WebAssembly) through a platform abstraction layer (`druid-shell`). The framework includes a rich set of built-in widgets (Flex, Scroll, Split, TextBox, etc.), a layout system inspired by Flutter's `BoxConstraints`, an environment-based theming system (`Env`), and a command/notification system for inter-widget communication. The project is explicitly discontinued and unmaintained, with its successor being Xilem. Despite this, the codebase exhibits high craftsmanship with clean abstractions, well-documented patterns (Controller, Scope, Lens combinators), and a modular architecture that influenced later Rust UI frameworks. However, technical drift is high due to outdated dependencies, incomplete backend implementations (especially Wayland and Web), and deprecated API usage.
The LLM identified 5 files worth highlighting for reuse:
Implements a flexible layout widget (row/column) with configurable axis, cross-axis alignment, main-axis alignment, and flex factors for distributing space among children. Includes intrinsic size computation and baseline alignment. This is a clean, self-contained layout component that could be extracted for use in any Rust UI project requiring a flexbox-like layout.
Defines the `Lens` trait and a suite of combinators (`then`, `map`, `index`, `in_arc`, `not`, `deref`, `as_ref`) for type-safe, composable access to subfields of immutable data structures. This pattern is reusable in any Rust application that needs to project and update nested state without boilerplate, and demonstrates a functional programming approach to state management.
Provides a reusable `ScrollComponent` that handles scrollbar rendering, hover/held state management, and fade-in/out animations. It can be embedded into any scrollable widget to add scrollbar functionality with minimal coupling. The component uses timer-based animation for scrollbar fading and supports both vertical and horizontal scrolling.
Implements the `Controller` trait, which allows adding behavior to a widget without subclassing or modifying the widget itself. Controllers wrap a child widget and can intercept events, lifecycle calls, and updates. This is a clean composition pattern that can be reused in any widget system to separate concerns and add cross-cutting behavior (e.g., logging, validation, animation).
Defines `BoxConstraints` with min/max width/height, aspect ratio enforcement, and loosen/tighten operations. Inspired by Flutter's layout system, this provides a robust foundation for constraint-based layout that can be reused in any 2D layout engine. The implementation is self-contained and well-documented.