How lapce/floem works
Main Components
• Floem Core Library – The “src” directory holds the core functionality (e.g., event handling, view creation, state management, style, animations, layout, theming, etc.). This represents the “heart” of your library.
• Reactive Engine – The “reactive” crate implements the fine-grained reactivity system (using reactive primitives such as RwSignals) that drives much of the dynamic UI updates.
• Rendering System – Multiple crates are dedicated to rendering:
• The “renderer” crate integrates with wgpu for GPU rendering and falls back to using CPU rendering with tiny-skia.
• Other crates like “tiny_skia”, “vello”, and “vger” also play roles in rendering/vector graphics. Even if these appear as separate libraries (or lower-level layers), they are part of the rendering abstraction.
• Specialized / Supporting Components – For example:
• “editor-core”: Provides an editor or text editing component built atop Floem.
• “views” in the core “src” directory: These files include definitions of various UI widgets (buttons, labels, text editors, etc.) that rely on the reactive and rendering systems.
• Examples – The “examples” directory contains numerous sample applications that demonstrate how to utilize Floem in different contexts (from a simple counter to more complex layouts and graphics). They represent client usage of the core library.
Relationships and Data Flows
• The UI Layer (widgets, views, event handling, etc.) built in the core library is supported by the reactive engine. Reactive components (signals, effects) update state and trigger the re-rendering of views.
• Inputs and events (from modules like “src/event”, “src/keyboard”, “src/pointer”) feed into the reactive layer and subsequently update the view state.
• The consolidated view tree, once updated, is passed to the rendering system, which interprets layout and draws UI elements using GPU (via wgpu) or CPU (tiny-skia) backends.
• Components such as “editor-core” may also have their own sub-modules that integrate with both the reactive layer and the rendering layer, offering specialized UI behavior.
• The examples leverage these components to demonstrate real-world usage, bridging theory with practical application and showing integration points where developers interact with Floem.
Architectural Patterns and Design Principles
• Modular / Layered Architecture – The project separates core UI logic, reactivity, and rendering into distinct crates. This separation increases maintainability and promotes reusability.
• Declarative & Reactive Paradigm – Similar in spirit to frameworks like React, the library uses reactive primitives to update only the necessary parts of the UI when data changes.
• Example Applications as Consumers – The design should also capture how example apps, spread across many subdirectories, “pull in” the core library to build specific UIs.