The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXWidgetsBase.h
Go to the documentation of this file.
1
2/* **************************************************************************/
20#ifndef ZXWIDGETS_BASE
21#define ZXWIDGETS_BASE
22
23#include <string>
24#include <sstream>
25#include <functional>
26#include <memory>
27#include <vector>
28#include <utility>
29#include <algorithm>
32
33
34namespace zxeco
35{
36
37namespace gui
38{
39
40class Window; // declared elsewhere
41class ContainerWidget; // forwardly declared
42
43/*****************************************************************************
44*
45* Abstract Base Class: Widget
46*
47*******************************************************************************/
48
50
55class Widget
56{
57friend ContainerWidget; // For containers to call private methods of Widget
58
59 public:
60
61 /* -------------- General types, consts, etc. -------------- */
65
67 using ID = int;
68
70
74 using Ptr = std::shared_ptr<Widget>;
75
77 class PVector: public std::vector<Ptr>
78 {
79 public:
80
81 using Base = std::vector<Ptr>;
82
83 using Base::Base;
84
85 Widget * addChildOf(const Ptr & w, Widget & parent)
87
89 { push_back(w); back()->setParent(&parent); return(back().get()); }
90 };
91
93
95 class Path: public std::vector<Widget *>
96 {
97 public:
98
99 using Base = std::vector<Widget *>;
100
101 Path(bool downorup):Base{},downorup_{downorup} {}
103
106
109 bool isDownwards(void) const noexcept { return(downorup_); }
111
112 bool isUpwards(void) const noexcept { return(!downorup_); }
114
115 std::string to_string(void) const;
117
118 private:
119
120 bool downorup_;
121 };
122
124
126 enum class TravResult {
127 FINISH_OK,
128 FINISH_FAIL,
129 BACKTRACK,
130 CONTINUE
131 };
132
133 using TraverseObserver = std::function< TravResult(Widget &) >;
135
143 /* -------------- Drawing types, consts, etc. -------------- */
148 {
149 using Vector = std::vector<AreaFitting>;
150
152 enum class Fit {
153 UNFIT,
154 FIT,
155 FLEXFIT
156 };
157
159
160 enum : uint8_t {
162 FLEX_VER = 2
163 };
164
165
172 uint8_t flexdim;
173 std::string explanation;
174
175
176 AreaFitting(const CharArea & prov, Widget * wi,
177 const std::string & expl = ""):
179 widget{wi},widgetcause{wi},
180 provided{prov},
181 fitting{Fit::UNFIT},
182 needed{0,0},flexdim{0},
183 explanation{expl} {}
185
186 AreaFitting(const CharArea & prov, Widget * wi,
187 const CharArea & ndd, uint8_t fds = 0):
189 widget{wi},widgetcause{nullptr},
190 provided{prov},
192 needed{ndd},flexdim{fds}
194 { if (fds == 0) fitting = Fit::FIT; }
195
196 AreaFitting(Widget * wi, const CharArea & ndd,
197 const CharArea & availablearea);
199
206 AreaFitting(Widget * wi, const AreaFitting & oaf):AreaFitting{oaf}
208 { widget = wi; }
209
210 AreaFitting(Widget * wi, AreaFitting && oaf):AreaFitting{std::move(oaf)}
212
213 { widget = wi; }
214
217 { copyFrom(oaf); return(*this); }
218
221 { if (this != &oaf) moveFrom(std::move(oaf)); return(*this); }
222
223 void assign(Widget * wi, const AreaFitting & oaf)
225 { copyFrom(oaf); widget = wi; }
226
227 void assign(Widget * wi, AreaFitting && oaf)
229
230 { if (this != &oaf) moveFrom(std::move(oaf));
231 widget = wi; creattime = utime_now(); }
232
233
234 operator bool(void) const noexcept { return(fitting != Fit::UNFIT); }
236
237 std::string to_string(void) const;
239
240 private:
241
242 AreaFitting(const AreaFitting & oaf):needed{0,0},provided{0,0}
243 { copyFrom(oaf); creattime = utime_now(); }
244 AreaFitting(AreaFitting && oaf):needed{0,0},provided{0,0}
245 { moveFrom(std::move(oaf)); }
246
247 void copyFrom(const AreaFitting & oaf);
248 void moveFrom(AreaFitting && oaf);
249 };
250
252 enum class HorAlign {
253 LEFT,
254 RIGHT,
255 CENTER
256 };
257
259 enum class VertAlign {
260 TOP,
261 BOTTOM,
262 MIDDLE
263 };
264
268 /* -------------- Event types, consts, etc. -------------- */
272 enum class EventType {
273 MOUSE,
274 KEYBOARD,
275 FOCUS
276 };
277
279 enum class SubEvType {
280 MOUSE_MOVE,
284 KEYB_PRESS,
286 KEYB_TEXT,
287 FOCUS_GOT,
289 };
290
291
293
302 {
306 struct EvData { // better not to be union: contains non-trivial string
307 // and also because key events also store the last known
308 // mouse position (to decide about being those keys
309 // pressed while the mouse is over some widget).
310 int32_t wheelincr{0};
330 DesktopInterface::KeyID::NUM_OF_KEY_IDS};
332
333 std::string text;
336 EvData(int32_t wi):wheelincr{wi} {}
337 EvData(const PointingStatus & m):mouse{m} {}
338 EvData(const DesktopInterface::KeyID k):key{k} {}
339 EvData(const char * chutf8):text(chutf8) {}
340 EvData(const EvData & o) { copyFrom(o); }
341 EvData(EvData && o) { copyFrom(o); }
342 EvData & operator=(const EvData & o)
343 { copyFrom(o); return(*this); }
344 EvData & operator=(EvData && o)
345 { copyFrom(o); return(*this); }
346 ~EvData(void) {}
347
348 private:
349
350 void copyFrom(const EvData & o)
351 { wheelincr = o.wheelincr; mouse = o.mouse; key = o.key;
352 text = o.text; }
353
354 } evdata;
355
357 evdata{DesktopInterface::KeyID::NUM_OF_KEY_IDS} {}
359
360 EventData(int32_t wincr): evt{EventType::MOUSE},
362 evdata{wincr} {}
364
367
370
371 EventData(const char * chutf8) : evt{EventType::KEYBOARD},
373 evdata{chutf8} {}
375
376 EventData(const EventData & o):EventData{} { copyFrom(o); }
377 EventData(EventData && o):EventData{} { copyFrom(o); }
378 EventData & operator=(const EventData & o)
379 { copyFrom(o); return(*this); }
380 EventData & operator=(EventData && o)
381 { copyFrom(o); return(*this); }
382
385
389 bool isMouseClick(void) const noexcept
391 { return((evt == EventType::MOUSE) &&
393
394 bool isMouseUnclick(void) const noexcept
396 { return((evt == EventType::MOUSE) &&
398
399 bool isMouseRightClick(void) const noexcept
401 { return(isMouseClick() && evdata.mouse.buttonright); }
402
403 bool isMouseLeftClick(void) const noexcept
405 { return(isMouseClick() && evdata.mouse.buttonleft); }
406
407 bool isMouseRightUnclick(void) const noexcept
409 { return(isMouseUnclick() && (!evdata.mouse.buttonright)); }
410
411 bool isMouseLeftUnclick(void) const noexcept
413 { return(isMouseUnclick() && (!evdata.mouse.buttonleft)); }
414
415 bool isMouseMove(void) const noexcept
417 { return((evt == EventType::MOUSE) &&
419
420 bool isMouseWheel(void) const noexcept
422 { return((evt == EventType::MOUSE) &&
424
425 bool isKeyPressed(void) const noexcept
427
429 { return((evt == EventType::KEYBOARD) &&
431
432 bool isKeyUnpressed(void) const noexcept
434
436 { return((evt == EventType::KEYBOARD) &&
438
439 bool isRecognizedText(void) const noexcept
441 { return((evt == EventType::KEYBOARD) &&
443
444 bool isGotFocus(void) const noexcept
446 { return((evt == EventType::FOCUS) &&
448
449 bool isLostFocus(void) const noexcept
451 { return((evt == EventType::FOCUS) &&
453
454 bool needsFocus(void) const noexcept
456
458 { return(// needs focus to lose the focus:
459 isLostFocus() ||
460 // needs focus if it is a non-motion key:
461 (isKeyPressed() || isKeyUnpressed()) ||
462// The following prevented motion keys for being dealt with by focused widgets
463// that could benefit from them when they were not pressed/unpressed within the
464// widgets spatial area.
465// ((isKeyPressed() || isKeyUnpressed())
466// && (!DesktopInterface::keyIsForMotion(evdata.key))) ||
467 // needs focus if it is a typed text:
468 isRecognizedText()); }
469
470 bool hasMouse(void) const noexcept
472 { return((!isLostFocus()) &&
473 (!isKeyPressed()) && (!isKeyUnpressed())); }
474
475
476 std::string to_string(void) const;
478
479 private:
480
481 void copyFrom(const EventData & o)
482 { evt = o.evt; subevt = o.subevt; evdata = o.evdata; }
483
484 };
485
487
493 {
495 enum {
499 WINCLOSE
500 };
501
502
503 int result;
508 ChainEventResult(bool winclose = false):result{winclose? WINCLOSE :
510 who{nullptr} {}
512
513 ChainEventResult(int r):result{r},who{nullptr} {}
515
519 ChainEventResult(int r, Widget * p):result{r},who{p} {}
521
525 std::string to_string(void) const
527 { return(std::string{result == PROCESSED_OK ? "PROCESSED_OK" :
529 "PROCESSED_FINISH" :
530 result == WINCLOSE ?
531 "WINCLOSE" : "NOT_PROCESSED"} +
532 (who == nullptr ? std::string{", no leaf widget"} :
533 (std::string{", leaf widget ID "} +
534 std::to_string(who->getID())))); }
535
536 };
537
539
542 {
543 char moment;
547 const EventData * pevd;
548
549
551 bool isAfterWithData(void) const noexcept
552 { return((moment == 'A') && (pevd != nullptr)); }
553
554 bool isBeforeWithData(void) const noexcept
555 { return((moment == 'B') && (pevd != nullptr)); }
556
558 bool isToGetFocus(void) const noexcept
559 { return(isBeforeWithData() && pevd->isGotFocus()); }
560
562
564 bool hasBeenLeftClicked(void) const noexcept
565 { return(isAfterWithData() && pevd->isMouseLeftUnclick()); }
566
568
571 { return(isAfterWithData() && pevd->isKeyUnpressed() &&
572 (pevd->evdata.key == k)); }
573
575 bool hasPressedEnter(void) const noexcept
576 { return(hasPressedKey(DesktopInterface::K_ENTER)); }
577
579 bool hasBeenLeftClickedOrEnter(void) const noexcept
580 { return(hasBeenLeftClicked() || hasPressedEnter()); }
581
582
583 std::string to_string(void) const
584 { return("CallbackParms: moment = " + std::string(1,moment) +
585 ", whoprocessed = " + (whoprocessed == nullptr ? "null" :
586 whoprocessed->idText()) +
587 ", eventadata = " + (pevd == nullptr ? "null" :
588 pevd->to_string())); }
589 };
590
591 using CallbackRout = std::function< bool(Widget &, const CallbackParms &)>;
593
602
606 /* -------------- Tracing errors -------------- */
610
615 struct Trace
616 {
617 using Type = uint8_t;
618
619 enum : Type {
620 Drawing = 1
621 // TODO: Events = 2, ///< All events except mouse move.
622 // TODO: EvMMove = 4, ///< Mouse move events
623 };
624 };
625
626 static const std::string kTraceBegin;
627 static const std::string kTraceEnd;
628
629 static void addGlobalTraces(Trace::Type traces) noexcept
631 { traces_ |= traces; }
632
633 static void delGlobalTraces(Trace::Type traces) noexcept
635 { traces_ &= ~traces; }
636
637 static inline Trace::Type isTracing(Trace::Type traces) noexcept
639 { return(traces_ & traces); }
640
641 static void printTrace(Trace::Type trace, const std::string & tr);
643
644 static void printIfTrace(Trace::Type trace, const std::string & tr);
646
652 /* -------------- Constructors -------------- */
655 Widget(ID id, const std::string & name,
656 const std::string & tooltiptext = "",
657 HorAlign hal = HorAlign::LEFT,
658 VertAlign val = VertAlign::TOP):
659 id_{id},
660 name_{nonCtrlString(name)},
661 visible_{true},
662 enabled_{true},
663 focused_{false},
664 drawn_{false},
665 callback_{NullCallback},
666 hal_{hal},val_{val},
667 fitting_needs_{{0,0},this},
668 pwin_{nullptr},
669 pwincols_{nullptr},
670 parent_{nullptr},
671 explaindrawing_{false},
672 udgs_{nullptr}
673 { setTooltip(tooltiptext); }
675
686 Widget(const Widget &) = delete;
687 Widget(Widget &&) = delete;
688 Widget & operator=(const Widget &) = delete;
689 Widget & operator=(Widget &&) = delete;
691 virtual ~Widget(void) = default;
693
697 /* -------------- General Methods -------------- */
700 virtual const char * className(void) const noexcept = 0;
702
706 std::string idText(bool withpointer = false) const;
708
711 virtual bool isContainer(void) const noexcept { return(false); }
715 bool isUserContainer(void) const noexcept;
719 ID getID(void) const noexcept { return(id_); }
724 void changeID(ID id) noexcept { id_ = id; }
726
729 const std::string & getName(void) const noexcept { return(name_); }
731
735 bool operator==(const Widget & oth) const noexcept { return(this == & oth);}
737
738 bool operator!=(const Widget & oth) const noexcept { return(this != & oth);}
740
741 virtual std::pair<bool,const CharRect *> hasFocusZone(void) const noexcept
743
748 { return(std::make_pair(false,nullptr)); }
749
750 virtual void setWindow(Window & win) noexcept { pwin_ = & win; }
753 virtual void setWinColors(const WinColors & wincols) noexcept
755 { pwincols_ = & wincols; }
756
757 const WinColors & getWinColors(void) const noexcept { return(*pwincols_); }
760 virtual void setUDGs(const uint8_t * udgs) { udgs_ = udgs; }
765 const uint8_t * getUDGs(void) { return(udgs_); }
767
768 virtual void setTooltip(const std::string & ttt)
769
772 { tooltiptext_ = nonCtrlString(ttt); }
773
774 const std::string & getTooltip(void) const noexcept { return(tooltiptext_);}
776
780 /* -------------- Widget tree methods -------------- */
783 void setParent(Widget * parent);
788 Widget * getParent(void) const noexcept { return(parent_); }
792 Widget * getRoot(void);
794
797 bool isRoot(void) const noexcept { return(parent_ == nullptr); }
799
800 bool isDescendantOf(Widget & w) const;
804 Widget * searchID(ID id) const;
806
809 ID maxUsedID(void) const;
811
814 TravResult traverse(const TraverseObserver & obs);
823 TravResult revTraverse(const TraverseObserver & obs);
825
836 /* -------------- Visibility, enabling and focus methods -------------- */
839 void setVisibility(bool visible = true);
841
851 void setVisibilityNoRedrawing(bool vis) noexcept { visible_ = vis; }
853
859 bool getVisibility(void) const noexcept;
861
866 void setEnabled(bool enabled = true);
868
873 bool getEnabled(void) const noexcept;
875
878 bool isFocusable(bool drawntoo = true) const;
880
882 bool isInFocusPath(void) const noexcept { return(focused_); }
884
887 bool isLeafFocused(void) const noexcept
889 { return(isInFocusPath() && !isContainer()); }
890
891 Widget * whoIsFocused(void);
893
895 void acquireFocus(const PointingStatus * m = nullptr);
897
904 void releaseFocus(void);
906
913 /* -------------- General, Top-Level Drawing Methods -------------- */
916 void drawAll(const CharRect & rect);
918
932 Widget * redrawAll(void);
934
945 void redrawMe(void);
947
951 void drawMe(void);
953
961 /* --- Parts of the calculation, placement & drawing general process --- */
964 virtual const AreaFitting & calcFittingNeeds(const CharArea & area) = 0;
966
989 const AreaFitting & fittingNeeds(void) const noexcept
991
992 { return(fitting_needs_); }
993
994 virtual Widget * setDrawingZone(const CharRect & zone);
996
1023 const CharRect & drawingZone(void) const noexcept
1026 { return(drawing_zone_); }
1027
1028 const CharRect & alignedDrawingZone(void) const noexcept
1030
1032 { return(aligned_drawing_zone_); }
1033
1034 virtual void moveDrawingZones(IntDist incx, IntDist incy) noexcept;
1036
1041 bool drawn(void) const noexcept { return(drawn_); }
1043
1044 void undraw(void) noexcept { drawn_ = false; }
1050 /* --------- Getting explanations of drawing of one widget -------------- */
1051 /* (NOTICE THAT FOR TRACING ERRORS MAYBE BETTER TO USE THE TRACING GLOBAL
1052 ONES -SEE ABOVE- ) */
1055 void setExplanations(bool setit = true) noexcept
1061 { explaindrawing_ = setit; }
1062
1063 bool getExplanations(void) const noexcept { return(explaindrawing_); }
1065
1066 std::string traceOfDrawing(bool withoutprivate = true) const
1068
1070 { std::stringstream ss; traceOfDrawingRecursive(0,ss,withoutprivate);
1071 return(ss.str()); }
1072
1073 virtual void traceOfDrawingRecursive(size_t level,
1074 std::stringstream & ss,
1075 bool withoutprivate = true) const;
1077
1084 /* -------------- Interaction Methods -------------- */
1087 virtual ChainEventResult chainEvent(const EventData & data);
1089
1106 virtual void setCallback(const CallbackRout & callback = NullCallback)
1107
1108 { callback_ = callback; }
1109
1110 const CallbackRout & getCallback(void) const noexcept { return(callback_); }
1112
1113 void addCallback(const CallbackRout & cbk);
1115
1121 protected:
1122
1123 static Trace::Type traces_;
1124
1125
1126 ID id_;
1127 const std::string name_;
1128
1129 const WinColors * pwincols_;
1130 const uint8_t * udgs_;
1131 Window * pwin_;
1132
1133 // use the public methods to change these
1134 // (read them directly without problems, though)
1135 CallbackRout callback_;
1136 std::string tooltiptext_;
1138 VertAlign val_;
1139 AreaFitting fitting_needs_;
1140 CharRect drawing_zone_;
1141 CharRect aligned_drawing_zone_;
1142 Widget * parent_;
1143 bool explaindrawing_;
1144
1145
1146 virtual void drawRaw(void) {}
1158 virtual int processEvent(const EventData & evdata, Widget * who)
1159
1182 { return(1); }
1183
1184 void addLineToExplanation(const std::string & line);
1186
1189 private:
1190
1191 static const std::string & traceName(Trace::Type trace);
1193
1197 bool visible_;
1198 bool enabled_;
1199 bool focused_;
1200 bool drawn_;
1201
1202 CharRect alignArea(const CharRect & availablezone,
1203 const CharArea & areaneeded) const
1204 { return(availablezone.align_area(areaneeded,
1205 hal_ == HorAlign::CENTER ? 'C' :
1206 (hal_ == HorAlign::RIGHT ? 'R' : 'L'),
1207 val_ == VertAlign::MIDDLE ? 'M' :
1208 (val_ == VertAlign::BOTTOM ? 'B' : 'T'))); }
1209 bool decideCanQuitFocus(const Path & mypathtoroot) const;
1210 void updateFocus(bool focusgotorlost);
1211 Widget * recalcDrawingZones(bool directparent,
1212 CharRect & old_drawing_zone_,
1213 Widget * & ptrcause);
1214 Widget * drawAllFrom(Widget * from, const CharRect & rect,
1215 bool onlyifchanged);
1216 void draw(bool cls = true);
1217 bool coversTargetOfEvent(const EventData & evdata, CharCursor & cc) const;
1218};
1219
1220
1221/*****************************************************************************
1222*
1223* Class: ContainerWidget
1224*
1225*******************************************************************************/
1226
1228
1230{
1231 public:
1232
1233 /* -------------- Types, consts, etc. -------------- */
1237 enum class OrType {
1238 VERTICAL,
1239 HORIZONTAL,
1240 DEEP
1249 };
1250
1252 enum class CCType {
1253 USER,
1258 OWN
1265 };
1266
1268
1272 enum class FMType {
1273 NORMAL,
1274 PRESERVE
1275 };
1276
1280 /* -------------- Constructors -------------- */
1283 ContainerWidget(ID id, const std::string & name,
1284 CCType cctype = CCType::USER,
1285 OrType ortype = OrType::VERTICAL,
1286 FMType foctype = FMType::NORMAL,
1287 bool withframe = false,
1288 const std::string & title = "",
1289 HorAlign hal = HorAlign::LEFT,
1290 VertAlign val = VertAlign::TOP,
1291 const std::string & tooltiptext = ""):
1292 Widget{id,name,tooltiptext,hal,val},
1293 cctype_{cctype},
1294 ortype_{ortype},
1295 focustype_{foctype},
1296 whodeep_{0},
1297 withframe_{withframe},
1298 title_{nonCtrlString(title,'L')} {}
1300
1321 /* -------------- Container methods -------------- */
1324 CCType ccType(void) const noexcept { return(cctype_); }
1327 OrType orType(void) const noexcept { return(ortype_); }
1330 FMType focusMngType(void) const noexcept { return(focustype_); }
1333 bool getFrame(void) const noexcept { return(withframe_); }
1335
1338 const std::string & getTitle(void) const noexcept { return(title_); }
1340
1341 bool cursorInTopFrame(const CharCursor & cc) const;
1343
1346 const PVector & children(void) noexcept { return(children_); }
1351 Widget * addChild(const Ptr & ch)
1354 { return(children_.addChildOf(ch,*this)); }
1355
1356 void setDeepSelected(PVector::size_type who);
1358
1362 PVector::size_type getDeepSelected(void) const;
1364
1369 /* -------------- Widget methods -------------- */
1372 const char * className(void) const noexcept { return("ContainerWidget"); }
1373 bool isContainer(void) const noexcept override { return(true); }
1374 const AreaFitting & calcFittingNeeds(const CharArea & area);
1375 void drawRaw(void);
1376 Widget * setDrawingZone(const CharRect & zone) override;
1377 void moveDrawingZones(IntDist incx, IntDist incy) noexcept override;
1378 void setWindow(Window & win) noexcept override;
1379 void setWinColors(const WinColors & wincols) noexcept override;
1380 ChainEventResult chainEvent(const EventData & data) override;
1381
1385 private:
1386
1387 static const std::vector<uint8_t> kContUDGs;
1388
1389
1390 CCType cctype_;
1391 OrType ortype_;
1392 FMType focustype_;
1393 PVector children_;
1394 PVector::size_type whodeep_;
1395 bool withframe_;
1396 std::string title_;
1397
1398
1399 bool isTabbedDeep(void) const noexcept;
1400 bool isFramed(void) const noexcept;
1401 CharDist tabTitleSize(const CharArea & area) const;
1402 size_t tabClicked(CharCoord x) const;
1403 void calcFrameDims(const CharArea & area,
1404 CharDist & framewidthchars,
1405 CharDist & frameheightchars,
1406 CharDist & titlewidthchars,
1407 CharCursor & bodytopleft) const;
1408 void drawFrameTitle(Screen & scr) const;
1409 Widget * calcChildrenOccupation(const CharArea & availablearea,
1410 bool calcfitting,
1411 size_t & howmanychildrenvisible,
1412 CharDist & totwidth, CharDist & totheight,
1413 size_t & howmanyflexvert,
1414 size_t & howmanyflexhor,
1415 std::string & explanation);
1416 void calcShareExcessForChildren(const CharArea & area,
1417 CharDist excess,
1418 std::vector<CharDist> & sharing,
1419 size_t howmanychildrenareflex,
1420 size_t howmanychildrenarevisible,
1421 CharDist totdim, OrType dir);
1422 void traceOfDrawingRecursive(size_t level, std::stringstream & ss,
1423 bool withoutprivate = true) const;
1424};
1425
1426
1427} // end namespace gui
1428} // end namespace zxeco
1429
1430#endif
1431 // ZXWidgetsBase
1433
1434
1435
LongestUnsignedType utime_now(void)
Return the current time since epoch in microseconds.
Definition: CppAddons.h:1116
KeyID
IDs for the most common keys in a keyboard.
Interface with the functionality that a desktop must provide.
Colors used in a GUI window.
Definition: ZXGUIGeneral.h:53
unsigned long long LongestUnsignedType
Longest unsigned integral type in the target machine.
Definition: CppAddons.h:367
bool isAfterWithData(void) const noexcept
Return TRUE for parameters that occur in 'A' moment and have data.
bool isToGetFocus(void) const noexcept
Return TRUE for parameters indicating right before getting focus.
Path(Widget *pw)
Create an upwards path from PW to the root (both included).
char moment
Either 'B' (before processing event) or 'A' (after).
EventData(const char *chutf8)
Constructor for KEYB_TEXT event.
std::vector< Ptr > Base
Shortcut.
Definition: ZXWidgetsBase.h:81
int32_t wheelincr
Vertical wheel incr. for MOUSE_WHEEL.
Widget * addChildOf(const Ptr &w, Widget &parent)
< Reuse constructors
Definition: ZXWidgetsBase.h:85
static Trace::Type traces_
Currently active traces.
@ PROCESSED_FINISH
The same, but the chaining must stop.
@ WINCLOSE
A window close event catched during the chaining.
@ NOT_PROCESSED
Neither widget or its descendants took it.
@ PROCESSED_OK
The widget or its descendants processed it.
bool isLostFocus(void) const noexcept
< Return TRUE if the event is the lost of focus by the widget.
bool needsFocus(void) const noexcept
< Return TRUE if the event needs some focused widget to be sent to.
std::string to_string(void) const
Return textual information about the fitting.
bool isKeyPressed(void) const noexcept
< Return TRUE if the event is a key pressed.
AreaFitting(const CharArea &prov, Widget *wi, const std::string &expl="")
Default constructor: UNFIT.
EventData(SubEvType s, DesktopInterface::KeyID key)
Constructor for KEYB_* event.
ChainEventResult(bool winclose=false)
Default constructor. Not processed / winclose events.
EventData(int32_t wincr)
Constructor for MOUSE_WHEEL.
std::string idText(bool withpointer=false) const
Return a text with the identification of this widget.
bool isMouseWheel(void) const noexcept
< Return TRUE if the event is mouse wheel.
HorAlign
Horizontal alignment of widgets within the areas of their containers.
static Trace::Type isTracing(Trace::Type traces) noexcept
< Return a non-zero value if any of TRACES is currently active.
FMType
Types of management of focus among descendant widgets.
Path(bool downorup)
Create an empty path that goes downwards (TRUE) or upwards (FALSE).
bool isMouseClick(void) const noexcept
< Return TRUE if the event is a click of the mouse.
static const CallbackRout NullCallback
Callback routine that does nothing.
bool isGotFocus(void) const noexcept
< Return TRUE if the event is the acquisition of focus to the widget.
SubEvType
Concrete events for each event kind.
@ MOUSE_MOVE
movement of the mouse
@ MOUSE_UNCLICK
unclick of the mouse
@ MOUSE_CLICK
click of the mouse
@ FOCUS_LOST
widget lost focus
@ MOUSE_WHEEL
mouse wheel motion
@ KEYB_TEXT
a char is recognized by the OS
@ FOCUS_GOT
widget got focus
bool hasBeenLeftClickedOrEnter(void) const noexcept
Return TRUE for parameters indicating left click or enter.
EventType evt
Event kind.
AreaFitting(Widget *wi, AreaFitting &&oaf)
bool isMouseRightUnclick(void) const noexcept
< Return TRUE if the event is the right unclick of the mouse.
bool isRecognizedText(void) const noexcept
< Return TRUE if the event is the recognition of a char by the OS.
std::string to_string(void) const
< Return a text describing the result.
bool hasPressedEnter(void) const noexcept
Return TRUE for parameters indicating ENTER has been pressed.
bool hasBeenLeftClicked(void) const noexcept
Return TRUE for parameters indicating a left click has been produced.
bool isMouseRightClick(void) const noexcept
< Return TRUE if the event is the right click of the mouse.
static void addGlobalTraces(Trace::Type traces) noexcept
< Add TRACES to the currently active traces (initially none).
DesktopInterface::KeyID keyOrWheelIntoKey(void) const
If the event is mouse wheel, return either UP or DOWN.
LongestUnsignedType creattime
Time of creation.
std::string text
If the event is KEYB_TEXT.
Widget(ID id, const std::string &name, const std::string &tooltiptext="", HorAlign hal=HorAlign::LEFT, VertAlign val=VertAlign::TOP)
Constructor.
Widget * who
Leaf widget that dealt with widget or null if unknown.
EventData(EventType e, SubEvType s, const PointingStatus &m)
Constructor for MOUSE (not wheel) or FOCUS_GOT event.
Fit fitting
How the widget fits in the provided area.
DesktopInterface::KeyID key
If event is KEYB_PRESS/UNPRESS.
bool isMouseLeftUnclick(void) const noexcept
< Return TRUE if the event is the left unclick of the mouse.
EventType
Kinds of events that the widgets may process from the graphical environ.
@ MOUSE
movement, clicking, ...
@ KEYBOARD
pressing, unpressing
std::string to_string(void) const
Construct a text describint the path.
uint8_t flexdim
Dimension along which a FLEXFIT can vary.
ID getID(void) const noexcept
Return the ID assigned to the widget at creation.
VertAlign
Vertical alignment of widgets within the areas of their containers.
bool isKeyUnpressed(void) const noexcept
< Return TRUE if the event is a key unpressed.
AreaFitting & operator=(AreaFitting &&oaf)
const EventData * pevd
Data about the event (no ownership).
bool isUpwards(void) const noexcept
Return TRUE if the path goes upwards.
CCType
Types of container according to the creation of their children.
@ FLEX_HOR
Can be flexible in horizontal.
@ FLEX_VER
Can be flexible in vertical.
AreaFitting(Widget *wi, const CharArea &ndd, const CharArea &availablearea)
Constructor for UNFIT, FLEXFIT or FIT type.
Widget * widgetcause
Ptr (no owner) to first widget that was unfit.
void assign(Widget *wi, const AreaFitting &oaf)
Fit
Kinds of fittings of the drawing of a widget in a given area.
@ FIT
Can fit in the area with a fixed size.
@ FLEXFIT
Can fit in the area at different sizes.
@ UNFIT
Cannot fit in the area.
PointingStatus mouse
If the event is MOUSE or FOCUS_GOT.
bool hasMouse(void) const noexcept
< Return TRUE if the event contains info of mouse coordinates.
bool isMouseLeftClick(void) const noexcept
< Return TRUE if the event is the left click of the mouse.
Widget * whoprocessed
If 'B', nullptr; if 'A': who processed event.
static void delGlobalTraces(Trace::Type traces) noexcept
< Delete the given traces from the current active ones.
AreaFitting & operator=(const AreaFitting &oaf)
std::string explanation
Explanation of the fit (optional).
OrType
Types of containers according to the spatial orientation of their contnt.
@ Drawing
Traces in the placing/drawing process.
static const std::string kTraceEnd
< Add TRACES to the currently active traces (initially none).
std::function< bool(Widget &, const CallbackParms &)> CallbackRout
std::string to_string(void) const
Return a text explaining the event.
Widget(Widget &&)=delete
Constructor.
static void printTrace(Trace::Type trace, const std::string &tr)
Put TR in console as a trace, with a mark indicating TRACE.
bool isDownwards(void) const noexcept
Return TRUE if the path goes downwards.
Widget * widget
Ptr (no ownerwhip) to the widget that produces fit.
CharArea needed
Area decided if FIT or min. area needed if FLEXFIT.
static void printIfTrace(Trace::Type trace, const std::string &tr)
The same as printTrace() but only print if any of TRACE is active.
int result
One of the possible result values.
static const std::string kTraceBegin
< Add TRACES to the currently active traces (initially none).
bool isMouseUnclick(void) const noexcept
< Return TRUE if the event is an unclick of the mouse.
ChainEventResult(int r)
Constructor for event that does not know yet the leaf widget.
void assign(Widget *wi, AreaFitting &&oaf)
bool isMouseMove(void) const noexcept
< Return TRUE if the event is a motion of the mouse.
EventData(void)
Default constructor: FOCUS_LOST.
CharArea provided
Area that was provided for the calculation.
Widget & operator=(Widget &&)=delete
Constructor.
bool hasPressedKey(DesktopInterface::KeyID k) const noexcept
Return TRUE for parameters indicating KEY has been pressed.
ContainerWidget(ID id, const std::string &name, CCType cctype=CCType::USER, OrType ortype=OrType::VERTICAL, FMType foctype=FMType::NORMAL, bool withframe=false, const std::string &title="", HorAlign hal=HorAlign::LEFT, VertAlign val=VertAlign::TOP, const std::string &tooltiptext="")
Constructor.
std::vector< AreaFitting > Vector
Several, ordered fittings.
A container of other widgets.
All widgets must inherit from this.
Definition: ZXWidgetsBase.h:56
A vector of ptrs to widgets.
Definition: ZXWidgetsBase.h:78
A path in the widget tree.
Definition: ZXWidgetsBase.h:96
int ID
A numeric ID associated to the widget.
Definition: ZXWidgetsBase.h:67
std::shared_ptr< Widget > Ptr
A polymorphic ptr to a widget.
Definition: ZXWidgetsBase.h:74
TravResult
Possible results of observer when traversing widgets in the widget tree.
std::function< TravResult(Widget &) > TraverseObserver
Information about the fitting of widgets drawings into rectangular areas.
A class to contain the parameters received by a callback routine.
Result of chaining an event, i.e., flowing it through the widget tree.
Data passed to a widget when an event occurs.
Kinds of tracings that can be activated in the whole widget system.
A window on the screen.
Definition: ZXWindows.h:50
std::string nonCtrlString(const std::string &txt, char who='A')
Return a version of TXT without control codes.
uint16_t CharCoord
Represent both x and y screen char coordinates.
Definition: ZXGraphics.h:94
int16_t IntDist
Positive and negative distances on screen.
Definition: ZXGraphics.h:99
Rect align_area(const area_type &areaneeded, char horalign, char vertalign) const
Return the portion of this rectangle that contains AREANEEDED aligned.
Definition: ZXGraphics.h:1628
uint16_t CharDist
A distance meadured in screen chars.
Definition: ZXGraphics.h:97
bool buttonright
State (TRUE->pressed) of main buttons.
Definition: ZXPointing.h:45
bool buttonleft
State (TRUE->pressed) of main buttons.
Definition: ZXPointing.h:45
Status of the pointing device.
Definition: ZXPointing.h:39
The class that provides the main support for managing the ZX screen.
Definition: ZXScreen.h:89
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31