Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Public Member Functions | Public Attributes | List of all members
ListElement Class Reference
Inheritance diagram for ListElement:
Inheritance graph
[legend]
Collaboration diagram for ListElement:
Collaboration graph
[legend]

Public Member Functions

bool process (InputEvents *event)
 process any input that is received for this element More...
 
bool handleInertiaScroll (InputEvents *event)
 
bool processUpDown (InputEvents *event)
 
- Public Member Functions inherited from Element
virtual bool process (InputEvents *event)
 process any input that is received for this element More...
 
virtual void render (Element *parent)
 display the current state of the display More...
 
bool onTouchDown (InputEvents *event)
 
bool onTouchDrag (InputEvents *event)
 
bool onTouchUp (InputEvents *event)
 
void hide ()
 
void unhide ()
 
void renderBackground (bool fill=true)
 
void append (Element *element)
 
void remove (Element *element)
 
void removeAll (bool moveToTrash=false)
 
void position (int x, int y)
 position the element More...
 
void recalcPosition (Element *parent)
 
CST_Rect getBounds ()
 
CST_Renderer * getRenderer ()
 
void wipeAll (bool delSelf=false)
 
Elementchild (Element *child)
 
ElementsetPosition (int x, int y)
 
ElementsetAction (std::function< void()> func)
 
ElementcenterHorizontallyIn (Element *parent)
 
ElementcenterVerticallyIn (Element *parent)
 
ElementcenterIn (Element *parent)
 
ElementsetAbsolute (bool isAbs)
 
Elementconstrain (int flags, int padding=0)
 
Elementanimate (int durationIn, std::function< void(float)> onStep, std::function< void()> onFinish)
 
ElementmoveToFront ()
 
ElementsetTouchable (bool touchable)
 
void screenshot (std::string path)
 Take a screenshot of this element and its children, and save it to the given path. More...
 

Public Attributes

int highlighted = -1
 
int initialTouchDown = -1
 
int minYScroll = 0
 
- Public Attributes inherited from Element
std::function< void()> action = NULL
 the action to call (from binded callback) on touch or button selection https://stackoverflow.com/questions/14189440/c-class-member-callback-simple-examples More...
 
std::function< void(InputEvents *event)> actionWithEvents = NULL
 
std::vector< Element * > elements
 visible GUI child elements of this element More...
 
float scale = 1.0f
 
bool touchable = false
 whether or not this element can be touched (highlights bounds) More...
 
bool dragging = false
 whether or not this element is currently being dragged More...
 
bool needsRedraw = false
 whether or not this element needs the screen redrawn next time it's processed More...
 
int futureRedrawCounter = 0
 whether this element needs a redraw for the next X redraws (decreases each time) (0 is no redraws) More...
 
int lastMouseY = 0
 the last Y, X coordinate of the mouse (from a drag probably) More...
 
int lastMouseX = 0
 
bool hasBackground = false
 
rgb backgroundColor = {0, 0, 0}
 
bool isAbsolute = false
 
