leds and tiny buttons measure actual preferred width
This commit is contained in:
@@ -61,6 +61,8 @@ bool cButton::isScrollable() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int tiny_text_offset = 18;
|
||||
|
||||
void cButton::draw(){
|
||||
rectangle from_rect, to_rect;
|
||||
|
||||
@@ -81,7 +83,7 @@ void cButton::draw(){
|
||||
eTextMode textMode = eTextMode::CENTRE;
|
||||
if(type == BTN_TINY) {
|
||||
textMode = wrapLabel ? eTextMode::WRAP : eTextMode::LEFT_TOP;
|
||||
to_rect.left += 18;
|
||||
to_rect.left += tiny_text_offset;
|
||||
style.colour = textClr;
|
||||
} else if(type == BTN_PUSH) {
|
||||
to_rect.top += 42;
|
||||
@@ -175,13 +177,17 @@ void cButton::validatePostParse(ticpp::Element& elem, std::string fname, const s
|
||||
if(labelledButtons.count(type)) {
|
||||
if(!attrs.count("color") && !attrs.count("colour") && parent->getBg() == cDialog::BG_DARK)
|
||||
setColour(sf::Color::White);
|
||||
if(!getText().empty() && !attrs.count("width"))
|
||||
throw xMissingAttr(elem.Value(), "width", elem.Row(), elem.Column(), fname);
|
||||
}
|
||||
}
|
||||
|
||||
location cButton::getPreferredSize() const {
|
||||
return {btnRects[type][0].width(), btnRects[type][0].height()};
|
||||
int width = btnRects[type][0].width();
|
||||
if(type == BTN_TINY && !getText().empty()){
|
||||
TextStyle style;
|
||||
style.pointSize = textSize;
|
||||
width = tiny_text_offset + string_length(getText(), style);
|
||||
}
|
||||
return {width, btnRects[type][0].height()};
|
||||
}
|
||||
|
||||
void cButton::recalcRect() {
|
||||
|
@@ -86,6 +86,8 @@ bool cLed::manageFormat(eFormat prop, bool set, boost::any* val) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const int text_offset = 18; // Possibly could be 20
|
||||
|
||||
void cLed::draw(){
|
||||
rectangle from_rect, to_rect;
|
||||
|
||||
@@ -103,7 +105,7 @@ void cLed::draw(){
|
||||
rect_draw_some_item(*ResMgr::graphics.get(buttons[btnGW[BTN_LED]]),from_rect,*inWindow,to_rect);
|
||||
style.colour = textClr;
|
||||
to_rect.right = frame.right;
|
||||
to_rect.left = frame.left + 18; // Possibly could be 20
|
||||
to_rect.left = frame.left + text_offset;
|
||||
win_draw_string(*inWindow,to_rect,getText(),wrapLabel ? eTextMode::WRAP : eTextMode::LEFT_TOP,style);
|
||||
}
|
||||
|
||||
@@ -152,5 +154,11 @@ bool cLed::parseContent(ticpp::Node& content, int n, std::string tagName, std::s
|
||||
}
|
||||
|
||||
location cLed::getPreferredSize() const {
|
||||
return {ledRects[0][0].width(), ledRects[0][0].height()};
|
||||
int width = ledRects[0][0].width();
|
||||
if(!getText().empty()){
|
||||
TextStyle style;
|
||||
style.pointSize = textSize;
|
||||
width = text_offset + string_length(getText(), style);
|
||||
}
|
||||
return {width, ledRects[0][0].height()};
|
||||
}
|
||||
|
Reference in New Issue
Block a user