From ca452a58867b4ceaacb35c823902c89f2f6b6b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Mon, 11 Apr 2016 23:57:18 +0200 Subject: 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. --- src/FbTk/Menu.cc | 10 +++++----- src/FbTk/MenuTheme.cc | 31 +++++++++++++++---------------- src/FbTk/MenuTheme.hh | 4 +++- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 484a399..34cc6ae 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -158,7 +158,7 @@ Menu::Menu(FbTk::ThemeProxy &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(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(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(item->submenu()->height()); int subm_width = static_cast(item->submenu()->width()); int subm_bw = item->submenu()->fbwindow().borderWidth(); diff --git a/src/FbTk/MenuTheme.cc b/src/FbTk/MenuTheme.cc index db54483..9fc55e4 100644 --- a/src/FbTk/MenuTheme.cc +++ b/src/FbTk/MenuTheme.cc @@ -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); diff --git a/src/FbTk/MenuTheme.hh b/src/FbTk/MenuTheme.hh index e217e7c..b03b6fc 100644 --- a/src/FbTk/MenuTheme.hh +++ b/src/FbTk/MenuTheme.hh @@ -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; } -- cgit v0.11.2