(bind-func Widget_checkbox_c
(lambda (label:i8* cb:[void,i1]*)
(let ((lab (String label))
(state:i1 0)
(click_p:i1 0)
(prev_click_p:i1 0))
(lambda (widget:Widget* bounds:Rect*)
(let ((vg (GUI_context EXTEMPORE_GUI)))
;; toggle state
(set! click_p (gui_left_click_p bounds))
(if (and click_p (not prev_click_p))
(begin
(set! state (not state))
;; fire callback
(cb state)))
(set! prev_click_p click_p)
;; draw widget
(nvgBeginPath vg)
;; checkboxes are edge-triggered on state change
(if state
(nvgFillColor vg GUI_COLOR_GREEN_L)
(nvgFillColor vg GUI_COLOR_GREEN_D))
(gui_draw_rect bounds)
(nvgFill vg)
(nvgFillColor vg GUI_COLOR_BG)
(nvgBeginPath vg)
(gui_draw_text_in_bounds bounds lab 30.)
(nvgFill vg))))))