dius 0.1.0
Loading...
Searching...
No Matches
tty.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/reflect/prelude.h"
4#include "di/types/integers.h"
5
6namespace dius::tty {
7struct WindowSize {
8 u32 rows { 0 };
9 u32 cols { 0 };
10 u32 pixel_width { 0 };
11 u32 pixel_height { 0 };
12
13 auto rows_shrinked(u32 r) -> WindowSize {
14 if (r >= rows) {
15 return { 0, cols, pixel_width, 0 };
16 }
17 return { rows - r, cols, pixel_width, pixel_height - (r * pixel_height / rows) };
18 }
19
20 auto cols_shrinked(u32 c) -> WindowSize {
21 if (c >= cols) {
22 return { rows, 0, 0, pixel_height };
23 }
24 return { rows, cols - c, pixel_width - (c * pixel_width / cols), pixel_height };
25 }
26
27 auto operator==(WindowSize const&) const -> bool = default;
28
29 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<WindowSize>) {
30 return di::make_fields<"WindowSize">(di::field<"rows", &WindowSize::rows>, di::field<"cols", &WindowSize::cols>,
31 di::field<"pixel_width", &WindowSize::pixel_width>,
32 di::field<"pixel_height", &WindowSize::pixel_height>);
33 }
34};
35}
Definition tty.h:6
Definition tty.h:7
auto rows_shrinked(u32 r) -> WindowSize
Definition tty.h:13
u32 rows
Definition tty.h:8
auto cols_shrinked(u32 c) -> WindowSize
Definition tty.h:20
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< WindowSize >)
Definition tty.h:29
auto operator==(WindowSize const &) const -> bool=default
u32 cols
Definition tty.h:9
u32 pixel_width
Definition tty.h:10
u32 pixel_height
Definition tty.h:11