Phoenard
PHNNumberBox.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include "PHNWidget.h"
32 #include "PHNScrollbar.h"
33 
34 #ifndef _PHN_NUMBERBOX_H_
35 #define _PHN_NUMBERBOX_H_
36 
49 class PHN_NumberBox : public PHN_Widget, public PHN_TextContainer {
50 public:
52  PHN_NumberBox();
54  void setRange(int minValue, int maxValue);
56  int minValue() const { return _minValue; }
58  int maxValue() const { return _maxValue; }
60  void addValue(int increment);
62  void setValue(int value);
64  int value() { return scroll.value(); }
66  bool isValueChanged() const { return _valueChanged; }
68  void setWrapAround(bool wrapAround);
70 
81  char wrapAroundIncrement() const { return _lastWrapAround; }
82 
83  virtual void setTextRaw(const char* text, int textLen);
84  virtual const char* text() { return textBuff.text(); }
85  virtual void draw(void);
86  virtual void update(void);
87 
88 private:
89  TextBounds getTextBounds();
90  void drawText(TextBounds bounds);
91 
92  int _minValue, _maxValue;
93  bool _firstUpdate;
94  bool _valueChanged;
95  char _lastWrapAround;
96  int scrollWidth;
97  bool wrapAround;
98  bool textDirty;
99  TextBounds lastTextBounds;
100  DataBuffer textBuff;
101  PHN_Scrollbar scroll;
102 };
103 
104 #endif
Struct to hold the information for drawing text inside an area.
Definition: PHNDisplay.h:83
bool isValueChanged() const
Gets whether the value was changed.
Definition: PHNNumberBox.h:66
int value()
Gets the current value.
Definition: PHNNumberBox.h:64
virtual void setTextRaw(const char *text, int textLen)
Sets the new text to display using a buffer and length.
Definition: PHNNumberBox.cpp:36
PHN_NumberBox()
Initializer.
Definition: PHNNumberBox.cpp:28
Abstraction for a widget that can store and update text.
Definition: PHNTextContainer.h:41
Maintains data stored on the heap and frees it when the class is destructed.
Definition: DataBuffer.h:44
virtual const char * text()
Gets the text displayed.
Definition: DataBuffer.h:62
void setWrapAround(bool wrapAround)
Sets whether the value wraps around.
Definition: PHNNumberBox.cpp:83
virtual const char * text()
Gets the text displayed.
Definition: PHNNumberBox.h:84
Contains the PHN_Scrollbar widget; a widget for a bar that can be dragged.
virtual void draw(void)
Draw function routine, where widgets must perform drawing.
Definition: PHNNumberBox.cpp:129
int maxValue() const
Gets the range maximum value.
Definition: PHNNumberBox.h:58
int minValue() const
Gets the range minimum value.
Definition: PHNNumberBox.h:56
A single widget which covers a rectangular area of the screen.
Definition: PHNWidget.h:145
char wrapAroundIncrement() const
Gets last wrap-around increment performed.
Definition: PHNNumberBox.h:81
void setValue(int value)
Sets the current value.
Definition: PHNNumberBox.cpp:45
void addValue(int increment)
Increments or decrements the value.
Definition: PHNNumberBox.cpp:41
Holds the PHN_Widget and PHN_WidgetContainer classes used for managing widgets.
virtual void update(void)
Update function routine, where widget logic must be performed.
Definition: PHNNumberBox.cpp:94
void setRange(int minValue, int maxValue)
Sets the minimum and maximum range of the value.
Definition: PHNNumberBox.cpp:73
The numberbox widget can be scrolled by the user to change between integer values.
Definition: PHNNumberBox.h:49
const int value(void)
Gets the scrollbar value.
Definition: PHNScrollbar.h:60
Shows a scroll bar the user can drag.
Definition: PHNScrollbar.h:47