Scrollbars were not sending proper data with click callbacks.

This commit is contained in:
Scott Duensing 2022-07-16 18:52:36 -05:00
parent f1878955e5
commit fe79a0b139
3 changed files with 30 additions and 16 deletions

View file

@ -40,6 +40,8 @@ static void hscrollPaint(struct WidgetS *widget, ...);
static void hscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event, void *data) {
HscrollT *h = (HscrollT *)widget;
(void)data;
// Clicking in left arrow?
if (x <= GADGET_SIZE) {
// Move content left.
@ -49,7 +51,7 @@ static void hscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (h->handler) h->handler(widget, x, y, event, data);
if (h->handler) h->handler(widget, x, y, event, h->base.data);
return;
}
@ -62,7 +64,7 @@ static void hscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (h->handler) h->handler(widget, x, y, event, data);
if (h->handler) h->handler(widget, x, y, event, h->base.data);
return;
}
@ -75,7 +77,7 @@ static void hscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (h->handler) h->handler(widget, x, y, event, data);
if (h->handler) h->handler(widget, x, y, event, h->base.data);
return;
}
@ -88,7 +90,7 @@ static void hscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (h->handler) h->handler(widget, x, y, event, data);
if (h->handler) h->handler(widget, x, y, event, h->base.data);
return;
}
}
@ -197,7 +199,7 @@ static void hscrollPaint(struct WidgetS *widget, ...) {
void hscrollRangeSet(HscrollT *hscroll, int32_t min, int32_t max) {
hscroll->min = min;
hscroll->max = max;
widgetDirtySet(W(hscroll), 1);
hscrollValueSet(hscroll, min);
}

View file

@ -36,7 +36,17 @@ static void scrollablePaint(struct WidgetS *widget, ...);
static void scrollableClickHandler(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event, void *data) {
logWrite("Event from scrollable\n");
ScrollableT *s = (ScrollableT *)data;
(void)widget;
(void)x;
(void)y;
(void)event;
logWrite("Event from scrollable - %d %d\n", hscrollValueGet(s->scrollh), vscrollValueGet(s->scrollv));
s->offset.x = hscrollValueGet(s->scrollh);
s->offset.y = vscrollValueGet(s->scrollv);
}
@ -49,15 +59,17 @@ ScrollableT *scrollableCreate(int16_t width, int16_t height, int16_t totalWidth,
NEW(ScrollableT, s);
memset(s, 0, sizeof(ScrollableT));
widgetBaseSet(W(s), __MAGIC_SCROLLABLE, width, height);
// Set up desired scroll bars.
s->flags = flags;
if (s->flags & SCROLLABLE_SCROLL_V) {
s->scrollv = vscrollCreate(height, scrollableClickHandler, NULL);
s->scrollv = vscrollCreate(height, scrollableClickHandler, s);
vscrollRangeSet(s->scrollv, 0, totalHeight- 1);
w = s->scrollv->base.r.w; // Used when creating horizontal scroll bar below.
}
if (s->flags & SCROLLABLE_SCROLL_H) {
s->scrollh = hscrollCreate(width - w, scrollableClickHandler, NULL);
s->scrollh = hscrollCreate(width - w, scrollableClickHandler, s);
hscrollRangeSet(s->scrollh, 0, totalWidth - 1);
}
@ -71,8 +83,6 @@ ScrollableT *scrollableCreate(int16_t width, int16_t height, int16_t totalWidth,
surfaceClear(GUI_LIGHTBLUE);
surfaceSet(t);
widgetBaseSet(W(s), __MAGIC_SCROLLABLE, width, height);
return s;
}

View file

@ -38,7 +38,9 @@ static void vscrollPaint(struct WidgetS *widget, ...);
static void vscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event, void *data) {
VscrollT *v = (VscrollT *)widget;
VscrollT *v = (VscrollT *)widget;
(void)data;
// Clicking in up arrow?
if (y <= GADGET_SIZE) {
@ -49,7 +51,7 @@ static void vscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (v->handler) v->handler(widget, x, y, event, data);
if (v->handler) v->handler(widget, x, y, event, v->base.data);
return;
}
@ -62,7 +64,7 @@ static void vscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (v->handler) v->handler(widget, x, y, event, data);
if (v->handler) v->handler(widget, x, y, event, v->base.data);
return;
}
@ -75,7 +77,7 @@ static void vscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (v->handler) v->handler(widget, x, y, event, data);
if (v->handler) v->handler(widget, x, y, event, v->base.data);
return;
}
@ -88,7 +90,7 @@ static void vscrollClick(WidgetT *widget, uint16_t x, uint16_t y, uint8_t event,
// Update.
widgetDirtySet(widget, 1);
// Call the actual click event.
if (v->handler) v->handler(widget, x, y, event, data);
if (v->handler) v->handler(widget, x, y, event, v->base.data);
return;
}
}
@ -189,7 +191,7 @@ static void vscrollPaint(struct WidgetS *widget, ...) {
void vscrollRangeSet(VscrollT *vscroll, int32_t min, int32_t max) {
vscroll->min = min;
vscroll->max = max;
widgetDirtySet(W(vscroll), 1);
vscrollValueSet(vscroll, min);
}