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
Chesto::ListElement Class Reference
Inheritance diagram for Chesto::ListElement:
Inheritance graph
[legend]
Collaboration diagram for Chesto::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 Chesto::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 addNode (std::unique_ptr< Element > node)
 
void remove (Element *element)
 
void removeAll ()
 
void position (int x, int y)
 position the element More...
 
void recalcPosition (Element *parent)
 
float getEffectiveScale () const
 
CST_Rect getBounds ()
 
CST_Renderer * getRenderer ()
 
ElementsetPosition (int x, int y)
 
ElementsetAction (std::function< void()> func)
 
ElementsetAbsolute (bool isAbs)
 
template<typename T , typename... Args>
T * createNode (Args &&... args)
 
Elementconstrain (int flags, int padding=0)
 
ElementconstrainToTarget (Element *target, 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 Chesto::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< std::unique_ptr< Element, std::function< void(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}
 
int backgroundOpacity = 0xff
 
bool isAbsolute = false
 
Elementparent = nullptr
 the parent element (reference only, not owned) 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 cornerRadius = 0
 
int tag = 0
 
std::vector< std::unique_ptr< Constraint > > constraints
 
std::vector< std::unique_ptr< 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 Chesto::Element
typedef Element super
 
- Protected Member Functions inherited from Chesto::Element
void addStackMember (Element *element)
 

Detailed Description

Definition at line 8 of file ListElement.hpp.

Member Function Documentation

◆ handleInertiaScroll()

bool Chesto::ListElement::handleInertiaScroll ( InputEvents event)

Definition at line 37 of file ListElement.cpp.

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

◆ process()

bool Chesto::ListElement::process ( InputEvents event)
virtual

process any input that is received for this element

Reimplemented from Chesto::Element.

Definition at line 5 of file ListElement.cpp.

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

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

◆ processUpDown()

bool Chesto::ListElement::processUpDown ( InputEvents event)

Definition at line 20 of file ListElement.cpp.

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

Member Data Documentation

◆ highlighted

int Chesto::ListElement::highlighted = -1

Definition at line 11 of file ListElement.hpp.

◆ initialTouchDown

int Chesto::ListElement::initialTouchDown = -1

Definition at line 12 of file ListElement.hpp.

◆ minYScroll

int Chesto::ListElement::minYScroll = 0

Definition at line 13 of file ListElement.hpp.


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