mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-25 00:30:46 +01:00
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include <escher/button.h>
|
|
#include <assert.h>
|
|
|
|
Button::Button(Responder * parentResponder, const char * textBody, Invocation invocation, KDText::FontSize size) :
|
|
Responder(parentResponder),
|
|
m_pointerTextView(PointerTextView(size, textBody, 0.5f, 0.5f)),
|
|
m_invocation(invocation),
|
|
m_backgroundColor(KDColorWhite)
|
|
{
|
|
}
|
|
|
|
int Button::numberOfSubviews() const {
|
|
return 1;
|
|
}
|
|
|
|
View * Button::subviewAtIndex(int index) {
|
|
assert(index == 0);
|
|
return &m_pointerTextView;
|
|
}
|
|
|
|
void Button::layoutSubviews() {
|
|
m_pointerTextView.setFrame(bounds());
|
|
}
|
|
|
|
bool Button::handleEvent(Ion::Events::Event event) {
|
|
if (event == Ion::Events::OK) {
|
|
m_invocation.perform(this);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void Button::setBackgroundColor(KDColor backgroundColor) {
|
|
m_backgroundColor = backgroundColor;
|
|
m_pointerTextView.setBackgroundColor(backgroundColor);
|
|
markRectAsDirty(bounds());
|
|
}
|
|
|
|
KDSize Button::minimalSizeForOptimalDisplay() const {
|
|
KDSize textSize = m_pointerTextView.minimalSizeForOptimalDisplay();
|
|
return KDSize(textSize.width() + k_horizontalMargin, textSize.height() + k_verticalMargin);
|
|
}
|