(bind-func Widget_slider_c
(lambda (label:i8* cb:[void,float]*)
(let ((lab (String label))
(slider_pos 0.))
(lambda (widget:Widget* bounds:Rect*)
(let ((vg (GUI_context EXTEMPORE_GUI))
(parent (Widget_parent widget))
(click_p (gui_left_click_p bounds))
(vertical_p (or (null? parent)
(Widget_split_vertical_p parent))))
;; toggle state
(if click_p
(begin
(set! slider_pos
(if vertical_p
(/ (- (gui_mouse_x) (tref bounds 0))
(tref bounds 2))
(/ (- (gui_mouse_y) (tref bounds 1))
(tref bounds 3))))
(cb slider_pos)))
;; draw background
(nvgBeginPath vg)
(nvgFillColor vg GUI_COLOR_BLUE_D)
(gui_draw_rect bounds)
(nvgFill vg)
;; draw "marker"
(nvgBeginPath vg)
(if click_p
(nvgFillColor vg GUI_COLOR_BLUE_L)
(nvgFillColor vg GUI_COLOR_BLUE))
(let ((slider_rect:Rect* (salloc)))
(if vertical_p
(tfill! slider_rect
(+ (* (tref bounds 2) slider_pos) (tref bounds 0) -10.)
(tref bounds 1)
20.
(tref bounds 3))
(tfill! slider_rect
(tref bounds 0)
(+ (* (tref bounds 3) slider_pos) (tref bounds 1) -10.)
(tref bounds 2)
20.))
(gui_draw_rect slider_rect))
(nvgFill vg)
(nvgFillColor vg GUI_COLOR_BG)
(nvgBeginPath vg)
(gui_draw_text_in_bounds bounds lab 30.)
(nvgFill vg))))))