-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTextView.cpp
More file actions
61 lines (47 loc) · 1.26 KB
/
TextView.cpp
File metadata and controls
61 lines (47 loc) · 1.26 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
#include "TextView.hpp"
#include <cmath>
#include "Assets.hpp"
void TextView::doMeasure(Measure wm, Measure hm){
measuredWt = wm;
measuredHt = hm;
int iW, iH;
painter->getTextSize(text, iW,iH);
int ht = iH;
int wt = iW;
ht += mTopPad + mBottomPad;
wt += mLeftPad + mRightPad;
measuredWt.value = resolveSize(wt, wm);
measuredHt.value = resolveSize(ht, hm);
}
void TextView::doLayout(bool , int ,int ,int ,int ){
}
void TextView::doDraw(Canvas& c){
int x,y;
c.getCurrentWorldXY(x,y);
c.drawText(text, x, y, getWidth(), getHeight(),textColor,painter);
}
bool TextView::dispatchTextEnteredEvent(TextEvent* tevent){
auto code = tevent->code;
if(code == "\b"){
if(text.size() > 0)
text.pop_back();
}
else
text += code;
return true;
}
bool TextView::dispatchKeyEvent(KeyEvent* event){
if(event->kind == KeyEvent::Kind::PRESSED)
if(event->code == KeyCode::Down)
requestUnFocus(FocusDirection::DOWN);
else if (event->code == KeyCode::Up)
requestUnFocus(FocusDirection::UP);
else if (event->code == KeyCode::BackSpace)
if(text.size()>0) text.pop_back();
return true;
}
std::unique_ptr<TextView> TextView::make(std::string data){
auto tv = std::make_unique<TextView>();
tv->setText(data);
return tv;
}