ButtonView¶
- class
A Push Button UI Widget.
This is a common state-less push button. It is basically a bordered text label. This button reacts to touch input (pushes) and can call a function when it is pushed.
You provide the button with a callback function, that gets called when the button is pushed. A valid button push is a touch that begins and ends within the button boundaries. If a touch begins inside the buttons boudaries, but ends outside - the button click callback is not triggered.
You define the button dimensions by the Rect you provide in the constructor. Note that the resistive touch panel is not that precise, you should not create buttons smaller than 40x35 pixels. Also note that buttons do not automatically scale, when you set their text content.
Example
// Create the button (should normally be defined as a class member) mono::ui::ButtonView btn(mono::geo::Rect(10,10,100,35), "Push Here") // Setup a click handler btn.setClickCallback<MyClass>(this, &MyClass::MyClickHandler); // show the button on the screen btn.show();
Public Functions
-
ButtonView::
ButtonView
()¶ Construct an empty button.
The button will have zero dimensions and no text.
-
ButtonView::
ButtonView
(geo::Rect rect, String text)¶ Construct a button with dimensions and text.
Creates a button with the provided dimensions and text to display. You still need to setup a callback and call show.
- Parameters
rect
-The view rect, where the button is displayed
text
-The text that is showed on the button
-
ButtonView::
ButtonView
(geo::Rect rect, const char *text)¶ Construct a button with dimensions and text.
Creates a button with the provided dimensions and text to display. You still need to setup a callback and call show.
- Parameters
rect
-The view rect, where the button is displayed
text
-The text that is showed on the button
-
void
ButtonView::
setText
(String txt)¶ Set the text content.
Sets the text that is displayed on the button. Note that the width and height of the button is not changed. You must change the buttons viewRect if your text is larger than the buttons dimensions.
When you set new text content, the button is automatically repainted
- Parameters
txt
-The new text content
-
void
mono::ui::ButtonView::
setFont
(MonoFont const &newFont)¶ Change the button fontface (font family and size)
You can change the buttons font to use a larger (or smaller) font.
-
void
mono::ui::ButtonView::
setFont
(GFXfont const &newFont)¶ Change the buttons fontface (font family and size)
You can change the buttons font to use a larger (or smaller) font.
- Parameters
newFont
-The font face to render the text content with
-
void
ButtonView::
setBorder
(Color c)¶ Sets the border color.
This method will not schedule repaint! You must scheduleRepaint manually.
- Parameters
c
-The new border color
-
void
ButtonView::
setText
(Color c)¶ Sets the text color.
This method will not schedule repaint! You must scheduleRepaint manually.
- Parameters
c
-The new text color
-
void
ButtonView::
setHighlight
(Color c)¶ Sets the highlight color (border & text)
The highlight color is the color used to represented a button that is currently being pushed. This means that a touch event has started inside its boundaries. The highlight color is applied to both border and text.
This method will not schedule repaint! You must scheduleRepaint manually.
- Parameters
c
-The new highlight color
-
void
ButtonView::
setBackground
(Color c)¶ Sets the background color.
The background color of the fill color inside the button bounding rectangle.
This method will not schedule repaint! You must scheduleRepaint manually.
- Parameters
c
-The new border and text color
-
virtual void
ButtonView::
setRect
(geo::Rect rect)¶ Set the view’s position and size, by providing a rectangle object.
Note that this method does not repaint the view, you must do that explicitly.
- Parameters
rect
-The view rectangle, containing size and position
-
const TextLabelView &
ButtonView::
TextLabel
()¶
const Get a reference to the internal TextLabel object.
You get a
const
reference to the button internal TextLabelView
- template <typename Owner>
-
void mono::ui::ButtonView::setClickCallback(Owner * obj, void(Owner::*)(void) memPtr)
Attach a member function as the button click handler.
Provide the callback member function you ewant to be called when the button is clicked.
NOTE: THere can only be one callback function
- Parameters
obj
-A pointer to the object where the callback method exists
memPtr
-A pointer to the callback method itself
-
void
mono::ui::ButtonView::
setClickCallback
(void (*memPtr)(void))¶ Attach a C function pointeras the button click handler.
Provide a pointer to the callback C function, you ewant to be called when the button is clicked.
NOTE: THere can only be one callback function.
- Parameters
memPtr
-A pointer to the C function callback
-
virtual void
ButtonView::
repaint
()¶ Painters.
-