From 7488a65e17870cd786a3aeb1fd0feb30eca288a4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Nov 2018 10:21:42 -0600 Subject: [PATCH] Updates from coding style review of PR 160 --- .../NxWidgets/nxwidgets}/src/clabelgrid.cxx | 153 +++++++++--------- .../NxWidgets/nxwidgets/src/cnxstring.cxx | 22 ++- .../nxwidgets/src/cscrollingpanel.cxx | 26 +-- .../graphics/nxwidgets}/clabelgrid.hxx | 21 ++- include/graphics/nxwidgets/cnumericedit.hxx | 4 +- include/graphics/nxwidgets/cnxstring.hxx | 5 +- 6 files changed, 122 insertions(+), 109 deletions(-) rename {NxWidgets/libnxwidgets => graphics/NxWidgets/nxwidgets}/src/clabelgrid.cxx (79%) rename {NxWidgets/libnxwidgets/include => include/graphics/nxwidgets}/clabelgrid.hxx (93%) diff --git a/NxWidgets/libnxwidgets/src/clabelgrid.cxx b/graphics/NxWidgets/nxwidgets/src/clabelgrid.cxx similarity index 79% rename from NxWidgets/libnxwidgets/src/clabelgrid.cxx rename to graphics/NxWidgets/nxwidgets/src/clabelgrid.cxx index 38f37be0e..625a00a8e 100644 --- a/NxWidgets/libnxwidgets/src/clabelgrid.cxx +++ b/graphics/NxWidgets/nxwidgets/src/clabelgrid.cxx @@ -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 * Petteri Aimonen * @@ -72,11 +72,12 @@ * Included Files ****************************************************************************/ -#include "clabelgrid.hxx" -#include "clabel.hxx" #include #include +#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); + } } - } } - - - - diff --git a/graphics/NxWidgets/nxwidgets/src/cnxstring.cxx b/graphics/NxWidgets/nxwidgets/src/cnxstring.cxx index ffb298eb5..01ed9f622 100644 --- a/graphics/NxWidgets/nxwidgets/src/cnxstring.cxx +++ b/graphics/NxWidgets/nxwidgets/src/cnxstring.cxx @@ -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 * * 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; diff --git a/graphics/NxWidgets/nxwidgets/src/cscrollingpanel.cxx b/graphics/NxWidgets/nxwidgets/src/cscrollingpanel.cxx index 831aadde3..e17735dca 100644 --- a/graphics/NxWidgets/nxwidgets/src/cscrollingpanel.cxx +++ b/graphics/NxWidgets/nxwidgets/src/cscrollingpanel.cxx @@ -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 * * 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) { diff --git a/NxWidgets/libnxwidgets/include/clabelgrid.hxx b/include/graphics/nxwidgets/clabelgrid.hxx similarity index 93% rename from NxWidgets/libnxwidgets/include/clabelgrid.hxx rename to include/graphics/nxwidgets/clabelgrid.hxx index f9a1d49b3..8469cdae3 100644 --- a/NxWidgets/libnxwidgets/include/clabelgrid.hxx +++ b/include/graphics/nxwidgets/clabelgrid.hxx @@ -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 * Petteri Aimonen * @@ -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 -#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 \ No newline at end of file +#endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CLABELGRIG_HXX diff --git a/include/graphics/nxwidgets/cnumericedit.hxx b/include/graphics/nxwidgets/cnumericedit.hxx index 4b1bf75ab..c869ef0f7 100644 --- a/include/graphics/nxwidgets/cnumericedit.hxx +++ b/include/graphics/nxwidgets/cnumericedit.hxx @@ -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 * Petteri Aimonen * @@ -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); } - }; } diff --git a/include/graphics/nxwidgets/cnxstring.hxx b/include/graphics/nxwidgets/cnxstring.hxx index 9353d6f7c..52f636dd3 100644 --- a/include/graphics/nxwidgets/cnxstring.hxx +++ b/include/graphics/nxwidgets/cnxstring.hxx @@ -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 * * 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, ...); }; }