From fb6f08baf47836921ee812aef354114211658929 Mon Sep 17 00:00:00 2001 From: David Sanchez Gregori Date: Fri, 13 Mar 2020 20:37:50 +0100 Subject: [PATCH 1/3] An if clause is used to return if it's not dragging the slider. MacOS and Windows, seems fixed. Also a little comment in code and reformating for better readability. --- src/Morphic-Widgets-Scrolling/Slider.class.st | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Morphic-Widgets-Scrolling/Slider.class.st b/src/Morphic-Widgets-Scrolling/Slider.class.st index 8dea269620f..c1df58986da 100644 --- a/src/Morphic-Widgets-Scrolling/Slider.class.st +++ b/src/Morphic-Widgets-Scrolling/Slider.class.st @@ -140,20 +140,27 @@ Slider >> roomToMove [ { #category : #scrolling } Slider >> scrollAbsolute: event [ | r p | + "There is no state variable, but we know it's draggin the slider by it color if the style is not #inset there nothing to do." + slider borderStyle style == #inset + ifFalse: [ ^ self ]. r := self roomToMove. bounds isWide - ifTrue: [r width = 0 ifTrue: [^ self]] - ifFalse: [r height = 0 ifTrue: [^ self]]. + ifTrue: [ r width = 0 + ifTrue: [ ^ self ] ] + ifFalse: [ r height = 0 + ifTrue: [ ^ self ] ]. p := event targetPoint adhereTo: r. self descending - ifFalse: - [self setValue: (bounds isWide - ifTrue: [(p x - r left) asFloat / r width] - ifFalse: [(p y - r top) asFloat / r height])] - ifTrue: - [self setValue: (bounds isWide - ifTrue: [(r right - p x) asFloat / r width] - ifFalse: [(r bottom - p y) asFloat / r height])] + ifFalse: [ self + setValue: + (bounds isWide + ifTrue: [ (p x - r left) asFloat / r width ] + ifFalse: [ (p y - r top) asFloat / r height ]) ] + ifTrue: [ self + setValue: + (bounds isWide + ifTrue: [ (r right - p x) asFloat / r width ] + ifFalse: [ (r bottom - p y) asFloat / r height ]) ] ] { #category : #initialization } From 36c54bf7a2421ccf9d2cbe1c7022753c0c05a72d Mon Sep 17 00:00:00 2001 From: David Sanchez Gregori Date: Fri, 13 Mar 2020 21:00:26 +0100 Subject: [PATCH 2/3] Added dragging variable, and accessors (getter and setter) to reflect the current state and act in consecuence. Using style of the slider was not a clean way to control the state. --- src/Morphic-Widgets-Scrolling/Slider.class.st | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Morphic-Widgets-Scrolling/Slider.class.st b/src/Morphic-Widgets-Scrolling/Slider.class.st index c1df58986da..b8bbcb5ac41 100644 --- a/src/Morphic-Widgets-Scrolling/Slider.class.st +++ b/src/Morphic-Widgets-Scrolling/Slider.class.st @@ -7,7 +7,8 @@ Class { 'setValueSelector', 'sliderShadow', 'sliderColor', - 'descending' + 'descending', + 'dragging' ], #category : #'Morphic-Widgets-Scrolling' } @@ -64,6 +65,16 @@ Slider >> descending: aBoolean [ self value: value ] +{ #category : #access } +Slider >> dragging [ + ^ dragging. +] + +{ #category : #access } +Slider >> dragging: aBoolean [ + dragging := aBoolean. +] + { #category : #geometry } Slider >> extent: newExtent [ newExtent = bounds extent ifTrue: [^ self]. @@ -80,6 +91,7 @@ Slider >> initialize [ super initialize. value := 0.0. descending := false. + dragging := false. self initializeSlider ] @@ -110,19 +122,20 @@ Slider >> initializeSlider [ Slider >> mouseDownInSlider: event [ slider borderStyle style == #raised - ifTrue: [slider borderColor: #inset]. + ifTrue: [slider borderColor: #inset. self dragging: true]. sliderShadow color: self sliderShadowColor. sliderShadow cornerStyle: slider cornerStyle. sliderShadow bounds: slider bounds. - sliderShadow show + sliderShadow show. + ] { #category : #'other events' } Slider >> mouseUpInSlider: event [ slider borderStyle style == #inset - ifTrue: [slider borderColor: #raised]. + ifTrue: [slider borderColor: #raised. self dragging: false]. sliderShadow hide ] @@ -140,9 +153,9 @@ Slider >> roomToMove [ { #category : #scrolling } Slider >> scrollAbsolute: event [ | r p | - "There is no state variable, but we know it's draggin the slider by it color if the style is not #inset there nothing to do." - slider borderStyle style == #inset - ifFalse: [ ^ self ]. + "If I'm not dragging I will do nothing." + self dragging ifFalse: [ ^ self ]. + r := self roomToMove. bounds isWide ifTrue: [ r width = 0 From ff393ef7ae111c8c197d4c9fceb9f4b72e73ec40 Mon Sep 17 00:00:00 2001 From: David Sanchez Gregori Date: Sun, 15 Mar 2020 11:08:05 +0100 Subject: [PATCH 3/3] Code revision and documentation. --- src/Morphic-Widgets-Scrolling/Slider.class.st | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Morphic-Widgets-Scrolling/Slider.class.st b/src/Morphic-Widgets-Scrolling/Slider.class.st index b8bbcb5ac41..0e68a6cdbc0 100644 --- a/src/Morphic-Widgets-Scrolling/Slider.class.st +++ b/src/Morphic-Widgets-Scrolling/Slider.class.st @@ -119,25 +119,30 @@ Slider >> initializeSlider [ ] { #category : #'other events' } -Slider >> mouseDownInSlider: event [ - - slider borderStyle style == #raised - ifTrue: [slider borderColor: #inset. self dragging: true]. +Slider >> mouseDownInSlider: event [ + "When mouse down I start dragging, and change the border colors and show a shadow + on the original position." + + slider borderColor: #inset. sliderShadow color: self sliderShadowColor. sliderShadow cornerStyle: slider cornerStyle. sliderShadow bounds: slider bounds. sliderShadow show. + self dragging: true ] { #category : #'other events' } -Slider >> mouseUpInSlider: event [ +Slider >> mouseUpInSlider: event [ + "When mouse up, the dragging ends and the color is reseted to it's orignal + value and the shadow of original position is hidden." - slider borderStyle style == #inset - ifTrue: [slider borderColor: #raised. self dragging: false]. + slider borderColor: #raised. + + sliderShadow hide. - sliderShadow hide + self dragging: false. ] { #category : #access }