cotis-wgpu 0.1.0-alpha

Desktop wgpu renderer backend for Cotis
Documentation
//! Shared types and helpers for cotis-wgpu examples.

use cotis::cotis_app::{CotisApp, RenderApp, UiFn};
use cotis::utils::ElementIdConfig;
use cotis_defaults::colors::Color;
use cotis_defaults::element_configs::premade_configs::GenericElementConfig;
use cotis_defaults::element_configs::style::CotisStyle;
use cotis_defaults::render_commands::render_t_list::RenderTList;
use cotis_defaults::render_commands::{Border, ClipEnd, ClipStart, Rectangle, Text};
use cotis_layout::layout_struct::RenderCommandOutput;
use cotis_layout::preamble::CotisLayoutManager;
use cotis_pipes::cotis_layout_pipes::CotisLayoutToRenderListPipeForGenerics;
use cotis_wgpu::CotisWgpuRenderer;

#[cfg(feature = "complex-color")]
use cotis_defaults::colors::ColorLayer;

/// Fill color for backgrounds and text when `complex-color` may be enabled.
#[cfg(not(feature = "complex-color"))]
pub type FillColor = Color;
#[cfg(feature = "complex-color")]
pub type FillColor = ColorLayer;

/// Builds a solid fill color compatible with the active color mode.
pub fn solid_color(r: f32, g: f32, b: f32, a: f32) -> FillColor {
    let color = Color::rgba(r, g, b, a);
    #[cfg(not(feature = "complex-color"))]
    {
        color
    }
    #[cfg(feature = "complex-color")]
    {
        ColorLayer::Solid(color)
    }
}

/// Element config without image data for the wgpu example.
pub type ExampleConfig = GenericElementConfig<'static, (), ()>;

/// Clip + rectangle + border + text pipeline decoded by [`CotisLayoutToRenderListPipeForGenerics`].
pub type StandardRenderCmds = RenderTList<
    ClipStart<'static, ()>,
    RenderTList<
        ClipEnd,
        RenderTList<
            Rectangle<'static, ()>,
            RenderTList<Border<'static, ()>, RenderTList<Text<'static, ()>, ()>>,
        >,
    >,
>;

pub type ExampleCotisApp =
    CotisApp<CotisWgpuRenderer, CotisLayoutManager, CotisLayoutToRenderListPipeForGenerics>;

/// Minimal element config for leaf nodes (text-only children).
pub fn empty_example_config() -> ExampleConfig {
    ExampleConfig {
        id_config: ElementIdConfig::new_empty(),
        style: CotisStyle::default(),
        image: None,
        custom: None,
        extra_data: None,
    }
}

pub fn compute_frame<'layout, Cmds, Ui>(app: &'layout mut ExampleCotisApp, ui: Ui)
where
    CotisWgpuRenderer: cotis::renders::CotisRenderer<Cmds>,
    CotisLayoutToRenderListPipeForGenerics:
        cotis::pipes::LayoutRenderPipe<RenderCommandOutput<ExampleConfig>, Cmds>,
    Ui: for<'a> UiFn<
            'a,
            cotis_layout::preamble::CotisLayoutRun<'layout, ExampleConfig>,
            ExampleConfig,
        >,
{
    RenderApp::<
        ExampleConfig,
        RenderCommandOutput<ExampleConfig>,
        Cmds,
        CotisWgpuRenderer,
        CotisLayoutManager,
    >::compute_frame(app, ui);
}