diff options
Diffstat (limited to 'fw/fe310/eos/eve/widget/togglew.c')
-rw-r--r-- | fw/fe310/eos/eve/widget/togglew.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/fw/fe310/eos/eve/widget/togglew.c b/fw/fe310/eos/eve/widget/togglew.c new file mode 100644 index 0000000..fbebacb --- /dev/null +++ b/fw/fe310/eos/eve/widget/togglew.c @@ -0,0 +1,58 @@ +#include <stdlib.h> +#include <string.h> + +#include "eve.h" +#include "eve_kbd.h" +#include "eve_font.h" + +#include "screen/window.h" +#include "screen/page.h" + +#include "widget.h" + +void eve_togglew_init(EVEToggleWidget *widget, EVERect *g, EVEPage *page, EVEFont *font, char *labels) { + EVEWidget *_widget = &widget->w; + + memset(widget, 0, sizeof(EVEPageWidget)); + eve_widget_init(_widget, EVE_WIDGET_TYPE_TOGGLE, g, page, eve_togglew_draw, eve_togglew_touch, NULL); + widget->font = font; + widget->labels = labels; + if (_widget->g.w == 0) _widget->g.w = 3 * eve_font_h(widget->font); + if (_widget->g.h == 0) _widget->g.h = eve_font_h(widget->font); +} + +int eve_togglew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + EVEToggleSpec *tspec = &spec->tspec.toggle; + EVEFont *font = tspec->font ? tspec->font : eve_window_font(page->v.window); + + eve_togglew_init(widget, &spec->g, page, font, tspec->labels); + + return EVE_OK; +} + +uint8_t eve_togglew_draw(EVEWidget *_widget, uint8_t tag0) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + + _widget->tag0 = tag0; + if (tag0 != EVE_NOTAG) { + eve_cmd_dl(TAG(tag0)); + tag0++; + } + _widget->tagN = tag0; + + eve_cmd(CMD_TOGGLE, "hhhhhhs", _widget->g.x, _widget->g.y, _widget->g.w, widget->font->id, 0, widget->state ? 65535 : 0, widget->labels); + + return _widget->tagN; +} + +int eve_togglew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) { + EVEToggleWidget *widget = (EVEToggleWidget *)_widget; + + if (evt & EVE_TOUCH_ETYPE_TAG_UP) { + widget->state = !widget->state; + return 1; + } + + return 0; +} |