-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.cpp
More file actions
72 lines (56 loc) · 1.86 KB
/
popup.cpp
File metadata and controls
72 lines (56 loc) · 1.86 KB
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
#include "popup.h"
#include "color.h"
#include "nanovg.h"
#include "rectangle.h"
Popup::Popup(Item *parent, float x, float y, float width, float hieght):
Item(parent, x, y, width, hieght)
{
visible = false;
}
void Popup::show(Item *anchorItem, Item *content, Color backgroundColor) {
while(childCount() > 0)
removeChild(childAt(0));
mBackgroundColor = backgroundColor;
mAnchorItem = anchorItem;
addChild(content);
content->performLayout();
width = content->width();
hieght = content->hieght();
float ax, ay;
anchorItem->absolutePosition(&ax, &ay);
x = ax - width() + mAnchorItem->width() - 2;
y = ay + anchorItem->hieght();
//content->hieght.on_change().connect([=](float h) { hieght = h;});
parent()->bringChildToFront(this);
visible = true;
}
void Popup::hide() {
visible = false;
//while(childCount() > 0)
// removeChild(childAt(0));
}
void Popup::draw(NVGcontext *vg) {
const int radius = 4;
Rectangle::drawRect(vg, x(), y(), width(), hieght(), radius, mBackgroundColor);
Item::draw(vg);
nvgSave(vg);
auto shadowPaint = nvgBoxGradient(vg, x(),y()+2, width(),hieght(), radius*2, 10, nvgRGBA(0,0,0,25), nvgRGBA(0,0,0,0));
nvgBeginPath(vg);
nvgRect(vg, x()-10,y()-10, width()+20,hieght()+30);
nvgRoundedRect(vg, x(),y(), width(),hieght(), radius);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, shadowPaint);
nvgFill(vg);
Rectangle::drawRect(vg, x(), y(), width(), hieght(), radius, 0x0);
nvgStrokeColor(vg, Color(0xDFDFDFFF).vgColor());
nvgStrokeWidth(vg, 1);
nvgStroke(vg);
nvgBeginPath(vg);
float baseX = x() + width() - 30;
nvgMoveTo(vg, baseX, y()+1);
nvgLineTo(vg, baseX + 10, y() - 11);
nvgLineTo(vg, baseX + 20, y()+1);
nvgFillColor(vg, mBackgroundColor.vgColor());
nvgFill(vg);
nvgRestore(vg);
}