AWind
TextBoxNumber.h
1 /*
2  AWind.h - Arduino window library support for Color TFT LCD Boards
3  Copyright (C)2015 Andrei Degtiarev. All right reserved
4 
5 
6  You can always find the latest version of the library at
7  https://github.com/AndreiDegtiarev/AWind
8 
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the CC BY-NC-SA 3.0 license.
12  Please see the included documents for further information.
13 
14  Commercial use of this library requires you to buy a license that
15  will allow commercial use. This includes using the library,
16  modified or not, as a tool to sell products.
17 
18  The license applies to all part of the library including the
19  examples and tools supplied with the library.
20 */
21 #pragma once
22 #include "TextBox.h"
24 class TextBoxNumber : public TextBox
25 {
26  float _number;
27  bool _isOK;
28  int _precission;
29  bool _isReadOnly;
30 public:
32 
39  TextBoxNumber(int left=0,int top=0,int width=0,int height=0,int precission=0):TextBox(left,top,width,height)
40  {
41  _precission=precission;
42  _isOK=true;
43  _number=0;
44  SetFont(BigFont);
45  SetDecorators(Environment::Get()->FindDecorators(F("EditTextBoxReadOnly")));
46  SetMargins(0,1);
47  SetIsReadOnly(true);
48  }
50  int Precission()
51  {
52  return _precission;
53  }
54  void SetPrecission(int precission)
55  {
56  _precission=precission;
57  }
58  bool IsAwaitTouch()
59  {
60  return !_isReadOnly||TextBox::IsAwaitTouch();
61  }
62  bool OnTouch(int x,int y);
64  void SetIsReadOnly(bool isReadOnly)
65  {
66  SetDecorators(Environment::Get()->FindDecorators(isReadOnly?F("EditTextBoxReadOnly"):F("EditTextBox")));
67  _isReadOnly=isReadOnly;
68  }
69  bool IsReadOnly()
70  {
71  return _isReadOnly;
72  }
74  void SetNumber(float number)
75  {
76  if(_number!=number)
77  {
78  _number = number;
79  if(_changedEvent!=NULL)
80  _changedEvent->NotifyContentChanged(this);
81  Invalidate();
82  }
83  }
84  float GetNumber()
85  {
86  return _number;
87  }
88  void SetStatus(bool isOK)
89  {
90  _isOK = isOK;
91  }
93  virtual void OnDraw(DC *dc)
94  {
95  TextBox::OnDraw(dc);
96  if(_isOK)
97  {
98  dc->DrawNumber(_number,_precission,_offset_x,_offset_y);
99  }
100  }
101 };
int Precission()
Returns actual number of digits after decimal point.
Definition: TextBoxNumber.h:50
virtual bool IsAwaitTouch()
Returns true if window await touch action (like button) or false if touch manager should ignore this ...
Definition: Window.h:107
void SetFont(uint8_t *font)
Sets font.
Definition: TextBox.h:64
void SetIsReadOnly(bool isReadOnly)
Defines whether window is readonly.
Definition: TextBoxNumber.h:64
Base class for window with text content.
Definition: TextBox.h:30
bool OnTouch(int x, int y)
Touch manager calls this function right after touch is released.
Definition: TextBoxNumber.cpp:25
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
void DrawNumber(int number, int x, int y)
Draws integer number. Input coordinates have to be defined in the window coordinate system...
Definition: DC.h:161
Text box for numbers.
Definition: TextBoxNumber.h:24
virtual void OnDraw(DC *dc)
Implements drawing code.
Definition: TextBoxNumber.h:93
TextBoxNumber(int left=0, int top=0, int width=0, int height=0, int precission=0)
Constructor.
Definition: TextBoxNumber.h:39
Device context. Abstraction layer to the device specific drawing code. Coordinates in drawing functio...
Definition: DC.h:29
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
void OnDraw(DC *dc)
Implements drawing code.
Definition: TextBox.h:69
virtual void NotifyContentChanged(Window *window)=0
Has to be implemented in target class.
void SetNumber(float number)
Initialize window with number.
Definition: TextBoxNumber.h:74
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
bool IsAwaitTouch()
Returns true if window await touch action (like button) or false if touch manager should ignore this ...
Definition: TextBoxNumber.h:58
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58