From 320e660e8539192bb402e9fcaf1c9f908dfbf22e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 21 May 2019 16:00:19 -0600 Subject: [PATCH] apps/graphics/twm4nx: Add a configuration option to control the number of buttons in one column of the Icon Manager. The Icon Manager now long relies the default window width; now it determines a preffered window with based primarily on the font size. --- graphics/twm4nx/Kconfig | 6 +++ graphics/twm4nx/README.txt | 7 +-- graphics/twm4nx/src/cfonts.cxx | 2 +- graphics/twm4nx/src/ciconmgr.cxx | 63 +++++++++++------------ graphics/twm4nx/src/ctwm4nx.cxx | 2 +- include/graphics/twm4nx/ciconmgr.hxx | 14 +++-- include/graphics/twm4nx/twm4nx_config.hxx | 20 ++++++- 7 files changed, 70 insertions(+), 44 deletions(-) diff --git a/graphics/twm4nx/Kconfig b/graphics/twm4nx/Kconfig index 92cbf358d..0de6efc58 100644 --- a/graphics/twm4nx/Kconfig +++ b/graphics/twm4nx/Kconfig @@ -127,6 +127,12 @@ config TWM4NX_CONTEMPORARY endchoice # Twm4Nx Theme +config TWM4NX_ICONMGR_NCOLUMNS + int "Icon Manager columns" + default 4 + ---help--- + The number of buttons in one row of the Icon Manager. + config TWM4NX_DEBUG bool "Force debug output" default n diff --git a/graphics/twm4nx/README.txt b/graphics/twm4nx/README.txt index 6df013a81..e68e7312f 100644 --- a/graphics/twm4nx/README.txt +++ b/graphics/twm4nx/README.txt @@ -68,6 +68,7 @@ Progress: directly on the background without the use of a widget. 2019-05-15: Resizing now seems to work correctly in Twm4Nx. 2019-05-20: Calibration screen is now in place. + 2019-05-21: A "CONTEMPORARY" theme was added. Still has a few glitches. How To: @@ -161,10 +162,6 @@ Issues: menu just as any other region of the background. This would be easy to fix, but just replacing the background image widget is the better solution. - 7. The Icon Manager currently used the default window width. That is - set half of the display width which is okay for the display I am using, - but it really needs to set a width that is appropriate for the number - of columns and the size of a generic name string. - 8. There are a few color artifacts in the toolbar of the CONTEMPORARY + 7. There are a few color artifacts in the toolbar of the CONTEMPORARY theme. These look like boards are being drawn around the toolbar widgets (even though the are configured to be borderless). diff --git a/graphics/twm4nx/src/cfonts.cxx b/graphics/twm4nx/src/cfonts.cxx index ba282ec18..31cad2a8b 100644 --- a/graphics/twm4nx/src/cfonts.cxx +++ b/graphics/twm4nx/src/cfonts.cxx @@ -158,7 +158,7 @@ bool CFonts::initialize(void) } m_iconManagerFont = - new NXWidgets::CNxFont((enum nx_fontid_e)CONFIG_TWM4NX_ICONMGR_SIZEFONTID, + new NXWidgets::CNxFont((enum nx_fontid_e)CONFIG_TWM4NX_ICONMGR_FONTID, CONFIG_TWM4NX_ICONMGR_FONTCOLOR, CONFIG_TWM4NX_TRANSPARENT_COLOR); if (m_iconManagerFont == (FAR NXWidgets::CNxFont *)0) diff --git a/graphics/twm4nx/src/ciconmgr.cxx b/graphics/twm4nx/src/ciconmgr.cxx index 9f8426db0..3c02944fc 100644 --- a/graphics/twm4nx/src/ciconmgr.cxx +++ b/graphics/twm4nx/src/ciconmgr.cxx @@ -333,7 +333,7 @@ bool CIconMgr::resizeIconManager(void) return false; } - nxgl_coord_t rowHeight = getRowHeight(); + nxgl_coord_t rowHeight = getButtonHeight(); windowSize.h = newrows * rowHeight; if (!m_window->setWindowSize(&windowSize)) { @@ -466,24 +466,36 @@ bool CIconMgr::event(FAR struct SEventMsg *eventmsg) return success; } +/** + * Return the width of one button + * + * @return The width of one button + */ + +nxgl_coord_t CIconMgr::getButtonWidth(void) +{ + FAR CFonts *fonts = m_twm4nx->getFonts(); + FAR NXWidgets::CNxFont *iconManagerFont = fonts->getIconManagerFont(); + + // Fudge factors: Width is 8 characters of the width of 'M' width plus 4 + + return 8 * iconManagerFont->getCharWidth('M') + 4; +} + /** * Return the height of one row * * @return The height of one row */ -nxgl_coord_t CIconMgr::getRowHeight(void) +nxgl_coord_t CIconMgr::getButtonHeight(void) { FAR CFonts *fonts = m_twm4nx->getFonts(); FAR NXWidgets::CNxFont *iconManagerFont = fonts->getIconManagerFont(); - nxgl_coord_t rowHeight = iconManagerFont->getHeight() + 10; - if (rowHeight < (CONFIG_TWM4NX_ICONMGR_IMAGE.width + 4)) - { - rowHeight = CONFIG_TWM4NX_ICONMGR_IMAGE.width + 4; - } + // Fudge factors: Width is the maximal font height plus 6 rows - return rowHeight; + return iconManagerFont->getHeight() + 6; } /** @@ -550,31 +562,16 @@ bool CIconMgr::createIconManagerWindow(FAR const char *prefix) return false; } - // Adjust the height of the window (and probably the width too?) - // The height of one row is determined (mostly) by the font height + // Get the height and width of the Icon manager window. The width is + // determined by the typical string lenght the maximum character width, + // The height of one row is determined (mostly) by the maximum font + // height struct nxgl_size_s windowSize; - if (!m_window->getWindowSize(&windowSize)) - { - twmerr("ERROR: Failed to get window size\n"); - delete m_window; - m_window = (FAR CWindow *)0; - return false; - } + windowSize.w = m_nColumns * getButtonWidth(); + windowSize.h = getButtonHeight(); - windowSize.h = getRowHeight(); - - // Set the new window size - - if (!m_window->setWindowSize(&windowSize)) - { - twmerr("ERROR: Failed to set window size\n"); - delete m_window; - m_window = (FAR CWindow *)0; - return false; - } - - // Get the frame size (includes border and toolbar) + // Get the Icon manager frame size (includes border and toolbar) struct nxgl_size_s frameSize; m_window->windowToFrameSize(&windowSize, &frameSize); @@ -588,9 +585,11 @@ bool CIconMgr::createIconManagerWindow(FAR const char *prefix) framePos.x = displaySize.w - frameSize.w - 1; framePos.y = 0; - if (!m_window->setFramePosition(&framePos)) + // Set the new window size and position + + if (!m_window->resizeFrame(&frameSize, &framePos)) { - twmerr("ERROR: Failed to set window position\n"); + twmerr("ERROR: Failed to set window size/position\n"); delete m_window; m_window = (FAR CWindow *)0; return false; diff --git a/graphics/twm4nx/src/ctwm4nx.cxx b/graphics/twm4nx/src/ctwm4nx.cxx index e918d83cb..ebd81e4fd 100644 --- a/graphics/twm4nx/src/ctwm4nx.cxx +++ b/graphics/twm4nx/src/ctwm4nx.cxx @@ -246,7 +246,7 @@ bool CTwm4Nx::initialize(void) // Create the Icon Manager - m_iconmgr = new CIconMgr(this, 4); + m_iconmgr = new CIconMgr(this, CONFIG_TWM4NX_ICONMGR_NCOLUMNS); if (m_iconmgr == (FAR CIconMgr *)0) { cleanup(); diff --git a/include/graphics/twm4nx/ciconmgr.hxx b/include/graphics/twm4nx/ciconmgr.hxx index 4efe59908..306975bb6 100644 --- a/include/graphics/twm4nx/ciconmgr.hxx +++ b/include/graphics/twm4nx/ciconmgr.hxx @@ -100,12 +100,20 @@ namespace Twm4Nx uint8_t m_nrows; /**< Number of rows in the button array */ /** - * Return the height of one row + * Return the width of one button * - * @return The height of one row + * @return The width of one button */ - nxgl_coord_t getRowHeight(void); + inline nxgl_coord_t getButtonWidth(void); + + /** + * Return the height of one button + * + * @return The height of one button + */ + + inline nxgl_coord_t getButtonHeight(void); /** * Create and initialize the icon manager window diff --git a/include/graphics/twm4nx/twm4nx_config.hxx b/include/graphics/twm4nx/twm4nx_config.hxx index 857de8299..5b3057a18 100644 --- a/include/graphics/twm4nx/twm4nx_config.hxx +++ b/include/graphics/twm4nx/twm4nx_config.hxx @@ -363,6 +363,22 @@ # define CONFIG_TWM4NX_BACKGROUND_IMAGE NXWidgets::g_nuttxBitmap160x160 #endif +// Icon Manager ////////////////////////////////////////////////////////////// + +// CONFIG_TWM4NX_ICONMGR_NCOLUMNS - The number of horizontal entries in the +// Icon Manager button array. + +// See also: +// CONFIG_TWM4NX_ICONMGR_FONTID +// CONFIG_TWM4NX_ICONMGR_FONTCOLOR +// CONFIG_TWM4NX_ICONMGR_IMAGE +// CONFIG_TWM4NX_ICONMGR_VSPACING +// CONFIG_TWM4NX_ICONMGR_HSPACING + +#ifndef CONFIG_TWM4NX_ICONMGR_NCOLUMNS +# define CONFIG_TWM4NX_ICONMGR_NCOLUMNS 4 +#endif + // Cursor //////////////////////////////////////////////////////////////////// // Cursor Images @@ -402,8 +418,8 @@ # define CONFIG_TWM4NX_SIZE_FONTID NXFONT_DEFAULT #endif -#ifndef CONFIG_TWM4NX_ICONMGR_SIZEFONTID -# define CONFIG_TWM4NX_ICONMGR_SIZEFONTID NXFONT_DEFAULT +#ifndef CONFIG_TWM4NX_ICONMGR_FONTID +# define CONFIG_TWM4NX_ICONMGR_FONTID NXFONT_DEFAULT #endif // Font Colors