mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
36 lines
1.2 KiB
C++
36 lines
1.2 KiB
C++
#include <escher/button_state.h>
|
|
#include <assert.h>
|
|
#include <algorithm>
|
|
|
|
View * ButtonState::subviewAtIndex(int index) {
|
|
assert(index >= 0 && index < 2);
|
|
if (index == 0) {
|
|
return &m_messageTextView;
|
|
}
|
|
return &m_stateView;
|
|
}
|
|
|
|
void ButtonState::layoutSubviews(bool force) {
|
|
KDSize textSize = Button::minimalSizeForOptimalDisplay();
|
|
KDRect textRect = KDRect(0, 0, textSize.width(), bounds().height());
|
|
// State view will be vertically centered and aligned on the left
|
|
KDSize stateSize = m_stateView.minimalSizeForOptimalDisplay();
|
|
KDRect stateRect = KDRect(textSize.width(), k_verticalOffset, stateSize.width(), stateSize.height());
|
|
|
|
m_messageTextView.setFrame(textRect, force);
|
|
m_stateView.setFrame(stateRect, force);
|
|
}
|
|
|
|
void ButtonState::drawRect(KDContext * ctx, KDRect rect) const {
|
|
KDColor backColor = isHighlighted() ? highlightedBackgroundColor() : KDColorWhite;
|
|
ctx->fillRect(bounds(), backColor);
|
|
}
|
|
|
|
KDSize ButtonState::minimalSizeForOptimalDisplay() const {
|
|
KDSize textSize = Button::minimalSizeForOptimalDisplay();
|
|
KDSize stateSize = m_stateView.minimalSizeForOptimalDisplay();
|
|
return KDSize(
|
|
textSize.width() + stateSize.width() + k_stateMargin,
|
|
std::max(textSize.height(), stateSize.height()));
|
|
}
|