The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXWidgetList.h
Go to the documentation of this file.
1
2/* **************************************************************************/
19#ifndef ZXWIDGET_LIST
20#define ZXWIDGET_LIST
21
22#include <memory>
25
26
27namespace zxeco
28{
29
30namespace gui
31{
32
33/*******************************************************************************
34*
35* Class: ListWidget
36*
37*******************************************************************************/
38
40
64{
65 public:
66
67 ListWidget(ID id, const std::string & name,
68 const LabelList & initllist, const CharArea & minsize,
69 uint8_t flexdims = AreaFitting::FLEX_HOR | AreaFitting::FLEX_VER,
70 const std::string & tooltiptext = "",
71 HorAlign hal = HorAlign::LEFT,
72 VertAlign val = VertAlign::TOP);
74
102 LabelList & list(void) noexcept { return(*pllist_); }
104
107 void append(const Label::Vector & v);
109
113 size_t howManyLinesCanBeShown(void) const;
115
117 size_t listSizeOfVisible(void) const;
119
123 size_t indexOfTopLine(void) const;
125
127 LabelList::Iterator lastLineInteracted(void) const noexcept
129
133 { return(lastlinepointed_); }
137
142 void moveCursoredLine(bool upordown, size_t howmany);
144
151 void moveCursoredLineToExtreme(bool beginningorend);
153
157 void moveCursoredLine(size_t where);
159
162 bool eventProcessedByList(const CallbackParms & cbp) const noexcept
164
168 { return((cbp.isAfterWithData()) &&
169 (cbp.whoprocessed != nullptr) &&
170 (cbp.whoprocessed == pnudelist_)); }
172 char eventProcessedWentBeyond(const CallbackParms & cbp) const noexcept;
174
185 bool eventLeftClickedOrEnter(const CallbackParms & cbp) const noexcept
187 { return(eventProcessedByList(cbp) &&
188 (cbp.hasBeenLeftClicked() || cbp.hasPressedEnter())); }
190 bool eventHasChangedCursored(const CallbackParms & cbp) const noexcept
192 { return(eventProcessedByList(cbp) &&
193 (cbp.pevd->isMouseWheel() ||
194 cbp.hasBeenLeftClicked() ||
195 cbp.hasPressedKey(DesktopInterface::KeyID::K_ENTER) ||
196 cbp.hasPressedKey(DesktopInterface::KeyID::K_DOWN) ||
197 cbp.hasPressedKey(DesktopInterface::KeyID::K_UP) ||
198 cbp.hasPressedKey(DesktopInterface::KeyID::K_PGDOWN) ||
199 cbp.hasPressedKey(DesktopInterface::KeyID::K_PGUP) )); }
200
204
209 void setUDGs(const uint8_t * udgs)
210
211 { if (istree_) RUNTIMEEXCEP("Cannot set UDGs with a tree list");
212 Widget::setUDGs(udgs); }
214 const char * className(void) const noexcept { return("ListWidget"); }
215 std::pair<bool,const CharRect *> hasFocusZone(void) const noexcept override;
216 const AreaFitting & calcFittingNeeds(const CharArea & area);
217 Widget * setDrawingZone(const CharRect & zone) override;
218 void setTooltip(const std::string & ttt) override;
219
220
221 private:
222
223 enum Subwidgs {
224 NUDELIST = 0,
225 VERTSCROLL,
226 HORIZSCROLL,
227 NUMSUBWIDGETS
228 };
229
230 static const uint8_t kTreeUDGs_[5 * 8];
231 static const std::string kTreeChars_;
232 static const ID kIDsSubs[NUMSUBWIDGETS];
233
234
235 const CharArea nudeminsize_;
236 const uint8_t flexdims_;
237
238 std::unique_ptr<LabelList> pllist_;
239 bool istree_;
240 Widget * pnudelist_;
241 SlideWidget * pvertscroll_;
242 SlideWidget * phorizscroll_;
243 double oldvalh_,oldvalv_;
244 LabelList::Iterator lastlinepointed_;
245
246 bool needExpandedCursor(void) const;
247 LabelList::Iterator cursoredLabel(int & relposfirst,
248 int & relposlast) const;
249 std::string scrollStatesInfo(void) const;
250 std::string nudelistStateInfo(void) const;
251 void setViewportFromSlide(char who);
252 void setSlideFromViewport(char who);
253 void setBothViewportAndSlide(char who, int val);
254 void syncViewportAfterSlides(bool respectcursored, char cause);
255 void listChanged(bool respectcursored, char cause);
256 void drawRaw(void);
257 int processEvent(const EventData & evdata, Widget * who) override;
258};
259
260
261
262} // end namespace gui
263} // end namespace zxeco
264
265#endif
266 // ZXWidgetList
268
269
270
#define RUNTIMEEXCEP(txt)
Raise a runtime exception with the given std::string TXT + additional info.
Definition: CppAddons.h:93
std::vector< Label > Vector
A vector of labels.
Definition: ZXGUIGeneral.h:183
A list of labels to be displayed vertically, with possible marks on them.
Definition: ZXGUIGeneral.h:231
Bidirectional iterator to scan indexes in the list under a given view.
Definition: ZXGUIGeneral.h:246
HorAlign
Horizontal alignment of widgets within the areas of their containers.
VertAlign
Vertical alignment of widgets within the areas of their containers.
virtual void setUDGs(const uint8_t *udgs)
Assign an UDG character set for the widget drawing (do not copy them).
A container of other widgets.
All widgets must inherit from this.
Definition: ZXWidgetsBase.h:56
int ID
A numeric ID associated to the widget.
Definition: ZXWidgetsBase.h:67
Information about the fitting of widgets drawings into rectangular areas.
A class to contain the parameters received by a callback routine.
char eventProcessedWentBeyond(const CallbackParms &cbp) const noexcept
Return an indicator of whether the processed event in CBP went beyond.
void moveCursoredLineToExtreme(bool beginningorend)
Move the cursored line to the beginning (true) or end (false) of list.
LabelList & list(void) noexcept
Return the current list of elements.
Definition: ZXWidgetList.h:102
const char * className(void) const noexcept
Must return a text with the name of the class.
Definition: ZXWidgetList.h:213
size_t indexOfTopLine(void) const
Return the index in the list of the current top line, if any.
CharRect zoneForLineContent(const LabelList::Iterator &itl) const
Return the zone in the drawing for line ITL, or {{0,0},{0,0}} if none.
void append(const Label::Vector &v)
Append all elements of V to the list but with just 1 refresh call.
void setTooltip(const std::string &ttt) override
Must return a text with the name of the class.
bool eventHasChangedCursored(const CallbackParms &cbp) const noexcept
< Return TRUE if the callback is for some event that may change cursored.
Definition: ZXWidgetList.h:189
LabelList::Iterator cursoredLine(void) const
Return an iterator to the current line with the cursor, or end().
ListWidget(ID id, const std::string &name, const LabelList &initllist, const CharArea &minsize, uint8_t flexdims=AreaFitting::FLEX_HOR|AreaFitting::FLEX_VER, const std::string &tooltiptext="", HorAlign hal=HorAlign::LEFT, VertAlign val=VertAlign::TOP)
Constructor.
bool eventLeftClickedOrEnter(const CallbackParms &cbp) const noexcept
< Return TRUE if the callback is for a list-processed left click or enter
Definition: ZXWidgetList.h:184
bool eventProcessedByList(const CallbackParms &cbp) const noexcept
< Return TRUE if the callback is for an event already processed by list.
Definition: ZXWidgetList.h:161
size_t listSizeOfVisible(void) const
Return the number of lines marked as visible in the list.
void setUDGs(const uint8_t *udgs)
Assign an UDG character set for the widget drawing (do not copy them).
Definition: ZXWidgetList.h:208
Widget * setDrawingZone(const CharRect &zone) override
Set the final drawing zone for the widget and the aligned one.
size_t howManyLinesCanBeShown(void) const
Return how many lines can be shown currently in the viewport for list.
std::pair< bool, const CharRect * > hasFocusZone(void) const noexcept override
< Must return TRUE and the zone if the widget contains a focus-able zone.
LabelList::Iterator lastLineInteracted(void) const noexcept
< Return the last line involved in a mouse event or in an ENTER pressing.
Definition: ZXWidgetList.h:126
void moveCursoredLine(bool upordown, size_t howmany)
Move the cursored line up (true) or down (false) howmany times.
const AreaFitting & calcFittingNeeds(const CharArea &area)
Must calculate the widget fitting within the dimensions of AREA.
A sequence of text lines with possibly scroll bars and selection of elements.
Definition: ZXWidgetList.h:64
A slide, either horizontal or vertical, e.g., to serve as scroll bar.
Definition: ZXWidgetSlide.h:39
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31