1use crate::DEFAULT_WINDOW_SIZE;
4use anyhow::Result;
5use gpui_types::{Bounds, Pixels, point};
6use std::fmt::{self, Debug};
7use uuid::Uuid;
8
9#[derive(PartialEq, Eq, Hash, Copy, Clone)]
11pub struct DisplayId(pub(crate) u64);
12
13impl DisplayId {
14 pub fn new(id: u64) -> Self {
16 Self(id)
17 }
18}
19
20impl From<u64> for DisplayId {
21 fn from(id: u64) -> Self {
22 Self(id)
23 }
24}
25
26impl From<DisplayId> for u64 {
27 fn from(id: DisplayId) -> Self {
28 id.0
29 }
30}
31
32impl Debug for DisplayId {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 write!(f, "DisplayId({})", self.0)
35 }
36}
37
38pub trait PlatformDisplay: Debug {
40 fn id(&self) -> DisplayId;
42
43 fn uuid(&self) -> Result<Uuid>;
46
47 fn bounds(&self) -> Bounds<Pixels>;
49
50 fn visible_bounds(&self) -> Bounds<Pixels> {
54 self.bounds()
55 }
56
57 fn default_bounds(&self) -> Bounds<Pixels> {
59 let bounds = self.bounds();
60 let center = bounds.center();
61 let clipped_window_size = DEFAULT_WINDOW_SIZE.min(&bounds.size);
62
63 let offset = clipped_window_size / 2.0;
64 let origin = point(center.x - offset.width, center.y - offset.height);
65 Bounds::new(origin, clipped_window_size)
66 }
67}