@@ -11,14 +11,14 @@ import (
1111 "github.com/elgopher/pi/pimouse"
1212)
1313
14- // New creates a new GUI root element.
14+ // New creates a new GUI root element with the current screen size .
1515//
1616// To update and draw the element along with its children,
1717// add it to your game loop by calling Element.Update and Element.Draw.
1818func New () * Element {
1919 return & Element {
20- area : pi.IntArea {
21- W : pi .Screen ().W (), // TODO Should not be fixed
20+ Area : pi.IntArea {
21+ W : pi .Screen ().W (),
2222 H : pi .Screen ().H (),
2323 },
2424 }
@@ -29,19 +29,20 @@ func New() *Element {
2929// It returns the newly created element.
3030func Attach (parent * Element , x , y , w , h int ) * Element {
3131 ch := & Element {
32- area : pi.IntArea {X : x , Y : y , W : w , H : h },
32+ Area : pi.IntArea {X : x , Y : y , W : w , H : h },
3333 }
3434 parent .Attach (ch )
3535 return ch
3636}
3737
3838type Element struct {
39+ pi.Area [int ]
40+
3941 OnDraw func (DrawEvent )
4042 OnUpdate func (UpdateEvent )
4143 OnPressed func (Event )
4244 OnReleased func (Event )
4345 OnTapped func (Event )
44- area pi.Area [int ]
4546 children []* Element
4647 pressed bool
4748}
@@ -66,13 +67,13 @@ func (e *Element) Update() {
6667 pi .Camera = prevCamera
6768 }()
6869
69- pi .Camera .X -= e .area . X // musze przesuwac kamere, zeby dzieci dzieciow zbieraly eventy
70- pi .Camera .Y -= e .area . Y
70+ pi .Camera .X -= e .X // I have to move the camera so that the children's children can pick up events
71+ pi .Camera .Y -= e .Y
7172
7273 mousePosition := pimouse .Position .Add (pi .Camera )
7374
74- hasPointer := mousePosition .X >= 0 && mousePosition .X < e .area . W &&
75- mousePosition .Y >= 0 && mousePosition .Y < e .area . H
75+ hasPointer := mousePosition .X >= 0 && mousePosition .X < e .W &&
76+ mousePosition .Y >= 0 && mousePosition .Y < e .H
7677
7778 propagate := getPropagateToChildrenFromThePool ()
7879
@@ -132,12 +133,12 @@ func (e *Element) Draw() {
132133 pi .Camera = prevCamera
133134 }()
134135
135- pi .Camera .X -= e .area . X
136- pi .Camera .Y -= e .area . Y
136+ pi .Camera .X -= e .X
137+ pi .Camera .Y -= e .Y
137138
138139 prevClip := pi .SetClip (pi.IntArea {
139140 X : - pi .Camera .X , Y : - pi .Camera .Y ,
140- W : e .area . W , H : e . area .H ,
141+ W : e .W , H : e .H ,
141142 })
142143 defer func () {
143144 pi .SetClip (prevClip )
@@ -146,8 +147,8 @@ func (e *Element) Draw() {
146147 propagate := getPropagateToChildrenFromThePool ()
147148
148149 mousePosition := pimouse .Position .Add (pi .Camera )
149- hasPointer := mousePosition .X >= 0 && mousePosition .X < e .area . W &&
150- mousePosition .Y >= 0 && mousePosition .Y < e .area . H
150+ hasPointer := mousePosition .X >= 0 && mousePosition .X < e .W &&
151+ mousePosition .Y >= 0 && mousePosition .Y < e .H
151152
152153 drawEvent := DrawEvent {
153154 Element : e ,
@@ -169,6 +170,3 @@ func (e *Element) Draw() {
169170 }
170171 }
171172}
172- func (e * Element ) Area () pi.IntArea {
173- return e .area
174- }
0 commit comments