-
Notifications
You must be signed in to change notification settings - Fork 1
/
page.fs
96 lines (82 loc) · 1.99 KB
/
page.fs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
\ RilouwShell 0.1.0
\ Copyright (c) 2019 Jerome Martin
\ Released under the terms of the GNU GPL version 3
\ http://rilouw.eu/project/rilouwshell
struct
ptr% field page-name
ptr% field page-content
cell% field page-cursor
end-struct page%
variable mouse-x
variable mouse-y
variable mouse-buttons
: mouse-left? ( -- b ) mouse-buttons @ 1 and ;
: mouse-right? ( -- b ) mouse-buttons @ 4 and ;
0 value focused-element
0 value hovered-element
0 value clicked-element
: focused? ( element -- ) focused-element = ;
: hovered? ( element -- ) hovered-element = ;
: clicked? ( element -- ) clicked-element = ;
: reset-focus ( -- ) 0 to focused-element ;
: reset-hover ( -- ) 0 to hovered-element ;
: reset-clicked ( -- ) 0 to clicked-element ;
: page-limits ( page -- limit start )
>r
r@ page-content @
r@ page-cursor @ cells +
r> page-content @
;
: update-focus ( page -- )
reset-hover
page-limits do
i 2@
( element type )
dup TYPE-LABEL <> if \ labels don't get focus
over -rot \ keep element
get-element-rect
mouse-x @ mouse-y @ point-in-rect? if
( element ) dup
to focused-element
to hovered-element
leave
else drop then
else 2drop then
2 cells +loop
;
: next-element ( page -- next-element-addr )
dup page-content @ swap
page-cursor @ cells +
;
: add-to-page ( element type page -- )
>r
r@ next-element 2!
r@ page-cursor @ 2 +
r> page-cursor !
;
: render-page ( surface page -- )
page-limits do
dup \ keep surface for next loop
i 2@
( surface surface element type )
over focused? if
3dup get-element-rect draw-focus-around
then
render-element
2 cells +loop
drop \ surface
;
: page ( -- #element ) 0 ;
: end-page ( ...element&type #element <name> -- )
create page% %allot >r \ keep page
( ...element&type #element )
\ allot content
dup 2* cells here swap allot r@ page-content !
r> swap
\ consume each element
0 do
dup >r add-to-page
r>
loop
drop
;