//! Declarar el **tipo de contenido** de la ventana (`wp_content_type_v1`). //! //! Cicla `None → Photo → Video → Game` con cada click y se lo declara al //! compositor por [`Handle::set_content_type`]. No cambia nada de lo que se //! pinta: es una pista para que el compositor ajuste su política (mirada deja de //! animar su fondo de marca ante contenido con ritmo propio, y decide VRR y //! tearing con lo mismo). //! //! Corre con: `cargo run -p llimphi-ui --example content_type --release`. //! //! Para **ver el protocolo en el cable** (que es como se verificó el puente //! winit↔wayland-client): //! //! ```sh //! WAYLAND_DEBUG=1 cargo run -p llimphi-ui --example content_type --release 2>&1 \ //! | grep content_type //! ``` //! //! Tienen que aparecer el `get_surface_content_type` y un `set_content_type` //! por cada click. Si no aparece ninguno, el compositor no expone el global (el //! módulo avisa por stderr una sola vez y sigue sin romper nada). use llimphi_ui::llimphi_layout::taffy::{ prelude::{percent, Dimension, Size, Style}, AlignItems, JustifyContent, }; use llimphi_ui::llimphi_raster::peniko::Color; use llimphi_ui::{App, ContentType, Handle, View}; #[derive(Clone)] enum Msg { Ciclar, } struct Demo; fn siguiente(k: ContentType) -> ContentType { match k { ContentType::None => ContentType::Photo, ContentType::Photo => ContentType::Video, ContentType::Video => ContentType::Game, ContentType::Game => ContentType::None, } } fn nombre(k: ContentType) -> &'static str { match k { ContentType::None => "none", ContentType::Photo => "photo", ContentType::Video => "video", ContentType::Game => "game", } } impl App for Demo { type Model = ContentType; type Msg = Msg; fn title() -> &'static str { "llimphi · content type" } fn init(handle: &Handle) -> Self::Model { // Declarar el estado inicial también: el compositor arranca asumiendo // `none`, y una app que nace mostrando video quiere decirlo ya. handle.set_content_type(ContentType::None); ContentType::None } fn update(model: Self::Model, msg: Self::Msg, handle: &Handle) -> Self::Model { match msg { Msg::Ciclar => { let nuevo = siguiente(model); handle.set_content_type(nuevo); nuevo } } } fn view(model: &Self::Model) -> View { View::new(Style { size: Size { width: percent(1.0_f32), height: Dimension::auto(), }, flex_grow: 1.0, align_items: Some(AlignItems::CENTER), justify_content: Some(JustifyContent::CENTER), ..Default::default() }) .fill(Color::from_rgba8(16, 18, 26, 255)) .text( format!("content type: {}", nombre(*model)), 42.0, Color::from_rgba8(230, 240, 250, 255), ) .on_click(Msg::Ciclar) } } fn main() { llimphi_ui::run::(); }