ignore font for empty title height calculation

and align calculation on init and reconfigure

As a result, if a menu has no label, the title height is determined
only by menu.titleHeight (and the border sizes), not by the unused font.
This commit is contained in:
Thomas Lübking 2016-04-11 23:57:18 +02:00 committed by Mathias Gumz
parent ea306493f9
commit ca452a5886
3 changed files with 23 additions and 22 deletions

View file

@ -158,7 +158,7 @@ Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl):
event_mask |= EnterWindowMask | LeaveWindowMask;
int w = width();
int th = theme()->titleHeight();
int th = theme()->titleHeight(!m_title.label.logical().empty());
int fh = std::max(m_frame.height, m_frame.height);
//create menu title
@ -395,7 +395,7 @@ void Menu::updateMenu() {
int bw = theme()->borderWidth();
int ih = theme()->itemHeight();
unsigned int iw = 1;
int th = theme()->titleHeight();
int th = theme()->titleHeight(!m_title.label.logical().empty());
int tbw = m_title.win.borderWidth();
int w = static_cast<int>(width());
size_t l = m_items.size();
@ -668,7 +668,7 @@ void Menu::redrawTitle(FbDrawable &drawable) {
}
// difference between height based on font, and style-set height
int height_offset = theme()->titleHeight() - (font.height() + 2*dx);
int height_offset = theme()->titleHeight(!m_title.label.logical().empty()) - (font.height() + 2*dx);
font.drawText(drawable, screenNumber(), theme()->titleTextGC().gc(), m_title.label,
dx, font.ascent() + dx + height_offset/2); // position
}
@ -707,10 +707,10 @@ void Menu::drawSubmenu(unsigned int index) {
int bw = m_window.borderWidth();
int h = static_cast<int>(height());
int title_bw = m_title.win.borderWidth();
int title_height = (m_title.visible ? theme()->titleHeight() + title_bw : 0);
int title_height = (m_title.visible ? theme()->titleHeight(!m_title.label.logical().empty()) + title_bw : 0);
int subm_title_height = (item->submenu()->m_title.visible) ?
item->submenu()->theme()->titleHeight() + bw : 0;
item->submenu()->theme()->titleHeight(!m_title.label.logical().empty()) + bw : 0;
int subm_height = static_cast<int>(item->submenu()->height());
int subm_width = static_cast<int>(item->submenu()->width());
int subm_bw = item->submenu()->fbwindow().borderWidth();

View file

@ -86,14 +86,14 @@ MenuTheme::MenuTheme(int screen_num):
ThemeManager::instance().loadTheme(*this);
m_real_item_height = std::max(*m_item_height,
std::max(frameFont().height() + 2*bevelWidth(),
hiliteFont().height() + 2*bevelWidth()));
m_real_title_height = std::max(*m_title_height,
titleFont().height() + 2*bevelWidth());
m_real_item_height = m_real_item_height == 0 ? 1 : m_real_item_height;
m_real_title_height = m_real_title_height == 0 ? 1 : m_real_title_height;
if (*m_title_height < 1)
*m_title_height = 1;
const unsigned int pad = 2*bevelWidth();
m_real_item_height = std::max(std::max(pad + 1, *m_item_height),
std::max(frameFont().height() + pad,
hiliteFont().height() + pad));
m_real_title_height = std::max(std::max(pad + 1, *m_title_height),
titleFont().height() + pad);
t_text_gc.setForeground(*t_text);
f_text_gc.setForeground(*f_text);
@ -115,15 +115,14 @@ void MenuTheme::reconfigTheme() {
if (*m_border_width > 20)
*m_border_width = 20;
m_real_item_height = std::max(*m_item_height,
std::max(frameFont().height() + 2*bevelWidth(),
hiliteFont().height() + 2*bevelWidth()));
m_real_title_height = std::max(*m_title_height,
titleFont().height() + 2*bevelWidth());
unsigned int minsize = 2*bevelWidth()+1;
m_real_item_height = m_real_item_height < minsize ? minsize: m_real_item_height;
m_real_title_height = m_real_title_height == minsize ? minsize : m_real_title_height;
const unsigned int pad = 2*bevelWidth();
m_real_item_height = std::max(std::max(pad + 1, *m_item_height),
std::max(frameFont().height() + pad,
hiliteFont().height() + pad));
m_real_title_height = std::max(std::max(pad + 1, *m_title_height),
titleFont().height() + pad);
unsigned int item_pm_height = itemHeight();
m_bullet_pixmap->scale(item_pm_height, item_pm_height);

View file

@ -104,7 +104,9 @@ public:
BulletType bullet() const { return *m_bullet; }
Justify bulletPos() const { return *bullet_pos; }
unsigned int titleHeight() const { return m_real_title_height; }
unsigned int titleHeight(bool fontConstrained = false) const {
return fontConstrained ? m_real_title_height : *m_title_height;
}
unsigned int itemHeight() const { return m_real_item_height; }
unsigned int borderWidth() const { return *m_border_width; }
unsigned int bevelWidth() const { return *m_bevel_width; }