ButtonView¶
-
class
mono::ui::
ButtonView
¶ A Push Button UI Widget.
This is a common state-less push button. It is basicaaly 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();
Inherits from mono::ui::ResponderView
Public Functions
-
ButtonView
()¶ Construct an empty button.
The button will have zero dimensions and no text.
-
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
(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
setText
(String txt)¶ Set the text content.
MARK: Accessors.
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
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
setBorder
(Color c)¶ Sets the border and text color.
This method will not schedule repaint! You must scheduleRepaint manually.
- Parameters
c
-The new border and text color
-
void
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
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
-
const TextLabelView &
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
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
repaint
()¶ Painters.
-