forked from AndreiDegtiarev/AWind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardWindow.h
144 lines (136 loc) · 4.49 KB
/
KeyboardWindow.h
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
#pragma once
/*
GUI library for Arduino TFT and OLED displays
Copyright (c) 2014-2018 Andrei Degtiarev
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You may
obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
*/
#include "TextBoxNumber.h"
#include "TextBoxString.h"
#include "IDialogClosedEventReceiver.h"
#include "DecoratorPrimitives.h"
#include "Dialog.h"
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
///Implements Keyboard window, that helps to enter text/number information into text fields
class KeyboardWindow : public Dialog
{
//TextBoxNumber *_targetTextBox;
TextBoxString * _editField;
TextBoxNumber _digidWindows[10];
TextBoxFString * _pointSymbol;
TextBoxFString * _backspaceSymbol;
char _editBuffer[15];
int _editPosition;
const static int _buttonSize=39;
const static int _buttonDistance=5;
const static int _textOffset=9;
public:
///Constructor
/**
\param left left coordinate relative to screen
\param top top coordinate relative to screen
*/
KeyboardWindow(int left,int top):Dialog(left,top,7*(_buttonSize+_buttonDistance)+_buttonDistance,3*(_buttonSize+_buttonDistance)+_buttonDistance)
{
int x=_buttonDistance;
int y=_buttonDistance;
_editField=new TextBoxString(x,y,Width()-2*_buttonDistance,_buttonSize,"");
_editField->SetDecorators(Environment::Get()->FindDecorators(F("EditTextBoxReadOnly")));
_editField->SetFont(BigFont);
y+=_buttonSize+_buttonDistance;
_backspaceSymbol=new Button(5*(_buttonSize+_buttonDistance)+_buttonDistance,y,_buttonSize,_buttonSize,F("<-"));
_btnOK=new Button(6*(_buttonSize+_buttonDistance)+_buttonDistance,y,_buttonSize,_buttonSize,F("E"));
DecoratorList * btnDecorators=Environment::Get()->FindDecorators(F("Button"));
for(int i=0;i<10;i++)
{
x=(i-(i<5?0:5))*(_buttonSize+_buttonDistance);
if(i==5)
y+=_buttonSize+_buttonDistance;
//_digidWindows[i]=new TextBoxNumber(x+_buttonDistance,y,_buttonSize,_buttonSize,0);
_digidWindows[i].Move(x+_buttonDistance,y,_buttonSize,_buttonSize);
_digidWindows[i].SetNumber(i);
_digidWindows[i].SetDecorators(btnDecorators);
initTextBox(&_digidWindows[i]);
}
_pointSymbol=new Button(5*(_buttonSize+_buttonDistance)+_buttonDistance,y,_buttonSize,_buttonSize,F("."));
_btnCancel=new Button(6*(_buttonSize+_buttonDistance)+_buttonDistance,y,_buttonSize,_buttonSize,F("C"));
initTextBox(_editField);
initTextBox(_backspaceSymbol);
_backspaceSymbol->SetMargins(_textOffset,_textOffset*1.5);
_backspaceSymbol->SetFont(SmallFont);
initTextBox(_pointSymbol);
initTextBox(_btnCancel);
initTextBox(_btnOK);
}
protected:
void initTextBox(TextBox *text)
{
text->SetMargins(_textOffset,_textOffset);
text->RegisterTouchEventReceiver(this);
AddChild(text);
}
public:
///Initializes edit field with float value of desired precission
void Initialize(float value,int precision)
{
_editPosition=0;
dtostrf(value,0,precision,_editBuffer);
_editField->SetText(_editBuffer);
_editField->Invalidate();
_editPosition=strlen(_editBuffer);
}
///Returns number from edit window
float GetNumber()
{
return atof(_editBuffer);
}
///Process touch message from child controls
void DoControlMessage(Window *window)
{
//out<<F("Keybord notify")<<endln;
//if(Process_OK_Cancel_Touch(window))
// return;
/*if(window == _enterSymbol || window == _cancelSymbol)
{
if(_dialogClosedEventReceiver!=NULL)
_dialogClosedEventReceiver->NotifyDialogClosed(this,window == _enterSymbol?IDialogClosedEventReceiver::OK:IDialogClosedEventReceiver::Cancel);
}
else*/
{
bool needUpdate=false;
if(window == _backspaceSymbol && _editPosition>0)
{
_editPosition--;
_editBuffer[_editPosition]=0;
needUpdate=true;
}
else if(window == _pointSymbol && _editPosition<14)
{
_editBuffer[_editPosition++]='.';
_editBuffer[_editPosition]=0;
needUpdate=true;
}
else
{
for(int i=0;i<10;i++)
if(window == &_digidWindows[i] && _editPosition<14)
{
_editBuffer[_editPosition++]='0'+i;
_editBuffer[_editPosition]=0;
needUpdate=true;
break;
}
}
if(needUpdate)
_editField->SetText(_editBuffer);
}
}
};