-
Notifications
You must be signed in to change notification settings - Fork 1
/
layout.py
76 lines (65 loc) · 1.79 KB
/
layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from enum import Enum, auto
from config import (
SIDEBAR_WIDTH,
GRID_WIDTH,
BOARDER_WIDTH,
BOTTOM_SIDEBAR_HEIGHT,
GRID_HEIGHT,
SCREEN_HEIGHT,
)
class LAYOUTS(Enum):
GRID = auto()
LEFT_SIDEBAR = auto()
RIGHT_SIDEBAR = auto()
BOTTOM_SIDEBAR = auto()
class Layout:
def __init__(self, name, start_x, start_y, width, height):
self.name = name
self.start_x = start_x
self.start_y = start_y
self.width = width
self.height = height
class LayoutManager:
def __init__(self):
self.layouts = {}
def add_layout(self, layout: Layout):
self.layouts[layout.name] = layout
def on_layout(self, layout_name, x, y):
layout = self.layouts.get(layout_name)
if (
x >= layout.start_x
and x <= layout.start_x + layout.width
and y >= layout.start_y
and y <= layout.start_y + layout.height
):
return layout_name
return None
def get_layouts_below(self, x, y):
layouts = []
for layout in self.layouts:
result = self.on_layout(layout.name, x, y)
if result is not None:
layouts.append(result)
return layouts
layout_manager = LayoutManager()
layout_manager.add_layout(
Layout(LAYOUTS.GRID, SIDEBAR_WIDTH, BOTTOM_SIDEBAR_HEIGHT, GRID_WIDTH, GRID_HEIGHT)
)
layout_manager.add_layout(
Layout(
LAYOUTS.LEFT_SIDEBAR,
0,
BOTTOM_SIDEBAR_HEIGHT,
SIDEBAR_WIDTH,
SCREEN_HEIGHT - BOTTOM_SIDEBAR_HEIGHT,
)
)
layout_manager.add_layout(
Layout(
LAYOUTS.RIGHT_SIDEBAR,
SIDEBAR_WIDTH + GRID_WIDTH + BOARDER_WIDTH,
BOTTOM_SIDEBAR_HEIGHT,
SIDEBAR_WIDTH,
SCREEN_HEIGHT - BOTTOM_SIDEBAR_HEIGHT,
)
)