cotis-wgpu 0.1.0-alpha

Desktop wgpu renderer backend for Cotis
Documentation
//! wgpu-backed desktop renderer for the [Cotis](https://crates.io/crates/cotis) UI ecosystem.
//!
//! `cotis-wgpu` implements Cotis's [`cotis::renders::CotisRenderer`] and
//! [`cotis::renders::CotisRendererAsync`] traits on top of [wgpu](https://crates.io/crates/wgpu) 24,
//! [winit](https://crates.io/crates/winit) 0.30, and [glyphon](https://crates.io/crates/glyphon) 0.8.
//! It is a drop-in alternative to other Cotis render backends such as `cotis-raylib`.
//!
//! # Quick start
//!
//! For interactive applications, create a [`CotisWgpuRenderer`] and wire it into
//! [`CotisApp`](cotis::cotis_app::CotisApp) (from `cotis::cotis_app`) with a layout manager and pipe:
//!
//! ```rust,ignore
//! use cotis::cotis_app::{CotisApp, RenderApp};
//! use cotis_layout::preamble::CotisLayoutManager;
//! use cotis_pipes::cotis_layout_pipes::CotisLayoutToRenderListPipeForGenerics;
//! use cotis_utils::math::Dimensions;
//! use cotis_wgpu::prelude::*;
//!
//! let renderer = CotisWgpuRenderer::auto_start();
//! let manager = CotisLayoutManager::new(Dimensions::new(1000.0, 800.0));
//! let mut app = CotisApp::new(renderer, manager, CotisLayoutToRenderListPipeForGenerics);
//!
//! while !app.render().window_should_close() {
//!     RenderApp::compute_frame(&mut app, |root| {
//!         // build UI on root
//!     });
//! }
//! ```
//!
//! For the full wiring pattern including a `StandardRenderCmds` type alias, see
//! `examples/basic_example/support.rs` in this crate's source tree.
//!
//! Run the shipped example from the workspace root:
//!
//! ```text
//! cargo run --example basic_example -p cotis-wgpu
//! ```
//!
//! # Recommended imports
//!
//! Use [`prelude`] for the common entry-point types:
//!
//! ```rust,no_run
//! use cotis_wgpu::prelude::*;
//! ```
//!
//! # Rendering model
//!
//! [`CotisWgpuRenderer`] draws three kinds of command streams:
//!
//! - [`cotis_defaults::render_commands::render_t_list::RenderTList`] with a nested list type —
//!   typed heterogeneous command lists produced by layout pipes (primary path with `cotis-pipes`).
//! - [`cotis_defaults::render_commands::render_t_list::RenderTList`] with `()` as the list tail —
//!   single-command lists.
//! - [`Box<dyn drawable::WgpuDrawable>`] — type-erased custom commands; implement
//!   [`drawable::WgpuDrawable`] for types not covered by `cotis-defaults` commands.
//!
//! Each [`cotis::renders::CotisRenderer::draw_frame`] call pumps the winit event loop before presenting.
//! [`CotisWgpuRenderer::window_should_close`] also pumps events, so the typical app loop calls
//! `app.render()` (which invokes `draw_frame`) and then checks `window_should_close()`.
//!
//! Built-in drawing for standard `cotis-defaults` commands lives in [`default_drawables`].
//! Custom commands can use the advanced [`pipeline`], [`surface`], and [`text`] modules directly.
//!
//! # Cotis trait implementations
//!
//! [`CotisWgpuRenderer`] also implements Cotis context and interactivity traits.
//! See [`cotis_traits`] for the full list, including:
//!
//! - [`cotis_utils::traits::CotisWindowContext`] — physical window dimensions in pixels.
//! - [`cotis_utils::traits::CotisFrameContext`] — frame delta time.
//! - [`cotis_utils::traits::CotisRenderContext`] — render marker trait.
//! - [`cotis_utils::text::RendererTextMeasuringProvider`] — glyphon text measurement.
//! - [`cotis_utils::interactivity::mouse::MouseProvider`] and keyboard providers via [`input`].
//!
//! # Features
//!
//! | Feature | Effect |
//! |---------|--------|
//! | `complex-color` | Enables `cotis-defaults/complex_color` and `complex_colored_text`. Accepts `ColorLayer` types but **does not render gradients** — see [`default_drawables`]. |
//!
//! # Known limitations
//!
//! - **Fonts:** All text uses glyphon `Family::SansSerif`. `TextConfig::font_id` is ignored; there is
//!   no font-loading API.
//! - **Images:** [`cotis_defaults::render_commands::Image`] commands render as colored rectangles;
//!   texture loading is not implemented.
//! - **Geometry alpha:** The UI shader outputs opaque fragments; cotis color alpha is ignored for
//!   rectangles and borders (text alpha is preserved via glyphon).
//! - **Async renderer:** [`cotis::renders::CotisRendererAsync`] delegates synchronously to
//!   [`cotis::renders::CotisRenderer`]; there is no async GPU work.
//! - **Frame errors:** Present failures log a warning and skip the frame; the application continues.
//!
//! # Public modules
//!
//! | Module | Role |
//! |--------|------|
//! | [`prelude`] | Application entry-point re-exports |
//! | [`renderer`] | [`CotisWgpuRenderer`], [`WindowConfig`], event loop |
//! | [`error`] | [`WgpuBackendError`] |
//! | [`drawable`] | [`drawable::WgpuDrawable`] extension trait |
//! | [`default_drawables`] | Built-in `WgpuDrawable` impls for `cotis-defaults` commands |
//! | [`cotis_traits`] | Cotis context/interactivity trait impls |
//! | [`color`] | Cotis `Color` → wgpu conversions |
//! | [`input`] | winit input snapshot |
//! | [`pipeline`] | Advanced: UI geometry batch and WGSL pipeline |
//! | [`surface`] | Advanced: swapchain and depth buffer |
//! | [`text`] | Advanced: glyphon text batching |

pub mod color;
pub mod cotis_traits;
pub mod default_drawables;
pub mod drawable;
pub mod error;
pub mod input;
pub mod pipeline;
pub mod renderer;
pub mod surface;
pub mod text;

mod device;

pub use error::WgpuBackendError;
pub use renderer::{CotisWgpuRenderer, WindowConfig};

/// Convenient re-exports for application code.
///
/// Typical import:
///
/// ```rust,no_run
/// use cotis_wgpu::prelude::*;
/// ```
pub mod prelude {
    pub use crate::error::WgpuBackendError;
    pub use crate::renderer::{CotisWgpuRenderer, WindowConfig};
}