Skip to content

Commit

Permalink
add 'upward style for slider controls
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt committed Oct 31, 2023
1 parent 5dd45fb commit 09b8eb0
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
8 changes: 5 additions & 3 deletions gui-doc/scribblings/gui/slider-class.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Whenever the user changes the value of a slider, its callback
(is-a?/c panel%) (is-a?/c pane%))]
[callback ((is-a?/c slider%) (is-a?/c control-event%) . -> . any) (lambda (b e) (void))]
[init-value position-integer? min-value]
[style (listof (or/c 'horizontal 'vertical 'plain
[style (listof (or/c 'horizontal 'vertical 'upward 'plain
'vertical-label 'horizontal-label
'deleted))
'(horizontal)]
Expand Down Expand Up @@ -52,13 +52,15 @@ The @racket[callback] procedure is called (with the event type
@indexed-racket['slider]) when the user changes the slider's value.

The @racket[style] argument must include either @racket['vertical] for
a vertical slider, or @racket['horizontal] for a horizontal
slider. If @racket[style] includes @racket['plain], the slider does
a vertical slider going down, @racket['upward] for
a vertical slider going up, or @racket['horizontal] for a horizontal
slider going left-to-right. If @racket[style] includes @racket['plain], the slider does
not display numbers for its range and current value to the user.
@HVLabelNote[@racket[style]]{slider} @DeletedStyleNote[@racket[style] @racket[parent]]{slider}

@FontKWs[@racket[font]] @WindowKWs[@racket[enabled]] @SubareaKWs[] @AreaKWs[]

@history[#:changed "1.72" @elem{Added @racket['upward] as a possible @racket[style] element.}]

}

Expand Down
2 changes: 1 addition & 1 deletion gui-lib/mred/private/mritem.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
(check-container-parent cwho parent)
(check-callback cwho callback)
(check-slider-integer cwho init-value)
(check-style cwho '(vertical horizontal) '(plain vertical-label horizontal-label deleted) style)
(check-style cwho '(vertical horizontal upward) '(plain vertical-label horizontal-label deleted) style)
(check-font cwho font)
(unless (<= minv maxv)
(raise-arguments-error (who->name cwho)
Expand Down
8 changes: 6 additions & 2 deletions gui-lib/mred/private/wx/cocoa/slider.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
(inherit get-cocoa register-as-child
init-font)

(define vert? (memq 'vertical style))
(define vert? (or (memq 'vertical style)
(memq 'upward style)))
(define up? (memq 'upward style))

(define slider-lo lo)
(define slider-hi hi)
Expand Down Expand Up @@ -155,7 +157,9 @@

(define/private (flip v)
(if vert?
(+ slider-lo (- slider-hi v))
(if up?
v
(+ slider-lo (- slider-hi v)))
v))

(define/public (set-value v)
Expand Down
6 changes: 5 additions & 1 deletion gui-lib/mred/private/wx/gtk/slider.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
(define-gtk gtk_range_get_value (_fun _GtkWidget -> _double))
(define-gtk gtk_scale_set_digits (_fun _GtkWidget _int -> _void))
(define-gtk gtk_scale_set_draw_value (_fun _GtkWidget _gboolean -> _void))
(define-gtk gtk_range_set_inverted (_fun _GtkWidget _gboolean -> _void))

(define-signal-handler connect-changed "value-changed"
(_fun _GtkWidget -> _void)
Expand All @@ -42,7 +43,8 @@

(super-new [parent parent]
[gtk (as-gtk-allocation
(if (memq 'vertical style)
(if (or (memq 'vertical style)
(memq 'upward style))
(gtk_vscale_new #f)
(gtk_hscale_new #f)))]
[callback cb]
Expand All @@ -53,6 +55,8 @@
(gtk_range_set_range gtk lo hi)
(gtk_range_set_increments gtk 1.0 1.0)
(gtk_range_set_value gtk val)
(when (memq 'upward style)
(gtk_range_set_inverted gtk #true))

(when (memq 'plain style)
(gtk_scale_set_draw_value gtk #f))
Expand Down
12 changes: 9 additions & 3 deletions gui-lib/mred/private/wx/win32/slider.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
auto-size)

(define callback cb)
(define vertical? (memq 'vertical style))
(define vertical? (or (memq 'vertical style)
(memq 'upward style)))
(define up? (memq 'upward style))
(define upward-hi (and up? hi))

(define panel-hwnd
(if (memq 'plain style)
Expand Down Expand Up @@ -127,7 +130,7 @@

(SendMessageW slider-hwnd TBM_SETRANGEMIN 1 lo)
(SendMessageW slider-hwnd TBM_SETRANGEMAX 1 hi)
(set-value val)
(set-value (if up? (- hi val) val))

(define/override (set-size x y w h)
(super set-size x y w h)
Expand Down Expand Up @@ -165,4 +168,7 @@
(SetWindowTextW value-hwnd (format "~s" val)))

(define/public (get-value)
(SendMessageW slider-hwnd TBM_GETPOS 0 0)))
(define v (SendMessageW slider-hwnd TBM_GETPOS 0 0))
(if up?
(- upward-hi v)
v)))
20 changes: 11 additions & 9 deletions gui-lib/mred/private/wxlitem.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,19 @@

(define c (make-object wx-internal-slider% mred proxy (get-p) func label value min-val max-val
(filter-style style) font))

(set-c c
(memq 'horizontal style)
(memq 'vertical style))


(let ([vert? (or (memq 'vertical style)
(memq 'upward style))])
(set-c c
(not vert?)
vert?)
(let ([h? (not vert?)])
(stretchable-in-x h?)
(stretchable-in-y (not h?))))

(bounce
c
(get-value)
(set-value v))
(let ([h? (and (memq 'horizontal style) #t)])
(stretchable-in-x h?)
(stretchable-in-y (not h?)))))
(set-value v))))

)
11 changes: 8 additions & 3 deletions gui-test/tests/gracket/windowing.rktl
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,12 @@
(new slider% [parent parent] [label #f] [min-value 10] [max-value 9]))
(mismatch
(new slider% [parent parent] [label #f] [min-value 10] [max-value 11] [init-value 12]))
(letrec ([s (make-object slider%
(letrec ([style (case (random 3)
[(0) '(horizontal)]
[(1) '(vertical)]
[(2) '(upward)])]
[horiz? (and (memq 'horizontal style) #t)]
[s (make-object slider%
"&Slider"
-2 8
parent
Expand All @@ -653,7 +658,7 @@
(set! side-effect 'slider)
'oops)
3
'(horizontal))])
style)])
(label-test s "Slider")
(stv s command (make-object control-event% 'slider))
(test 'slider 'slider-callback side-effect)
Expand All @@ -666,7 +671,7 @@
(stv s set-value 8)
(st 8 s get-value)

(containee-window-tests s #t #f parent frame 2))
(containee-window-tests s horiz? (not horiz?) parent frame 2))

(let ([test-list-control
(lambda (l choice? multi?)
Expand Down

0 comments on commit 09b8eb0

Please sign in to comment.