Phoenard
PHNItemList.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include "PHNWidget.h"
32 
33 #ifndef _PHN_ITEM_LIST_H_
34 #define _PHN_ITEM_LIST_H_
35 
37 #define ITEMLIST_AUTO_SCROLL_DELAY 200
38 
40 typedef struct ItemParam {
41  int x, y, w, h;
42  int index;
43  int relativeIndex;
44  bool selected;
45  color_t color;
46 } ItemParam;
47 
71 class PHN_ItemList : public PHN_Widget {
72  public:
74  PHN_ItemList();
76  void setItemCount(int itemCount);
78  int itemCount() const { return _itemCount; }
80  void setPageSize(int itemsPerPage);
82  int pageSize() const { return _pageSize; }
84  void setScrollWidth(int scrollWidth);
86  void setDrawFunction(void (*drawFunction)(ItemParam&));
90  int selectedIndex() const { return _selectedIndex; }
92  bool selectionChanged() const { return _selectedChanged; }
94  int firstIndex() { return scroll.value(); }
96  int indexChange() { return (_currScroll - _prevScroll); }
98  bool isScrolled() { return indexChange() != 0; }
99 
101  void drawItem(int index);
102 
103  virtual void update(void);
104  virtual void draw(void);
105 
106  private:
107  PHN_Scrollbar scroll;
108  void (*_drawFunc)(ItemParam&);
109  int _itemCount, _pageSize;
110  int _selectedIndex, _drawnSelIndex;
111  int _itemW, _itemH;
112  int _scrollWidth;
113  int _prevScroll, _currScroll;
114  bool _selectedChanged;
115  bool _invalidateLater;
116  unsigned long lastScrollTime;
117 };
118 
119 #endif
virtual void draw(void)
Draw function routine, where widgets must perform drawing.
Definition: PHNItemList.cpp:165
The item list widget shows a list of items.
Definition: PHNItemList.h:71
int pageSize() const
Gets the amount of items displayed per page.
Definition: PHNItemList.h:82
int itemCount() const
Gets the amount of items displayed.
Definition: PHNItemList.h:78
PHN_ItemList()
Initializes a new list.
Definition: PHNItemList.cpp:36
void setDrawFunction(void(*drawFunction)(ItemParam &))
Sets the draw function to use for the items.
Definition: PHNItemList.cpp:64
int indexChange()
Gets the index change that happened due to scrolling.
Definition: PHNItemList.h:96
bool isScrolled()
Gets whether the first index was changed.
Definition: PHNItemList.h:98
void setScrollWidth(int scrollWidth)
Forces a certain width of the scroll-portion of the list.
Definition: PHNItemList.cpp:59
Structure that stores the parameters for the draw function.
Definition: PHNItemList.h:40
uint16_t color_t
Definition of the 16-bit 565 color type.
Definition: PHNDisplayHardware.h:97
void drawItem(int index)
Forces a particular item to be re-drawn.
Definition: PHNItemList.cpp:81
A single widget which covers a rectangular area of the screen.
Definition: PHNWidget.h:145
struct ItemParam ItemParam
Structure that stores the parameters for the draw function.
bool selectionChanged() const
Checks whether the selected index was changed.
Definition: PHNItemList.h:92
void setItemCount(int itemCount)
Sets the amount of items displayed.
Definition: PHNItemList.cpp:45
void setSelectedIndex(int selectedIndex)
Sets the index of the selected item.
Definition: PHNItemList.cpp:69
virtual void update(void)
Update function routine, where widget logic must be performed.
Definition: PHNItemList.cpp:101
Holds the PHN_Widget and PHN_WidgetContainer classes used for managing widgets.
int selectedIndex() const
Gets the index of the selected item.
Definition: PHNItemList.h:90
int firstIndex()
Gets the index of the first item displayed.
Definition: PHNItemList.h:94
const int value(void)
Gets the scrollbar value.
Definition: PHNScrollbar.h:60
Shows a scroll bar the user can drag.
Definition: PHNScrollbar.h:47
void setPageSize(int itemsPerPage)
Sets the amount of items displayed per page.
Definition: PHNItemList.cpp:54