-
Notifications
You must be signed in to change notification settings - Fork 13
/
uboxes.cpp
362 lines (310 loc) · 9.38 KB
/
uboxes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/************************************************************************
*
* uboxes.cpp : misc containers.
* Ubit GUI Toolkit - Version 6
* (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
*
* ***********************************************************************
* COPYRIGHT NOTICE :
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
* IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
* YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
* GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
* EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
* SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
* ***********************************************************************/
#include <ubit/ubit_features.h>
#include <iostream>
#include <ubit/uon.hpp>
#include <ubit/uboxgeom.hpp>
#include <ubit/ubackground.hpp>
#include <ubit/uboxes.hpp>
#include <ubit/ucolor.hpp>
#include <ubit/upix.hpp>
#include <ubit/ucall.hpp>
#include <ubit/uborder.hpp>
#include <ubit/uinteractors.hpp>
#include <ubit/ulistbox.hpp>
#include <ubit/uscrollpane.hpp>
#include <ubit/uupdatecontext.hpp>
using namespace std;
#define NAMESPACE_UBIT namespace ubit {
NAMESPACE_UBIT
// ==================================================== [Ubit Toolkit] =========
/* UVbox = vertical Box.
* Geometry: see class UBox for details.
*
class UVbox: public UBox {
public:
UCLASS("uvbox", UVbox, new UVbox)
UVbox(UArgs args = UArgs::none) : UBox(args) {}
///< creates a new vertical box; @see also shortcut: uvbox().
static UStyle* createStyle();
};
* UHbox = horizontal Box.
* Geometry: see class UBox for details.
*
class UHbox: public UBox {
public:
UCLASS("uhbox", UHbox, new UHbox)
UHbox(UArgs args = UArgs::none) : UBox(args) {}
///< creates a new horizontal box; @see also shortcut: uhbox().
static UStyle* createStyle();
};
UStyle* UHbox::createStyle() {
UStyle* style = new UStyle();
style->textSeparator = &ustr(" ");
style->orient = UOrient::HORIZONTAL;
style->halign = UHalign::LEFT;
style->valign = UValign::FLEX;
style->hspacing = 1;
style->vspacing = 1;
style->local.padding.set(0,0);
return style;
}
UStyle* UVbox::createStyle() {
UStyle* style = new UStyle();
style->textSeparator = &ustr("\n");
style->orient = UOrient::VERTICAL;
style->halign = UHalign::FLEX;
style->valign = UValign::TOP;
style->hspacing = 1;
style->vspacing = 1;
//style->local.vmargin = 0; style->local.hmargin = 0;
style->local.padding.set(0,0);
return style;
}
*/
// ==================================================== [Ubit Toolkit] =========
UStyle* UBar::createStyle() {
UStyle* s = new UStyle;
s->textSeparator = &ustr("\t");
s->orient = UOrient::HORIZONTAL;
s->halign = UHalign::LEFT;
s->valign = UValign::FLEX;
s->hspacing = 4;
s->vspacing = 5;
s->local.padding.set(5,2);
s->local.border = &UBorder::shadowOut;
return s;
}
UStyle* UStatusbar::createStyle() {
UStyle* s = new UStyle();
s->textSeparator = &ustr("\t");
s->orient = UOrient::HORIZONTAL;
s->halign = UHalign::LEFT;
s->valign = UValign::FLEX;
s->hspacing = 2;
s->vspacing = 2;
s->local.padding.set(6,2); //tb,lr
s->local.border = &UBorder::shadowIn;
return s;
}
// ==================================================== [Ubit Toolkit] =========
UStyle* UFlowbox::createStyle() {
UStyle& s = *new UStyle();
s.viewStyle = &UFlowView::style;
s.textSeparator = new UStr("\n");
s.orient = UOrient::HORIZONTAL;
s.halign = UHalign::FLEX;
s.valign = UValign::FLEX;
s.hspacing = 1;
s.vspacing = 1;
s.local.padding.set(0,0);
// width does not depend on content, but height does! otherwise the box could
// not grow vertically when children are added or resized (for instance the
// height of a text flow could not grow)
s.local.size.width = -1; // -1 means "keep initial size"
return &s;
}
UFlowbox::UFlowbox(UArgs a): UBox(a) {
emodes.IS_TEXT_SELECTABLE = true;
}
// ==================================================== [Ubit Toolkit] =========
UStyle* UCardbox::createStyle() {
UStyle& s = *new UStyle();
s.viewStyle = &UPaneView::style;
s.orient = UOrient::HORIZONTAL;
s.halign = UHalign::FLEX;
s.valign = UValign::FLEX;
s.hspacing = 1;
s.vspacing = 1;
s.local.padding.set(0,0);
//surtout ne pas faire cela: les cards n'apparaissent pas a pas celle qui
//est selectionnee au debut (ou si on est en flex)
//s.local.size.width = -1; // -1 means "keep initial size"
//s.local.size.height = -1;
return &s;
}
UCardbox::UCardbox(UArgs args) : UBox(args), ptabs(new UListbox())
{
ptabs->addAttr(ucall(this, &UCardbox::setSelectedImpl)
+ UOrient::horizontal + uhflex() + uvflex()
+ upadding(0,0) + UBackground::none + UBorder::none);
setAttr(*new UCompositeBorder(utop() + uhcenter() + *ptabs));
}
UCardbox::~UCardbox() {}
UChoice& UCardbox::choice() {return ptabs->choice();}
void UCardbox::setSelectedImpl() {
int index = ptabs->choice().getSelectedIndex();
int ix = 0;
for (UChildIter i = cbegin(); i != cend(); ++i) {
UBox* card = dynamic_cast<UBox*>(*i);
if (card) {
if (ix == index) card->show(true);
else card->show(false);
ix++;
}
}
}
UCardbox& UCardbox::addCard(UBox& card) {
addTab(UArgs::none, card);
return *this;
}
UCardbox& UCardbox::addTab(UArgs title, UBox& card) {
if (&title != &UArgs::none) ptabs->add(utabbutton(title));
else ptabs->add(uitem());
add(card);
setSelectedIndex(-1);
return *this;
}
UBox* UCardbox::getCard(int index) const {
int ix = 0;
for (UChildIter i = cbegin(); i != cend(); ++i) {
UBox* c = dynamic_cast<UBox*>(*i);
if (c && ix == index) return c;
ix++;
}
return null;
}
int UCardbox::getCardIndex(UBox& card) const {
int ix = 0;
for (UChildIter i = cbegin(); i != cend(); ++i) {
UBox* c = dynamic_cast<UBox*>(*i);
if (c == &card) return ix;
ix++;
}
return -1;
}
UBox* UCardbox::getSelectedCard() const {
int index = ptabs->choice().getSelectedIndex();
if (index >= 0) return getCard(index);
return null;
}
void UCardbox::setSelectedCard(UBox& card) {
int ix = getCardIndex(card);
if (ix >= 0) setSelectedIndex(ix);
}
int UCardbox::getSelectedIndex() const {
return ptabs->choice().getSelectedIndex();
}
void UCardbox::setSelectedIndex(int index) {
ptabs->choice().setSelectedIndex(index);
}
//UBox* UCardbox::getTab(int index) const {
// return ptabs->choice().getSelectableItem(index);
//}
//UBox* UCardbox::getSelectedTab() const {
// return ptabs->choice().getSelectedItem();
//}
//void UCardbox::setSelectedTab(UBox* tab) {
// ptabs->choice().setSelectedItem(tab);
//}
/*
UCardbox& UCardbox::setComboMode(bool cm) {
UBorder* border = getBorder(true); // true => create border if needed
//cerr <<"border "<<border<<" " <<border->getSubGroup()<<endl;
if (border->getSubGroup()) border->getSubGroup()->removeAll();
if (cm) {
ptabs->removeAllAttrs();
ptabs->addAttr(ptabs->choice());
border->add(utop() + uhcenter() + ucombobox(*ptabs));
}
else {
ptabs->addAttr(UOrient::horizontal);
ptabs->addAttr(uhspacing(0));
ptabs->addAttr(uhmargin(1));
ptabs->addAttr(uvmargin(1));
ptabs->addAttr(UBorder::none);
ptabs->addAttr(UBgcolor::none);
ptabs->addAttr(uhflex());
ptabs->addAttr(uvflex());
border->add(utop() + uhcenter() + *ptabs);
}
return *this;
}
*/
// ==================================================== [Ubit Toolkit] =========
// NB: ex: class UDocbox : public UVbox
UDocbox::UDocbox(UArgs args) {
zoom_quantum = 1.166;
ptitlebar = uhbox();
pscale = new UScale;
pcontent = uvbox(args);
pcontent->addAttr(*pscale);
pspane = uscrollpane(true, false);
pspane->add(*pcontent);
addAttr(UOrient::vertical + utop());
add(uhflex() + utop() + *ptitlebar + uvflex() + *pspane);
}
UDocbox::~UDocbox() {}
void UDocbox::zoom(float z) {
*pscale = z;
}
void UDocbox::zoomIn() {
pscale->mult(zoom_quantum);
}
void UDocbox::zoomOut() {
pscale->div(zoom_quantum);
}
void UDocbox::setZoomQuantum(float zq) {
zoom_quantum = zq;
}
bool UDocbox::isIconified() const {
return pspane->isShown();
}
void UDocbox::iconify(bool state) {
pspane->show(!state);
//piconify_btn->select(state);
}
// ==================================================== [Ubit Toolkit] =========
UAlertbox::UAlertbox(UArgs args) {
add(UOrient::vertical + UBackground::white + ualpha(0.8)
+ uhcenter() + uvcenter()
+ UFont::bold + UFont::large
+ args
+ UOn::action / ushow(*this, false)
+ uhbox(uscale(1.5) + UFont::xx_large
+ UPix::ray + UColor::red + " Alert! ")
+ " "
+ " "
+ " "
+ uhflex() // necessaire sinon affiche un mot par ligne!
+ uflowbox(UFont::x_large + UColor::navy + uhcenter() + message)
+ " "
+ " "
+ " "
+ uhcenter()
+ ubutton(uscale(1.25) + UFont::x_large + ualpha(0.6)
+ " OK " + ushow(*this, false))
);
}
UStyle* UAlertbox::createStyle() {
UStyle*s = UBox::createStyle();
s->orient = UOrient::VERTICAL;
return s;
}
void UAlertbox::showMsg(const UStr& msg) {
message.removeAll();
message.add(ustr(msg));
update();
UBox::show();
}
//void UAlertbox::showMsg(const UStr* msg) {if (msg) showMsg(*msg);}
void UAlertbox::showMsg(const char* msg) {
message.removeAll();
message.add(ustr(msg));
update();
UBox::show();
}
}