Files
Upsilon/escher/src/button.cpp
Émilie Feral 0a6d822046 [escher] Create a class pointer text view inheriting
from text view

Change-Id: I10dd24ed9404e634e90f2bc7fecb6441f7a93550
2016-10-17 22:18:15 +02:00

49 lines
1.2 KiB
C++

#include <escher/button.h>
#include <assert.h>
Button::Button(Responder * parentResponder, const char * textBody, Invocation invocation) :
Responder(parentResponder),
m_pointerTextView(PointerTextView(textBody, 0.5f, 0.5f)),
m_invocation(invocation),
m_backgroundColor(KDColorWhite)
{
}
void Button::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, m_backgroundColor);
}
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) {
switch (event) {
case Ion::Events::Event::ENTER:
m_invocation.perform(this);
return true;
default:
return false;
}
}
void Button::setBackgroundColor(KDColor backgroundColor) {
m_backgroundColor = backgroundColor;
m_pointerTextView.setBackgroundColor(backgroundColor);
markRectAsDirty(bounds());
}
KDSize Button::minimalSizeForOptimalDisplay() {
KDSize textSize = m_pointerTextView.minimalSizeForOptimalDisplay();
return KDSize(textSize.width() + k_horizontalMargin, textSize.height() + k_verticalMargin);
}