Simplify screen: make it absolute and fill the whole TFT
This commit is contained in:
@ -1,15 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "Main",
|
"name": "Main",
|
||||||
"x": 20,
|
|
||||||
"y": 0,
|
|
||||||
"w": 320,
|
|
||||||
"h": 220,
|
|
||||||
|
|
||||||
"widgets": [
|
"widgets": [
|
||||||
{
|
{
|
||||||
"name": "one",
|
"name": "one",
|
||||||
"x": 16,
|
"x": 16,
|
||||||
"y": 16,
|
"y": 36,
|
||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "One",
|
"label": "One",
|
||||||
@ -19,7 +14,7 @@
|
|||||||
{
|
{
|
||||||
"name": "two",
|
"name": "two",
|
||||||
"x": 256,
|
"x": 256,
|
||||||
"y": 16,
|
"y": 36,
|
||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "Two",
|
"label": "Two",
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "One",
|
"name": "One",
|
||||||
"x": 20,
|
|
||||||
"y": 0,
|
|
||||||
"w": 320,
|
|
||||||
"h": 220,
|
|
||||||
|
|
||||||
"widgets": [
|
"widgets": [
|
||||||
{
|
{
|
||||||
"name": "back",
|
"name": "back",
|
||||||
"x": 16,
|
"x": 16,
|
||||||
"y": 16,
|
"y": 36,
|
||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "Back",
|
"label": "Back",
|
||||||
@ -19,7 +14,7 @@
|
|||||||
{
|
{
|
||||||
"name": "one",
|
"name": "one",
|
||||||
"x": 256,
|
"x": 256,
|
||||||
"y": 16,
|
"y": 36,
|
||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "One",
|
"label": "One",
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "Two",
|
"name": "Two",
|
||||||
"x": 20,
|
|
||||||
"y": 0,
|
|
||||||
"w": 320,
|
|
||||||
"h": 220,
|
|
||||||
|
|
||||||
"widgets": [
|
"widgets": [
|
||||||
{
|
{
|
||||||
"name": "back",
|
"name": "back",
|
||||||
"x": 16,
|
"x": 16,
|
||||||
"y": 16,
|
"y": 36,
|
||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "Back",
|
"label": "Back",
|
||||||
@ -19,7 +15,7 @@
|
|||||||
{
|
{
|
||||||
"name": "two",
|
"name": "two",
|
||||||
"x": 256,
|
"x": 256,
|
||||||
"y": 16,
|
"y": 36,
|
||||||
"w": 48,
|
"w": 48,
|
||||||
"h": 48,
|
"h": 48,
|
||||||
"label": "Two",
|
"label": "Two",
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
struct screen_t {
|
struct screen_t {
|
||||||
char *name;
|
char *name;
|
||||||
uint16_t x, y, w, h;
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
SLIST_HEAD(widget_entries, widget_list_t) widget_entries;
|
SLIST_HEAD(widget_entries, widget_list_t) widget_entries;
|
||||||
@ -16,7 +15,7 @@ struct screen_t {
|
|||||||
void *default_user_data;
|
void *default_user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct screen_t *screen_create(char *name, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
struct screen_t *screen_create(char *name);
|
||||||
struct screen_t *screen_create_from_file(char *fn, widget_event_fn handler, void *user_data);
|
struct screen_t *screen_create_from_file(char *fn, widget_event_fn handler, void *user_data);
|
||||||
struct screen_t *screen_create_from_json(char *json, widget_event_fn handler, void *user_data);
|
struct screen_t *screen_create_from_json(char *json, widget_event_fn handler, void *user_data);
|
||||||
void screen_destroy(struct screen_t **s);
|
void screen_destroy(struct screen_t **s);
|
||||||
|
@ -21,8 +21,8 @@ static void touch_handler(struct mgos_stmpe610_event_data *ed) {
|
|||||||
x = map(ed->x, 0, 4095, 0, _width-1);
|
x = map(ed->x, 0, 4095, 0, _width-1);
|
||||||
y = map(ed->y, 0, 4095, 0, _height-1);
|
y = map(ed->y, 0, 4095, 0, _height-1);
|
||||||
LOG(LL_INFO, ("Touch %s at (%d,%d) pressure=%d, length=%d", ed->direction==TOUCH_UP?"UP":"DOWN", x, y, ed->z, ed->length));
|
LOG(LL_INFO, ("Touch %s at (%d,%d) pressure=%d, length=%d", ed->direction==TOUCH_UP?"UP":"DOWN", x, y, ed->z, ed->length));
|
||||||
|
|
||||||
widget = screen_widget_find_by_xy(screen, x, y);
|
widget = screen_widget_find_by_xy(screen, x, y);
|
||||||
|
|
||||||
if (ed->direction==TOUCH_DOWN) {
|
if (ed->direction==TOUCH_DOWN) {
|
||||||
widget_network_recv();
|
widget_network_recv();
|
||||||
if (widget && widget->handler)
|
if (widget && widget->handler)
|
||||||
|
13
src/screen.c
13
src/screen.c
@ -1,15 +1,11 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
struct screen_t *screen_create(char *name, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
struct screen_t *screen_create(char *name) {
|
||||||
struct screen_t *screen = NULL;
|
struct screen_t *screen = NULL;
|
||||||
|
|
||||||
screen = (struct screen_t *) calloc(1, sizeof(*screen));
|
screen = (struct screen_t *) calloc(1, sizeof(*screen));
|
||||||
if (!screen)
|
if (!screen)
|
||||||
return NULL;
|
return NULL;
|
||||||
screen->x=x;
|
|
||||||
screen->y=y;
|
|
||||||
screen->w=w;
|
|
||||||
screen->h=h;
|
|
||||||
if (name)
|
if (name)
|
||||||
screen->name=strdup(name);
|
screen->name=strdup(name);
|
||||||
SLIST_INIT(&screen->widget_entries);
|
SLIST_INIT(&screen->widget_entries);
|
||||||
@ -39,14 +35,13 @@ struct screen_t *screen_create_from_json(char *json, widget_event_fn handler, vo
|
|||||||
int idx;
|
int idx;
|
||||||
struct screen_t *screen = NULL;
|
struct screen_t *screen = NULL;
|
||||||
struct widget_t *widget = NULL;
|
struct widget_t *widget = NULL;
|
||||||
int screen_x, screen_y, screen_w, screen_h;
|
|
||||||
char *screen_name = NULL;
|
char *screen_name = NULL;
|
||||||
|
|
||||||
if (json_scanf(json, strlen(json), "{x:%d,y:%d,w:%d,h:%d,name:%Q}", &screen_x, &screen_y, &screen_w, &screen_h, &screen_name) != 5) {
|
if (json_scanf(json, strlen(json), "{name:%Q}", &screen_name) != 1) {
|
||||||
LOG(LL_ERROR, ("Incomplete JSON: require 'x', 'y', 'w', 'h' and 'name' fields"));
|
LOG(LL_ERROR, ("Incomplete JSON: require 'name' fields"));
|
||||||
screen=NULL; goto exit;
|
screen=NULL; goto exit;
|
||||||
}
|
}
|
||||||
screen = screen_create(screen_name, screen_x, screen_y, screen_w, screen_h);
|
screen = screen_create(screen_name);
|
||||||
if (!screen)
|
if (!screen)
|
||||||
return NULL;
|
return NULL;
|
||||||
screen_widget_set_handler(screen, handler, user_data);
|
screen_widget_set_handler(screen, handler, user_data);
|
||||||
|
@ -2,6 +2,17 @@
|
|||||||
#include "tft.h"
|
#include "tft.h"
|
||||||
#include "mongoose-touch.h"
|
#include "mongoose-touch.h"
|
||||||
|
|
||||||
|
static void widget_default_draw(struct widget_t *w) {
|
||||||
|
if (!w)
|
||||||
|
return;
|
||||||
|
mgos_ili9341_setclipwin(w->x, w->y, w->x+w->w, w->y+w->h);
|
||||||
|
|
||||||
|
mgos_ili9341_drawRect(0, 0, w->w, w->h, ILI9341_GREEN);
|
||||||
|
|
||||||
|
if (w->img)
|
||||||
|
mgos_ili9341_jpg_image(0, 0, 1, w->img, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void widget_default_ev(int ev, struct widget_t *w, void *ev_data) {
|
void widget_default_ev(int ev, struct widget_t *w, void *ev_data) {
|
||||||
char evname[15];
|
char evname[15];
|
||||||
|
|
||||||
@ -15,6 +26,8 @@ void widget_default_ev(int ev, struct widget_t *w, void *ev_data) {
|
|||||||
case EV_WIDGET_CREATE:
|
case EV_WIDGET_CREATE:
|
||||||
case EV_WIDGET_DRAW:
|
case EV_WIDGET_DRAW:
|
||||||
case EV_WIDGET_REDRAW:
|
case EV_WIDGET_REDRAW:
|
||||||
|
widget_default_draw(w);
|
||||||
|
break;
|
||||||
case EV_WIDGET_TIMER:
|
case EV_WIDGET_TIMER:
|
||||||
case EV_WIDGET_TOUCH_UP:
|
case EV_WIDGET_TOUCH_UP:
|
||||||
case EV_WIDGET_TOUCH_DOWN:
|
case EV_WIDGET_TOUCH_DOWN:
|
||||||
|
Reference in New Issue
Block a user