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.

This commit is contained in:
Gregory Nutt 2019-05-21 16:00:19 -06:00
parent 0a00a9950c
commit 320e660e85
7 changed files with 70 additions and 44 deletions

View File

@ -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

View File

@ -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).

View File

@ -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)

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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