Elementparent = NULL
 the parent element (can sometimes be null if it isn't set) More...
 
bool hidden = false
 whether this element should skip rendering or not More...
 
bool isProtected = false
 
int elasticCounter = 0
 how much time is left in an elastic-type flick/scroll set by the last distance traveled in a scroll, and counts down every frame More...
 
int width = 0
 width and height of this element (must be manually set, isn't usually calculated (but is in some cases, like text or images)) More...
 
int height = 0
 
int x = 0
 
int y = 0
 
int xAbs = 0
 
int yAbs = 0
 
double angle = 0
 rotation angle in degrees More...
 
int xOff = 0
 
int yOff = 0
 
std::vector< Constraint * > constraints
 
std::vector< Animation * > animations
 
bool useColorMask = false
 whether or not to overlay a color mask on top of this element More...
 
CST_Color maskColor = {0,0,0,0}
 The color to overlay on top. More...
 

Additional Inherited Members

- Public Types inherited from Element
typedef Element super
 

Detailed Description

Definition at line 6 of file ListElement.hpp.

Member Function Documentation

◆ handleInertiaScroll()

bool ListElement::handleInertiaScroll ( InputEvents event)

Definition at line 35 of file ListElement.cpp.

36{
37 bool ret = false;
38 ListElement* elem = this;
39
40 if (event->isTouchDown())
41 {
42 // make sure that the mouse down's X coordinate is over the app list (not sidebar)
43 if (event->xPos < elem->xAbs)
44 return false;
45
46 // saw mouse down so set it in our element object
47 elem->dragging = true;
48 elem->lastMouseY = event->yPos;
49 elem->initialTouchDown = event->yPos;
50
51 ret |= true;
52 }
53 // drag event for scrolling up or down
54 else if (event->isTouchDrag())
55 {
56 if (elem->dragging)
57 {
58 // prevent scrolling until we exceed a treshold distance in the Y direction
59 if (this->initialTouchDown >= 0 && (abs(event->yPos - this->initialTouchDown) < 10 / SCALER))
60 return false;
61
62 this->initialTouchDown = -1;
63
64 int distance = event->yPos - elem->lastMouseY;
65 elem->y += distance;
66 elem->lastMouseY = event->yPos;
67
68 // use the last distance as the rubber band value
69 elem->elasticCounter = distance;
70
71 ret |= true;
72 }
73 }
74 else if (event->isTouchUp())
75 {
76 // mouse up, no more mouse down (TODO: fire selected event here)
77 elem->dragging = false;
78
79 // if the scroll offset is less than the total number of apps
80 // (put on the mouse up to make it "snap" when going out of bounds)
81 // TODO: account for max number of apps too (prevent scrolling down forever)
82 if (elem->y > minYScroll)
83 elem->y = minYScroll;
84
85 ret |= true;
86 }
87
88 // if mouse is up, and there's some elastic counter left, burn out remaining elastic value
89 if (!elem->dragging && elem->elasticCounter != 0)
90 {
91 elem->y += elem->elasticCounter;
92
93 // reduce the elastic counter by 5% each time (slows down the scroll)
94 elem->elasticCounter *= 0.95;
95
96 // if we're less than 10 pixels on the counter, just stop
97 if (abs(elem->elasticCounter) < 10)
98 elem->elasticCounter = 0;
99
100 // TODO: same problem as above todo, also extract into method?
101 if (elem->y > minYScroll)
102 elem->y = minYScroll;
103
104 ret |= true;
105 }
106
107 if (ret) event->isScrolling = true;
108
109 if (event->wheelScroll != 0)
110 {
111 // apply wheel scroll directly to y position, and then reset
112 elem->y += event->wheelScroll * 10;
113 if (elem->y > minYScroll)
114 elem->y = minYScroll;
115 event->wheelScroll *= 0.95;
116
117 if (abs(event->wheelScroll) < 0.1)
118 event->wheelScroll = 0;
119
120 ret |= true;
121 }
122
123 return ret;
124}
bool dragging
whether or not this element is currently being dragged
Definition: Element.hpp:81
int elasticCounter
how much time is left in an elastic-type flick/scroll set by the last distance traveled in a scroll,...
Definition: Element.hpp:115
int lastMouseY
the last Y, X coordinate of the mouse (from a drag probably)
Definition: Element.hpp:90

◆ process()

bool ListElement::process ( InputEvents event)
virtual

process any input that is received for this element

Reimplemented from Element.

Definition at line 3 of file ListElement.cpp.

4{
5 bool ret = false;
6
7 // if we're hidden, don't process input
8 if (hidden) return ret;
9
10 // perform inertia scrolling for this element
11 ret |= this->handleInertiaScroll(event);
12
13 ret |= super::process(event);
14
15 return ret;
16}
virtual bool process(InputEvents *event)
process any input that is received for this element
Definition: Element.cpp:17
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:105

References Element::hidden, and Element::process().

◆ processUpDown()

bool ListElement::processUpDown ( InputEvents event)

Definition at line 18 of file ListElement.cpp.

19{
20 bool ret = false;
21 int SPEED = 1;
22
23 // handle up and down for the scroll view
24 if (event->isKeyDown())
25 {
26 // scroll the view by offsetting the elastic counter
27 event->wheelScroll += (SPEED * event->held(UP_BUTTON) - SPEED * event->held(DOWN_BUTTON));
28
29 ret |= event->held(UP_BUTTON) || event->held(DOWN_BUTTON);
30 }
31
32 return ret;
33}

Member Data Documentation

◆ highlighted

int ListElement::highlighted = -1

Definition at line 9 of file ListElement.hpp.

◆ initialTouchDown

int ListElement::initialTouchDown = -1

Definition at line 10 of file ListElement.hpp.

◆ minYScroll

int ListElement::minYScroll = 0

Definition at line 11 of file ListElement.hpp.


The documentation for this class was generated from the following files: