Updates from coding style review of PR 160

This commit is contained in:
Gregory Nutt 2018-11-09 10:21:42 -06:00
parent 66d4ed9912
commit 7488a65e17
6 changed files with 122 additions and 109 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clabelgrid.hxx
* apps/graphics/NxWkidgets/nwidgets/src/clabelgrid.cxx
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Petteri Aimonen <jpa@kapsi.fi>
*
@ -72,11 +72,12 @@
* Included Files
****************************************************************************/
#include "clabelgrid.hxx"
#include "clabel.hxx"
#include <assert.h>
#include <debug.h>
#include "graphics/nxwidgets/clabelgrid.hxx"
#include "graphics/nxwidgets/clabel.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
@ -98,25 +99,25 @@ CLabelGrid::CLabelGrid(CWidgetControl* pWidgetControl, nxgl_coord_t x, nxgl_coor
int cell_height = height / m_cols;
for (int row = 0; row < m_rows; row++)
{
m_rowheights.push_back(-1); // -1 signifies automatic sizing
}
{
m_rowheights.push_back(-1); // -1 signifies automatic sizing
}
for (int col = 0; col < m_cols; col++)
{
m_colwidths.push_back(-1);
}
{
m_colwidths.push_back(-1);
}
for (int row = 0; row < m_rows; row++)
{
for (int col = 0; col < m_cols; col++)
{
CLabel *label = new CLabel(pWidgetControl, col * cell_width, row * cell_height,
cell_width, cell_height, "");
this->addWidget(label);
m_labels.push_back(label);
for (int col = 0; col < m_cols; col++)
{
CLabel *label = new CLabel(pWidgetControl, col * cell_width, row * cell_height,
cell_width, cell_height, "");
this->addWidget(label);
m_labels.push_back(label);
}
}
}
}
CLabel& CLabelGrid::at(int col, int row)
@ -132,71 +133,81 @@ void CLabelGrid::onResize(nxgl_coord_t width, nxgl_coord_t height)
// Count the number of automatically sized columns and rows and
// space available to them.
int autocols = 0;
int fixedwidth = 0;
for (int i = 0; i < m_cols; i++)
{
if (m_colwidths.at(i) < 0)
{
autocols++;
if (m_colwidths.at(i) < 0)
{
autocols++;
}
else
{
fixedwidth += m_colwidths.at(i);
}
}
else
{
fixedwidth += m_colwidths.at(i);
}
}
int autorows = 0;
int fixedheight = 0;
for (int i = 0; i < m_rows; i++)
{
if (m_rowheights.at(i) < 0)
{
autorows++;
if (m_rowheights.at(i) < 0)
{
autorows++;
}
else
{
fixedheight += m_rowheights.at(i);
}
}
else
{
fixedheight += m_rowheights.at(i);
}
}
// Avoid divide by zero
if (autocols == 0)
autocols = 1;
{
autocols = 1;
}
if (autorows == 0)
autorows = 1;
{
autorows = 1;
}
// Divide the space among the rows and columns
int auto_width = (width - fixedwidth) / autocols;
int auto_height = (height - fixedheight) / autorows;
int y = 0;
for (int row = 0; row < m_rows; row++)
{
int h = m_rowheights.at(row);
if (h < 0)
{
h = auto_height;
int h = m_rowheights.at(row);
if (h < 0)
{
h = auto_height;
}
int x = 0;
for (int col = 0; col < m_cols; col++)
{
int w = m_colwidths.at(col);
if (w < 0)
{
w = auto_width;
}
this->at(col, row).changeDimensions(x, y, w, h);
dbg("G %d %d: %d %d %d %d\n", col, row, x, y, w, h);
x += w;
}
y += h;
}
int x = 0;
for (int col = 0; col < m_cols; col++)
{
int w = m_colwidths.at(col);
if (w < 0)
{
w = auto_width;
}
this->at(col, row).changeDimensions(x, y, w, h);
dbg("G %d %d: %d %d %d %d\n", col, row, x, y, w, h);
x += w;
}
y += h;
}
this->enableDrawing();
redraw();
}
@ -218,12 +229,12 @@ void CLabelGrid::setBackgroundColor(nxgl_mxpixel_t color)
CNxWidget::setBackgroundColor(color);
for (int row = 0; row < m_rows; row++)
{
for (int col = 0; col < m_cols; col++)
{
this->at(col, row).setBackgroundColor(color);
for (int col = 0; col < m_cols; col++)
{
this->at(col, row).setBackgroundColor(color);
}
}
}
}
void CLabelGrid::setBorderless(bool borderless)
@ -231,12 +242,12 @@ void CLabelGrid::setBorderless(bool borderless)
CNxWidget::setBorderless(borderless);
for (int row = 0; row < m_rows; row++)
{
for (int col = 0; col < m_cols; col++)
{
this->at(col, row).setBorderless(borderless);
for (int col = 0; col < m_cols; col++)
{
this->at(col, row).setBorderless(borderless);
}
}
}
}
void CLabelGrid::useWidgetStyle(const CWidgetStyle* style)
@ -244,14 +255,10 @@ void CLabelGrid::useWidgetStyle(const CWidgetStyle* style)
CNxWidget::useWidgetStyle(style);
for (int row = 0; row < m_rows; row++)
{
for (int col = 0; col < m_cols; col++)
{
this->at(col, row).useWidgetStyle(style);
for (int col = 0; col < m_cols; col++)
{
this->at(col, row).useWidgetStyle(style);
}
}
}
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* apps/graphics/NxWidgets/nxwidgets/src/cnxstring.cxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -83,10 +83,6 @@
#include "graphics/nxwidgets/cnxstring.hxx"
#include "graphics/nxwidgets/cstringiterator.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* CNxString Method Implementations
****************************************************************************/
@ -372,6 +368,7 @@ void CNxString::insert(const CNxString &text, int index)
FAR nxwidget_char_t *dest = &m_text[newLength - 1];
FAR const nxwidget_char_t *src = &m_text[m_stringLength - 1];
for (int i = 0; i < m_stringLength - index; i++)
{
*dest-- = *src--;
@ -822,15 +819,16 @@ CNxString CNxString::format(const char *fmt, ...)
va_end(args);
if (sizeof(nxwidget_char_t) > sizeof(char))
{
// Expand the string to full width, beginning from the last
// character so that we don't overwrite characters before
// we have converted them.
for (int i = len - 1; i >= 0; i--)
{
result.m_text[i] = (nxwidget_char_t)buf[i];
// Expand the string to full width, beginning from the last
// character so that we don't overwrite characters before
// we have converted them.
for (int i = len - 1; i >= 0; i--)
{
result.m_text[i] = (nxwidget_char_t)buf[i];
}
}
}
result.m_stringLength = len - 1;
return result;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* apps/graphics/NxWidgets/nxwidgets/src/cscrollingpanel.cxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -192,21 +192,21 @@ void CScrollingPanel::scroll(int32_t dx, int32_t dy)
CGraphicsPort *port = m_widgetControl->getGraphicsPort();
if (dx >= 0 && dy >= 0)
{
port->move(getX(), getY(), dx, dy, rect.getWidth() - dx, rect.getHeight() - dy);
}
{
port->move(getX(), getY(), dx, dy, rect.getWidth() - dx, rect.getHeight() - dy);
}
else if (dx <= 0 && dy >= 0)
{
port->move(getX() - dx, getY(), dx, dy, rect.getWidth() + dx, rect.getHeight() - dy);
}
{
port->move(getX() - dx, getY(), dx, dy, rect.getWidth() + dx, rect.getHeight() - dy);
}
else if (dx >= 0 && dy <= 0)
{
port->move(getX(), getY() - dy, dx, dy, rect.getWidth() - dx, rect.getHeight() + dy);
}
{
port->move(getX(), getY() - dy, dx, dy, rect.getWidth() - dx, rect.getHeight() + dy);
}
else if (dx <= 0 && dy <= 0)
{
port->move(getX() - dx, getY() - dy, dx, dy, rect.getWidth() + dx, rect.getHeight() + dy);
}
{
port->move(getX() - dx, getY() - dy, dx, dy, rect.getWidth() + dx, rect.getHeight() + dy);
}
if (dx > 0)
{

View File

@ -1,7 +1,7 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clabelgrid.hxx
* apps/include/nxwidgets/include/clabelgrid.hxx
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Petteri Aimonen <jpa@kapsi.fi>
*
@ -68,8 +68,8 @@
*
****************************************************************************/
#ifndef __INCLUDE_CLABELGRID_HXX
#define __INCLUDE_CLABELGRID_HXX
#ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CLABELGRIG_HXX
#define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CLABELGRIG_HXX
/****************************************************************************
* Included Files
@ -82,9 +82,9 @@
#include <nuttx/nx/nxglib.h>
#include "cnxwidget.hxx"
#include "cwidgetstyle.hxx"
#include "tnxarray.hxx"
#include "graphics/nxwidgets/cnxwidget.hxx"
#include "graphics/nxwidgets/cwidgetstyle.hxx"
#include "graphics/nxwidgets/tnxarray.hxx"
/****************************************************************************
* Pre-Processor Definitions
@ -110,6 +110,7 @@ namespace NXWidgets
* 2-dimensional grid of labels. Each row and column can have custom
* label styles applied.
*/
class CLabelGrid : public CNxWidget
{
protected:
@ -142,6 +143,7 @@ namespace NXWidgets
* @param cols Number of colums in the grid.
* @param rows Number of rows in the grid.
*/
CLabelGrid(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height, int cols, int rows);
@ -154,6 +156,7 @@ namespace NXWidgets
* @param row Zero-based index of the row.
* @returns Reference to CLabel.
*/
virtual CLabel &at(int col, int row);
/**
@ -162,6 +165,7 @@ namespace NXWidgets
* @param col Zero-based index of the column.
* @param width Width of column in pixels, or -1 to size automatically.
*/
void setColumnWidth(int col, int width);
/**
@ -170,6 +174,7 @@ namespace NXWidgets
* @param row Zero-based index of the row.
* @param height Height of row in pixels, or -1 to size automatically.
*/
void setRowHeight(int row, int height);
void setBackgroundColor(nxgl_mxpixel_t color);
@ -182,4 +187,4 @@ namespace NXWidgets
#endif // __cplusplus
#endif // __INCLUDE_CLABELGRID_HXX
#endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CLABELGRIG_HXX

View File

@ -1,7 +1,7 @@
/****************************************************************************
* apps/include/graphics/nxwidgets/cnumericedit.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Petteri Aimonen <jpa@kapsi.fi>
*
@ -199,6 +199,7 @@ namespace NXWidgets
/**
* Sets the text to display after the numeric value.
*/
void setUnit(const CNxString& text);
inline int getValue() const { return m_value; }
@ -212,7 +213,6 @@ namespace NXWidgets
inline int getIncrement() const { return m_increment; }
inline void setIncrement(int value) { m_increment = value; setValue(m_value); }
};
}

View File

@ -2,7 +2,7 @@
* include/cnxtring.hxx
*apps/include/graphics/nxwidgets/
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -480,6 +480,7 @@ namespace NXWidgets
/**
* Overloaded sum operator. Appends the string to current string.
*/
inline CNxString &operator+=(const CNxString &other)
{
append(other);
@ -489,6 +490,7 @@ namespace NXWidgets
/**
* Overloaded sum operator. Concatenates two strings.
*/
inline CNxString operator+(const CNxString &other)
{
CNxString result = *this;
@ -515,6 +517,7 @@ namespace NXWidgets
* @param fmt printf format string.
* @return New CNxString instance.
*/
static CNxString format(const char *fmt, ...);
};
}