The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXWidgetComboBox.h
Go to the documentation of this file.
1
2/* **************************************************************************/
19#ifndef ZXWIDGET_COMBOBOX
20#define ZXWIDGET_COMBOBOX
21
22#include <memory>
26
27
28namespace zxeco
29{
30
31namespace gui
32{
33
34
35/*******************************************************************************
36*
37* Class: ComboBoxWidget
38*
39*******************************************************************************/
40
42
44{
45 public:
46
47 ComboBoxWidget(ID id, const std::string & name,
48 const LabelList & l, const std::string & inittext = "",
49 CharDist maxwidths = 0, bool editable = false,
50 bool showing = true, bool deploybutton = true,
51 const std::string & tooltiptext = "",
52 HorAlign hal = HorAlign::LEFT,
53 VertAlign val = VertAlign::TOP);
55
77 const std::string & text(void) const noexcept { return(pwedit_->text()); }
79
80 const LabelList & list(void) const { return(*pllist_); }
81
82 size_t lastSelected(void) const noexcept { return(lastselected_); }
84
88 void clearLastSelected(void) { lastselected_ = pllist_->size(); }
90
93 void setSelected(const std::string & txt);
97 void setSelected(size_t ind);
101 bool processedByEditing(const CallbackParms & cbps) const noexcept
103 { return((cbps.whoprocessed != nullptr) &&
104 (cbps.whoprocessed->isDescendantOf(*pwedit_))); }
105
106 bool itemLeftClicked(const CallbackParms & cbps) const noexcept
108 { return(cbps.hasBeenLeftClicked() && (!processedByEditing(cbps))); }
109
110 bool itemLeftClickedOrEnter(const CallbackParms & cbps) const noexcept
112 { return(itemLeftClicked(cbps) || cbps.hasPressedEnter()); }
114
115 const char * className(void) const noexcept { return("ComboBoxWidget"); }
116
117
118 private:
119
120 enum Subwidgs {
121 LINE_EDIT = 0,
122 DEPLOY_BUTTON,
123 NUMSUBWIDGETS
124 };
125
126 enum WinPlacement {
127 PARENT_VERTICAL,
128 PARENT_HORIZONTAL
129 };
130
131 static const uint8_t kUDGs[1*8];
132 static const ID kIDsSubs[NUMSUBWIDGETS];
133 static const ID kIDListInWin;
134
135 const bool editable_;
136 const bool showing_;
137 const std::unique_ptr<LabelList> pllist_;
138 const size_t maxlenlist_;
139
140 LineInputWidget * pwedit_;
141 ButtonWidget * pwdeploy_;
142 size_t lastselected_;
143 std::string prevtext_;
144
145 void drawRaw(void);
146 int processEvent(const EventData & evdata, Widget * who) override;
147 CharRect calcPosList(const LabelList & llist,
148 const CharRect & parentarea,
149 WinPlacement placement,
150 CharArea & dimslist) const;
151 Window::MngResult openAndManageList(const LabelList & llist,
152 const CharRect & parea,
153 WinPlacement placement,
154 LabelList::Iterator & it,
155 std::unique_ptr<Window> & pwinlist);
156 Window::MngResult askUserSelection(void);
157};
158
159
160
161} // end namespace gui
162} // end namespace zxeco
163
164#endif
165 // ZXWidgetComboBox
167
168
169
A list of labels to be displayed vertically, with possible marks on them.
Definition: ZXGUIGeneral.h:231
HorAlign
Horizontal alignment of widgets within the areas of their containers.
VertAlign
Vertical alignment of widgets within the areas of their containers.
A container of other widgets.
int ID
A numeric ID associated to the widget.
Definition: ZXWidgetsBase.h:67
A class to contain the parameters received by a callback routine.
const std::string & text(void) const noexcept
Return the text currently in the line.
bool processedByEditing(const CallbackParms &cbps) const noexcept
< Return TRUE if the event of CBPS was processed in the edition zone.
ComboBoxWidget(ID id, const std::string &name, const LabelList &l, const std::string &inittext="", CharDist maxwidths=0, bool editable=false, bool showing=true, bool deploybutton=true, const std::string &tooltiptext="", HorAlign hal=HorAlign::LEFT, VertAlign val=VertAlign::TOP)
Constructor.
void clearLastSelected(void)
Clear the last selected element.
const char * className(void) const noexcept
Must return a text with the name of the class.
void setSelected(const std::string &txt)
Set the given text as the selection in the edit area.
const std::string & text(void) const noexcept
Return the current text in the editing zone.
bool itemLeftClickedOrEnter(const CallbackParms &cbps) const noexcept
< Return TRUE if the event of CBPS is a click on the list or an enter.
size_t lastSelected(void) const noexcept
Return the index in the list of the element that was selected last time.
bool itemLeftClicked(const CallbackParms &cbps) const noexcept
< Return TRUE if the event of CBPS is a click on the list.
A widget that allows the user to select one from a deployable list, and edit.
MngResult
Possible results of calling the manage() method.
Definition: ZXWindows.h:114
Area< CharDistT, CharDistT > CharArea
Shortcut for this kind of area.
Definition: ZXGraphics.h:605
Rect< CharDistT, CharDistT > CharRect
Shortcut for this kind of rectangle.
Definition: ZXGraphics.h:735
uint16_t CharDist
A distance meadured in screen chars.
Definition: ZXGraphics.h:97
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31