aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-08-14 21:12:56 +0200
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-08-14 21:12:56 +0200
commit7f70789bc3423b915195bc09dfcbff5121cd2f70 (patch)
tree97d22407e807095387ab9cd4b0b42174984d9399 /src
parentf7075e25ed9bcd701395745161f9ee086c025e21 (diff)
downloaduGFX-7f70789bc3423b915195bc09dfcbff5121cd2f70.tar.gz
uGFX-7f70789bc3423b915195bc09dfcbff5121cd2f70.tar.bz2
uGFX-7f70789bc3423b915195bc09dfcbff5121cd2f70.zip
Adding border option to TextEdit widget
Diffstat (limited to 'src')
-rw-r--r--src/gwin/gwin_textedit.c31
-rw-r--r--src/gwin/gwin_textedit.h14
2 files changed, 40 insertions, 5 deletions
diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c
index bb25c102..eb6340a3 100644
--- a/src/gwin/gwin_textedit.c
+++ b/src/gwin/gwin_textedit.c
@@ -22,6 +22,9 @@ const int TEXT_PADDING_LEFT = 4;
const int CURSOR_PADDING_LEFT = 0;
const int CURSOR_EXTRA_HEIGHT = 1;
+// Some flags
+#define GTEXTEDIT_FLG_BORDER (GWIN_FIRST_CONTROL_FLAG << 0)
+
// Macros to assist in data type conversions
#define gh2obj ((GTexteditObject *)gh)
#define gw2obj ((GTexteditObject *)gw)
@@ -191,14 +194,29 @@ GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* widget, GWidgetInit* p
strncpy(widget->textBuffer, gwinGetText((GHandle)widget), widget->bufferSize); // FixMe: pInit->text leads to a segfault
widget->cursorPos = strlen(widget->textBuffer);
- widget->w.g.flags |= flags;
+ widget->w.g.flags |= flags | GTEXTEDIT_FLG_BORDER;;
gwinSetVisible(&widget->w.g, pInit->g.show);
return (GHandle)widget;
}
+void gwinTexteditSetBorder(GHandle gh, bool_t border)
+{
+ // Is it a valid handle?
+ if (gh->vmt != (gwinVMT*)&texteditVMT) {
+ return;
+ }
+
+ if (border) {
+ gh2obj->w.g.flags |= GTEXTEDIT_FLG_BORDER;
+ } else {
+ gh2obj->w.g.flags &=~ GTEXTEDIT_FLG_BORDER;
+ }
+}
+
static void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param)
{
+
(void)param;
// Is it a valid handle?
@@ -211,8 +229,13 @@ static void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param)
color_t cursorColor = (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge;
// Render background and string
- //gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
- gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, textColor, gw->pstyle->background, justifyLeft);
+ gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
+ gdispGFillStringBox(gw->g.display, gw->g.x + TEXT_PADDING_LEFT, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, textColor, gw->pstyle->background, justifyLeft);
+
+ // Render border (if supposed to)
+ if (gw2obj->w.g.flags & GTEXTEDIT_FLG_BORDER) {
+ gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge);
+ }
// Render cursor (if focused)
if (gwinGetFocus() == (GHandle)gw) {
@@ -223,7 +246,7 @@ static void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param)
coord_t cursorSpacingBottom = (gw->g.height - cursorHeight)/2 - CURSOR_EXTRA_HEIGHT;
// Draw cursor
- coord_t lineX0 = gw->g.x + textWidth + CURSOR_PADDING_LEFT + gdispGetFontMetric(gw->g.font, fontBaselineX)/2;
+ coord_t lineX0 = gw->g.x + textWidth + CURSOR_PADDING_LEFT + TEXT_PADDING_LEFT + gdispGetFontMetric(gw->g.font, fontBaselineX)/2;
coord_t lineX1 = lineX0;
coord_t lineY0 = gw->g.y + cursorSpacingTop;
coord_t lineY1 = gw->g.y + gw->g.height - cursorSpacingBottom;
diff --git a/src/gwin/gwin_textedit.h b/src/gwin/gwin_textedit.h
index 2b5e26e7..5b0cea85 100644
--- a/src/gwin/gwin_textedit.h
+++ b/src/gwin/gwin_textedit.h
@@ -42,7 +42,7 @@ extern "C" {
#endif
/**
- * @brief Create a TextEdit widget.
+ * @brief Create a TextEdit widget
* @details A TextEdit widget is a rectangular box which allows the user to input data through a keyboard.
* The keyboard can either be a physical one or a virtual on-screen keyboard as the keyboard driver
* is abstracted through the GINPUT module.
@@ -59,6 +59,18 @@ extern "C" {
GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* widget, GWidgetInit* pInit, size_t bufSize);
#define gwinTexteditCreate(w, pInit, bufSize) gwinGTexteditCreate(GDISP, w, pInit, bufSize)
+/**
+ * @brief Border settings for the default rendering routine
+ *
+ * @note Border is enabled by default.
+ *
+ * @param[in] gh The widget handle (must be a TextEdit handle)
+ * @param[in] border Shall a border be rendered?
+ *
+ * @api
+ */
+void gwinTexteditSetBorder(GHandle gh, bool_t border);
+
#ifdef __cplusplus
}
#endif