gpui-ce 0.3.0

A community fork of Zed's GPU-accelerated UI framework
Documentation
use crate::{Bounds, DisplayId, Pixels, PlatformDisplay, Point, px};
use anyhow::{Ok, Result};
use std::time::Duration;

/// A fake display that the test platform reports as its only screen.
///
/// It is 1920 by 1080 logical pixels, with its origin at `(0, 0)`. Each one gets a new UUID.
#[derive(Debug, Clone)]
pub(crate) struct TestDisplay {
    id: DisplayId,
    uuid: uuid::Uuid,
    bounds: Bounds<Pixels>,
    pub(crate) refresh_interval: Option<Duration>,
}

impl TestDisplay {
    /// Creates the fake display, with a new UUID.
    pub fn new() -> Self {
        Self::with_id(DisplayId(1))
    }

    pub fn with_id(id: DisplayId) -> Self {
        TestDisplay {
            id,
            uuid: uuid::Uuid::new_v4(),
            bounds: Bounds::from_corners(Point::default(), Point::new(px(1920.), px(1080.))),
            refresh_interval: Some(Duration::from_secs(1) / 60),
        }
    }
}

impl PlatformDisplay for TestDisplay {
    fn id(&self) -> crate::DisplayId {
        self.id
    }

    fn uuid(&self) -> Result<uuid::Uuid> {
        Ok(self.uuid)
    }

    fn bounds(&self) -> crate::Bounds<crate::Pixels> {
        self.bounds
    }

    fn refresh_interval(&self) -> Option<Duration> {
        self.refresh_interval
    }
}