Draw images as blue roundrects; Add labels to non-imagery widgets, if they are set

This commit is contained in:
Pim van Pelt
2017-12-01 16:16:57 +01:00
parent 01bbb5d363
commit 95e2835871
4 changed files with 29 additions and 7 deletions

View File

@ -4,6 +4,8 @@
#include "mgos.h"
#include "mgos_pwm.h"
#include "mongoose-touch.h"
#include "fonts/FreeSerifBold9pt7b.h"
#include "fonts/FreeMonoBold9pt7b.h"
struct screen_t *screen = NULL;

View File

@ -1,18 +1,37 @@
#include "mgos.h"
#include "mongoose-touch.h"
extern GFXfont FreeSerifBold9pt7b;
static void widget_default_draw(struct widget_t *w, uint16_t color) {
if (!w)
return;
mgos_ili9341_set_window(w->x, w->y, w->x+w->w-1, w->y+w->h-1);
mgos_ili9341_set_fgcolor565(color);
mgos_ili9341_drawRoundRect(0, 0, w->w, w->h, 8);
if (w->img) {
mgos_ili9341_set_fgcolor565(ILI9341_BLUE);
mgos_ili9341_drawRoundRect(0, 0, w->w, w->h, 16);
} else if (w->label) {
int16_t text_width, text_height;
uint16_t x, y;
mgos_ili9341_drawRoundRect(0, 0, w->w, w->h, 8);
mgos_ili9341_set_font(&FreeSerifBold9pt7b);
text_width=mgos_ili9341_getStringWidth(w->label);
text_height=mgos_ili9341_getStringHeight(w->label);
if (text_width>w->w)
x=0;
else
x=(w->w-text_width)/2;
if (text_height>w->h)
y=0;
else
y=(w->h-text_height)/2;
mgos_ili9341_print(x, y, w->label);
}
/*
if (w->img)
mgos_ili9341_png(0, 0, w->img);
*/
}
void widget_default_ev(int ev, struct widget_t *w, void *ev_data) {

View File

@ -3,7 +3,6 @@
#include "mgos_wifi.h"
#include "mgos_net.h"
#include "mongoose-touch.h"
#include "fonts/FreeMonoBold9pt7b.h"
#define WIDGET_NAME_NAME 0
#define WIDGET_NAME_IPADDR 1
@ -13,6 +12,7 @@
static uint8_t what = WIDGET_NAME_NAME;
extern struct screen_t *screen;
extern GFXfont FreeMonoBold9pt7b;
static void widget_name_render(struct widget_t *w, void *ev_data) {
char namestring[21];

View File

@ -1,6 +1,7 @@
#include "mgos.h"
#include "mongoose-touch.h"
#include "fonts/FreeSerifBold9pt7b.h"
extern GFXfont FreeSerifBold9pt7b;
static void widget_time_render(struct widget_t *w, void *ev_data) {
char tmp_buff[32];