Skip to main content

netget/display/
types.rs

1//! Core types for the display module
2
3use serde::{Deserialize, Serialize};
4
5/// RGBA color with 8-bit channels
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub struct Color {
8    pub r: u8,
9    pub g: u8,
10    pub b: u8,
11    pub a: u8,
12}
13
14impl Color {
15    /// Create RGB color with full opacity
16    pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
17        Self { r, g, b, a: 255 }
18    }
19
20    /// Create RGBA color with alpha channel
21    pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
22        Self { r, g, b, a }
23    }
24
25    /// Black color
26    pub const BLACK: Color = Color::rgb(0, 0, 0);
27
28    /// White color
29    pub const WHITE: Color = Color::rgb(255, 255, 255);
30
31    /// Red color
32    pub const RED: Color = Color::rgb(255, 0, 0);
33
34    /// Green color
35    pub const GREEN: Color = Color::rgb(0, 255, 0);
36
37    /// Blue color
38    pub const BLUE: Color = Color::rgb(0, 0, 255);
39
40    /// Gray color
41    pub const GRAY: Color = Color::rgb(128, 128, 128);
42
43    /// Light gray color
44    pub const LIGHT_GRAY: Color = Color::rgb(192, 192, 192);
45
46    /// Dark gray color
47    pub const DARK_GRAY: Color = Color::rgb(64, 64, 64);
48}
49
50/// 2D point
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
52pub struct Point {
53    pub x: u32,
54    pub y: u32,
55}
56
57impl Point {
58    pub const fn new(x: u32, y: u32) -> Self {
59        Self { x, y }
60    }
61}
62
63/// Rectangle defined by position and size
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
65pub struct Rect {
66    pub x: u32,
67    pub y: u32,
68    pub width: u32,
69    pub height: u32,
70}
71
72impl Rect {
73    pub const fn new(x: u32, y: u32, width: u32, height: u32) -> Self {
74        Self {
75            x,
76            y,
77            width,
78            height,
79        }
80    }
81}
82
83/// Drawing commands that can be generated by LLM and rendered by the canvas
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub enum DisplayCommand {
86    /// Render ASCII art as monospace text
87    RenderAsciiArt {
88        text: String,
89        font_size: u32,
90        fg_color: Color,
91        bg_color: Color,
92    },
93
94    /// Draw a filled or outlined rectangle
95    DrawRectangle {
96        x: u32,
97        y: u32,
98        width: u32,
99        height: u32,
100        color: Color,
101        filled: bool,
102    },
103
104    /// Draw text at a position
105    DrawText {
106        x: u32,
107        y: u32,
108        text: String,
109        font_size: u32,
110        color: Color,
111    },
112
113    /// Draw a line between two points
114    DrawLine {
115        x1: u32,
116        y1: u32,
117        x2: u32,
118        y2: u32,
119        color: Color,
120        width: u32,
121    },
122
123    /// Draw a filled or outlined circle
124    DrawCircle {
125        x: u32,
126        y: u32,
127        radius: u32,
128        color: Color,
129        filled: bool,
130    },
131
132    /// Draw a window with title and content
133    DrawWindow {
134        x: u32,
135        y: u32,
136        width: u32,
137        height: u32,
138        title: String,
139        content: Vec<DisplayCommand>,
140    },
141
142    /// Draw a button
143    DrawButton {
144        x: u32,
145        y: u32,
146        width: u32,
147        height: u32,
148        label: String,
149    },
150
151    /// Draw a text input box
152    DrawTextBox {
153        x: u32,
154        y: u32,
155        width: u32,
156        height: u32,
157        text: String,
158        placeholder: Option<String>,
159    },
160
161    /// Set background color
162    SetBackground { color: Color },
163
164    /// Clear the canvas
165    Clear,
166}