1use crate::prelude::Bindable;
2
3#[derive(Clone, Copy, Default, Debug)]
4pub struct Viewport {
5 pub x: i32,
6 pub y: i32,
7 pub w: i32,
8 pub h: i32,
9}
10
11impl Viewport {
12 pub fn with_offset(x: i32, y: i32, w: i32, h: i32) -> Self {
13 Self { x, y, w, h }
14 }
15 pub fn with_size(w: i32, h: i32) -> Self {
16 Self { x: 0, y: 0, w, h }
17 }
18
19 pub fn get_offset(&self) -> (i32, i32) {
20 (self.x, self.y)
21 }
22
23 pub fn set_offset(&mut self, x: i32, y: i32) {
24 self.x = x;
25 self.y = y;
26 }
27
28 pub fn get_size(&self) -> (i32, i32) {
29 (self.w, self.h)
30 }
31
32 pub fn set_size(&mut self, w: i32, h: i32) {
33 self.w = w;
34 self.h = h;
35 }
36}
37
38impl Bindable for Viewport {
39 fn bind(&self) {
40 if (self.w * self.h) > 0 {
41 crate::viewport(self.x, self.y, self.w, self.h);
42 }
43 }
44}