Skip to content

Commit a78a59d

Browse files
committed
Implemented ElasticSliderScrollerFastList5
Added 2 files: src/Element/ui/list/5/list/composition/handlers/elastic/ElasticSliderScrollerFastListHandler.swift src/Element/ui/list/5/list/composition/protocol/Elastic5+Slidable5+FastListable5+Extensions.swift Modified 5 files: src/Element/ui/list/5/list/composition/ElasticScrollerFastList5.swift src/Element/ui/list/5/list/composition/ElasticSliderScrollerFastList5.swift src/Element/ui/list/5/list/composition/handlers/SliderScrollerFastListHandler.swift src/Element/ui/list/5/list/composition/handlers/elastic/ElasticScrollerFastListHandler.swift src/Element/ui/list/5/list/composition/protocol/Elastic5+Fast+Extensions.swift
1 parent b9ca23c commit a78a59d

File tree

7 files changed

+77
-136
lines changed

7 files changed

+77
-136
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import Foundation
22

3-
class ElasticScrollerList5 {
4-
3+
class ElasticScrollerFastList5:ScrollerFastList5,Elastic5 {
4+
lazy var moverGroup:MoverGroup = MoverGroup(self.setProgressVal,self.maskSize,self.contentSize)//⚠️️ remember to add eventHandler
5+
lazy var rbContainer:Container = self.createRBContainer/*Needed for the overshot animation*/
6+
//
7+
private var elasticHandler:ElasticScrollerFastListHandler {return handler as! ElasticScrollerFastListHandler}//move this to extension somewhere
8+
override lazy var handler:ProgressHandler = ElasticScrollerFastListHandler(progressable:self)
59
}
Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,13 @@
11
import Cocoa
22
@testable import Utils
33

4-
class ElasticSliderScrollerFastList5:FastList5,Elastic5,Slidable5 {
5-
lazy var hSlider:Slider = self.createHSlider
6-
lazy var vSlider:Slider = self.createVSlider
7-
lazy var moverGroup:MoverGroup = self.moverGrp
4+
class ElasticSliderScrollerFastList5:SliderScrollerFastList5,Elastic5 {
5+
lazy var moverGroup:MoverGroup = MoverGroup(self.setProgressValue,self.maskSize,self.contentSize)//⚠️️ remember to add eventHandler
86
lazy var rbContainer:Container = self.createRBContainer/*Needed for the overshot animation*/
9-
override func onEvent(_ event:Event) {
10-
if(event.type == AnimEvent.stopped){
11-
let dir:Dir = event.origin === moverGroup.yMover ? .ver : .hor
12-
hideSlider(dir)/*Hides the slider when bounce back anim stopps*/
13-
}
14-
super.onEvent(event)
15-
}
16-
17-
//move the bellow into the eventHandler ⚠️️
18-
19-
20-
/**
21-
* PARAM value: is the final y value for the lableContainer
22-
* ⚠️️ Do not use scalar value here (0-1) well you know...
23-
*/
24-
25-
func setProgressValue(_ value:CGFloat, _ dir:Dir) {/*Gets calls from MoverGroup*/
26-
//Swift.print("ElasticSlidableScrollableFastListable3.setProgressValue(val,dir)")
27-
//Swift.print("👻🏂📜🐎 ElasticScrollableFastListable.setProgress(\(value))")
28-
//Swift.print("value: " + "\(value)")
29-
var progressValue:CGFloat?//new
30-
let contentSide:CGFloat = contentSize[dir]//TODO: Use a precalculated itemsHeight instead of recalculating it on every setProgress call, what if dp.count changes though?
31-
if contentSide < maskSize[dir] {//when there is few items in view, different overshoot rules apply, this should be written more elegant
32-
progressValue = value / maskSize[dir]
33-
let val = progressValue! * maskSize[dir]
34-
posContainer(rbContainer,dir,val)
35-
}else{
36-
progressValue = value / -(contentSide - maskSize[dir])/*calc scalar from value, if itemsHeight is to small then use height instead*/
37-
let progress = progressValue!.clip(0, 1)
38-
39-
//⚠️️🔨the bellow needs refactoring
40-
//(self as! Scrollable5).setProgress(progress,dir)/*moves the lableContainer up and down*/
41-
super.setProgress(progress)/*Updates the positions of the FastListItems*/
42-
//
43-
let sliderProgress = ElasticUtils.progress(value,contentSide,maskSize[dir])//doing some double calculations here
44-
/*finds the values that is outside 0 and 1*/
45-
if sliderProgress < 0 {//⚠️️ You could also just do if value is bellow 0 -> y = value, and if y < itemsheight - height -> y = the sapce above itemsheight - leftover
46-
let v1 = maskSize[dir] * -sliderProgress
47-
posContainer(rbContainer,dir,v1)/*the half height is to limit the rubber effect, should probably be done else where*/
48-
}else if sliderProgress > 1 {
49-
let v2 = maskSize[dir] * -(sliderProgress-1)
50-
posContainer(rbContainer,dir,v2)
51-
}else{
52-
posContainer(rbContainer,dir,0)/*default position*/
53-
}
54-
}
55-
//Swift.print("rbContainer!.point[dir]: " + "\(rbContainer!.point[dir])")
56-
//Swift.print("contentContainer.point[dir]: " + "\(contentContainer!.point[dir])")
57-
58-
let sliderProgress = ElasticUtils.progress(value,contentSize[dir],maskSize[dir])//doing some double calculations here
59-
slider(dir).setProgressValue(sliderProgress)//temp fix
60-
}
61-
func scroll(_ event: NSEvent) {
62-
//Swift.print("ElasticSlidableScrollableFastListable3.scroll")
63-
//super.scroll(event)//forward the event
64-
switch event.phase{
65-
case /*NSEvent.Phase*/.changed://Direct scroll, ⚠️️That you need a hock here is not that great
66-
let sliderProgress:CGPoint = ElasticUtils.progress(moverGroup.result,contentSize,maskSize)
67-
(self as Slidable5).setProgress(sliderProgress)/*moves the sliders*/
68-
case /*NSEvent.Phase*/.mayBegin, /*NSEvent.Phase*/.began:/*same as onScrollWheelEnter()*/
69-
showSlider()
70-
case /*NSEvent.Phase*/.ended://same as onScrollWheelExit()
71-
hideSlider()
72-
default:break;
73-
}
74-
if(event.momentumPhase == NSEvent.Phase.began){//simulates: onScrollWheelMomentumBegan()
75-
showSlider()//cancels out the hide call when onScrollWheelExit is called when you release after pan gesture
76-
}
77-
}
78-
func onScrollWheelCancelled() {
79-
Swift.print("ElasticSlidableScrollable3.onScrollWheelCancelled")
80-
hideSlider()
81-
}
7+
//
8+
private var elasticHandler:ElasticSliderScrollerFastListHandler {return handler as! ElasticSliderScrollerFastListHandler}//move this to extension somewhere
9+
override lazy var handler:ProgressHandler = ElasticSliderScrollerFastListHandler(progressable:self)
8210
}
8311

8412

13+

src/Element/ui/list/5/list/composition/handlers/SliderScrollerFastListHandler.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@ import Cocoa
33

44
class SliderScrollerFastListHandler:ScrollerFastListHandler,SlidableDecorater {
55
/**
6-
* TODO: you could also override scroll and hock after the forward scroll call and then retrive the progress from the var. less code, but the value must be written in Displaceview, it could mess up Elastic, because it needs different progress. etc, do later
6+
* TODO: ⚠️️ you could also override scroll and hock after the forward scroll call and then retrive the progress from the var. less code, but the value must be written in Displaceview, it could mess up Elastic, because it needs different progress. etc, do later
77
*/
88
override func onScrollWheelChange(_ event:NSEvent) {
9-
Swift.print("SliderScrollerFastListHandler.onScrollWheelChange")
109
super.onScrollWheelChange(event)
11-
//Swift.print("🏂📜 SlidableScrollable3.onScrollWheelChange: \(event.type)")
12-
/*let horProg:CGFloat = SliderListUtils.progress(event.delta[.hor], interval(.hor), slider(.hor).progress)//TODO: ⚠️️ merge these 2 lines into one and make a method in SliderListUtils that returns point
13-
let verProg:CGFloat = SliderListUtils.progress(event.delta[.ver], /*5*/interval(.ver), slider(.ver).progress)*/
1410
let progressVal:CGPoint = SliderListUtils.progress(event.delta, interval, progress)
1511
setProgress(progressVal)
16-
// (self as Slidable5).setProgress(progressVal)
17-
//(self as Scrollable5).setProgress(progressVal)
1812
}
1913
override func onInDirectScrollWheelChange(_ event:NSEvent) {//enables momentum
2014
super.onInDirectScrollWheelChange(event)
2115
onScrollWheelChange(event)
2216
}
2317
override func onScrollWheelEnter() {
24-
Swift.print("SliderScrollerHandler.onScrollWheelEnter")
2518
super.onScrollWheelEnter()
2619
showSlider()
2720
}
@@ -30,7 +23,6 @@ class SliderScrollerFastListHandler:ScrollerFastListHandler,SlidableDecorater {
3023
hideSlider()
3124
}
3225
override func onScrollWheelExit() {
33-
Swift.print("SliderScrollerHandler.onScrollWheelExit")
3426
super.onScrollWheelExit()
3527
hideSlider()
3628
}

src/Element/ui/list/5/list/composition/handlers/elastic/ElasticScrollerFastListHandler.swift

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,4 @@ class ElasticScrollerFastListHandler:ScrollerFastListHandler,ElasticDecorator {
5050

5151
}
5252

53-
extension ElasticScrollerFastListHandler{
54-
/**
55-
* PARAM value: is the final y value for the lableContainer
56-
* ⚠️️ Do not use scalar value here (0-1) well you know...
57-
*/
58-
func setProgressVal(_ value:CGFloat,_ dir:Dir){
59-
//Swift.print("👻🏂📜🐎 ElasticScrollableFastListable.setProgress(\(value))")
60-
//Swift.print("value: " + "\(value)")
61-
var progressValue:CGFloat?//new
62-
let contentSide:CGFloat = contentSize[dir]//TODO: Use a precalculated itemsHeight instead of recalculating it on every setProgress call, what if dp.count changes though?
63-
if contentSide < maskSize[dir] {//when there is few items in view, different overshoot rules apply, this should be written more elegant
64-
progressValue = value / maskSize[dir]
65-
let val = progressValue! * maskSize[dir]
66-
posContainer(rbContainer,dir,val)
67-
}else{
68-
progressValue = value / -(contentSide - maskSize[dir])/*calc scalar from value, if itemsHeight is to small then use height instead*/
69-
let progress = progressValue!.clip(0, 1)
70-
71-
//⚠️️🔨the bellow needs refactoring
72-
(self as Scrollable5).setProgress(progress,dir)/*moves the lableContainer up and down*/
73-
(progressable as! FastList5).setProgress(progress)/*Updates the positions of the FastListItems*/
74-
//
75-
let sliderProgress = ElasticUtils.progress(value,contentSide,maskSize[dir])//doing some double calculations here
76-
/*finds the values that is outside 0 and 1*/
77-
if sliderProgress < 0 {//⚠️️ You could also just do if value is bellow 0 -> y = value, and if y < itemsheight - height -> y = the sapce above itemsheight - leftover
78-
let v1 = maskSize[dir] * -sliderProgress
79-
posContainer(rbContainer,dir,v1)/*the half height is to limit the rubber effect, should probably be done else where*/
80-
}else if sliderProgress > 1 {
81-
let v2 = maskSize[dir] * -(sliderProgress-1)
82-
posContainer(rbContainer,dir,v2)
83-
}else{
84-
posContainer(rbContainer,dir,0)/*default position*/
85-
}
86-
}
87-
//Swift.print("rbContainer!.point[dir]: " + "\(rbContainer!.point[dir])")
88-
//Swift.print("contentContainer.point[dir]: " + "\(contentContainer!.point[dir])")
89-
}
90-
}
91-
92-
93-
//extension ElasticScrollableFastListable3{
94-
// func posContainer(_ rbContainer:Container,_ dir:Dir,_ value:CGFloat){/*Temp*/
95-
// disableAnim {rbContainer.layerPos(value,dir)}/*default position*/
96-
// }
97-
//}
9853

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Foundation
2+
3+
class ElasticSliderScrollerFastListHandler {
4+
5+
}
Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
1-
import Foundation
2-
3-
class Elastic5_Fast_Extensions {
1+
import Cocoa
2+
@testable import Utils
43

4+
extension Elastic5 where Self:FastListable5/*, Self:Scrollable5 */{
5+
/**
6+
* Elastic + Fast needs this method
7+
* PARAM value: is the final y value for the lableContainer
8+
* ⚠️️ Do not use scalar value here (0-1) well you know...
9+
*/
10+
func setProgressVal(_ value:CGFloat,_ dir:Dir){//TODO: bind to Elastic and fast somehow
11+
Swift.print("setProgressVal")
12+
//Swift.print("value: " + "\(value)")
13+
var progressValue:CGFloat?//new
14+
let contentSide:CGFloat = contentSize[dir]//TODO: Use a precalculated itemsHeight instead of recalculating it on every setProgress call, what if dp.count changes though?
15+
if contentSide < maskSize[dir] {//when there is few items in view, different overshoot rules apply, this should be written more elegant
16+
progressValue = value / maskSize[dir]
17+
let val = progressValue! * maskSize[dir]
18+
posContainer(rbContainer,dir,val)
19+
}else{
20+
progressValue = value / -(contentSide - maskSize[dir])/*calc scalar from value, if itemsHeight is to small then use height instead*/
21+
let progress = progressValue!.clip(0, 1)
22+
23+
//⚠️️🔨the bellow needs refactoring
24+
(self as Progressable5).setProgress(progress,dir)/*moves the lableContainer up and down*/
25+
Swift.print("progress: " + "\(progress)")
26+
(self as FastListable5).setProgress(progress)/*Updates the positions of the FastListItems*/
27+
//
28+
let sliderProgress = ElasticUtils.progress(value,contentSide,maskSize[dir])//doing some double calculations here
29+
/*finds the values that is outside 0 and 1*/
30+
if sliderProgress < 0 {//⚠️️ You could also just do if value is bellow 0 -> y = value, and if y < itemsheight - height -> y = the sapce above itemsheight - leftover
31+
let v1 = maskSize[dir] * -sliderProgress
32+
posContainer(rbContainer,dir,v1)/*the half height is to limit the rubber effect, should probably be done else where*/
33+
}else if sliderProgress > 1 {
34+
let v2 = maskSize[dir] * -(sliderProgress-1)
35+
posContainer(rbContainer,dir,v2)
36+
}else{
37+
posContainer(rbContainer,dir,0)/*default position*/
38+
}
39+
}
40+
//Swift.print("rbContainer!.point[dir]: " + "\(rbContainer!.point[dir])")
41+
//Swift.print("contentContainer.point[dir]: " + "\(contentContainer!.point[dir])")
42+
}
543
}
44+
45+
46+
//extension ElasticScrollableFastListable3{
47+
// func posContainer(_ rbContainer:Container,_ dir:Dir,_ value:CGFloat){/*Temp*/
48+
// disableAnim {rbContainer.layerPos(value,dir)}/*default position*/
49+
// }
50+
//}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Cocoa
2+
@testable import Utils
3+
4+
extension Elastic5 where Self:Slidable5 {
5+
func setProgressValue(_ value:CGFloat, _ dir:Dir) {/*Gets calls from MoverGroup*/
6+
//Swift.print("ElasticSlidableScrollableFastListable3.setProgressValue(val,dir)")
7+
setProgressVal(value, dir)//forward
8+
let sliderProgress = ElasticUtils.progress(value,contentSize[dir],maskSize[dir])//doing some double calculations here
9+
slider(dir).setProgressValue(sliderProgress)//temp fix
10+
}
11+
}

0 commit comments

Comments
 (0)