Cocoa/Config: turn Overlay Style Scroller Config to the new Style

This commit is contained in:
rich2014 2024-08-21 22:03:20 +08:00
parent 3d7a79d4d0
commit 08275d757b
2 changed files with 62 additions and 17 deletions

View File

@ -152,14 +152,34 @@ type
fadeStep: Double;
end;
TCocoaConfgiScrollerOverlayKnob = object( TCocoaConfgiScrollerKnob )
minSize: Double;
end;
TCocoaConfigScrollerLegacy = record
knob: TCocoaConfgiScrollerLegacyKnob;
end;
TCocoaConfigScrollerOverlayBar = record
autoShowDelayTime: Double;
autoHideDelayTime: Double;
alpha: Double;
alphaFadeStep: Double;
alphaFadeTo: Double;
expandTimeInterval: Double;
expandSize: Double;
end;
TCocoaConfigScrollerOverlay = record
bar: TCocoaConfigScrollerOverlayBar;
knob: TCocoaConfgiScrollerOverlayKnob;
end;
TCocoaConfigScroller = record
preferredStyle: NSScrollerStyle;
fadeTimeInterval: Double;
legacy: TCocoaConfigScrollerLegacy;
overlay: TCocoaConfigScrollerOverlay;
end;
var
@ -184,6 +204,31 @@ var
fadeStep: 0.05; // Knob Alpha Step when fading in/out
);
);
overlay: (
bar: (
// Overly Style Scroller Auto Show Delay Time, in Seconds
// used when the Scroller is triggered by double-finger tapping the touchpad
autoShowDelayTime: 0.2;
autoHideDelayTime: 0.9; // Bar Auto Hide Delay Time, in Seconds
alpha: 0.5; // Bar Alpha in Normal
alphaFadeStep: -0.1; // Bar Alpha Step when fading out
alphaFadeTo: 0; // Bar Alpha when fade out ends
expandTimeInterval: 0.03; // Bar Expands time interval, in Seconds
expandSize: 4; // Bar Expands when the mouse enters, in Dots
);
knob: (
radius: 4; // Knob Radius, in Dots
color: @getCocoaScrollerDefaultKnobColor;
pos: 5; // Knob Position, in Dots
shrunkSize: 6; // Knob Shrunk Size, in Dots
// in extreme cases, the normally calculated Knob size of Overlay Scroller
// may be too small, keep the min size.
// min height for the Knob of VerticalScroller
// min width for the Knob of HorizontalScroller
minSize: 25;
)
);
);
type

View File

@ -1486,8 +1486,8 @@ end;
procedure TCocoaScrollBarEffectOverlay.onDelayHidingTimer( timer:NSTimer );
begin
self.delayTimer:= nil;
self.fade( CocoaConfig.CocoaScrollerOverlayStyleFadeStep,
CocoaConfig.CocoaScrollerOverlayStyleFadeTo );
self.fade( CocoaConfigScroller.overlay.bar.alphaFadeStep,
CocoaConfigScroller.overlay.bar.alphaFadeTo );
end;
procedure TCocoaScrollBarEffectOverlay.onExpandTimer(timer: NSTimer);
@ -1499,7 +1499,7 @@ begin
Exit;
end;
if self.expandedSize < CocoaConfig.CocoaScrollerOverlayStyleExpandSize then begin
if self.expandedSize < CocoaConfigScroller.overlay.bar.expandSize then begin
self.expandedSize:= self.expandedSize + 1;
end else begin
done:= True;
@ -1534,14 +1534,14 @@ end;
procedure TCocoaScrollBarEffectOverlay.setDelayShowingTimer;
begin
self.setDelayTimer(
CocoaScrollerOverlayStyleAutoShowDelayTime,
CocoaConfigScroller.overlay.bar.autoShowDelayTime,
ObjCSelector('onDelayShowingTimer:') );
end;
procedure TCocoaScrollBarEffectOverlay.setDelayHidingTimer;
begin
self.setDelayTimer(
CocoaConfig.CocoaScrollerOverlayStyleAutoHideDelayTime,
CocoaConfigScroller.overlay.bar.autoHideDelayTime,
ObjCSelector('onDelayHidingTimer:') );
end;
@ -1553,7 +1553,7 @@ begin
self.expandTimer.invalidate;
self.expandTimer:= NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats(
CocoaConfig.CocoaScrollerOverlayStyleExpandTimeInterval,
CocoaConfigScroller.overlay.bar.expandTimeInterval,
self,
ObjCSelector('onExpandTimer:'),
nil,
@ -1825,23 +1825,23 @@ begin
rect:= NSInsetRect(rect, 1, 1);
if scrollBar.IsHorizontal then begin
rect.origin.y:= rect.origin.y
+ CocoaConfig.CocoaScrollerOverlayStyleKnobPos
+ CocoaConfigScroller.overlay.knob.pos
- effect.expandedSize;
rect.size.height:= rect.size.height
- CocoaConfig.CocoaScrollerOverlayStyleKnobShrunkSize
- CocoaConfigScroller.overlay.knob.shrunkSize
+ effect.expandedSize;
end else begin
rect.origin.x:= rect.origin.x
+ CocoaConfig.CocoaScrollerOverlayStyleKnobPos
+ CocoaConfigScroller.overlay.knob.pos
- effect.expandedSize;
rect.size.width:= rect.size.width
- CocoaConfig.CocoaScrollerOverlayStyleKnobShrunkSize
- CocoaConfigScroller.overlay.knob.shrunkSize
+ effect.expandedSize;
end;
radius:= CocoaConfig.CocoaScrollerKnobRadius + effect.expandedSize/2;
radius:= CocoaConfigScroller.overlay.knob.radius + effect.expandedSize/2;
path:= NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius( rect, radius, radius );
CocoaConfig.CocoaScrollerOverlayStyleKnobColor().set_;
CocoaConfigScroller.overlay.knob.color().set_;
path.fill;
if scroller.knobProportion < 1 then
@ -1879,11 +1879,11 @@ begin
else
slotSize:= slotRect.size.height;
if knobProportion*slotSize <= CocoaConfig.CocoaScrollerOverlayStyleKnobMinSize then begin
if slotSize<=CocoaConfig.CocoaScrollerOverlayStyleKnobMinSize then
if knobProportion*slotSize <= CocoaConfigScroller.overlay.knob.minSize then begin
if slotSize<=CocoaConfigScroller.overlay.knob.minSize then
knobProportion:= 0.99
else
knobProportion:= CocoaConfig.CocoaScrollerOverlayStyleKnobMinSize/slotSize;
knobProportion:= CocoaConfigScroller.overlay.knob.minSize/slotSize;
end;
if (effect.currentKnobPosition=knobPosition) and (effect.currentKnobProportion=knobProportion) then
@ -1929,7 +1929,7 @@ begin
effect.manager:= self;
effect.currentKnobPosition:= -1;
effect.currentKnobProportion:= -1;
effect.currentAlpha:= CocoaConfig.CocoaScrollerOverlayStyleAlpha;
effect.currentAlpha:= CocoaConfigScroller.overlay.bar.alpha;
Result:= effect;
end;
@ -1976,7 +1976,7 @@ begin
// on old versions of macOS, alpha=0 is considered hidden.
// that is, to be truly visible, not only Hidden=false, but Alpha must also be set.
// otherwise it is considered hidden and setNeedsDisplay() does not take effect.
effect.currentAlpha:= CocoaConfig.CocoaScrollerOverlayStyleAlpha;
effect.currentAlpha:= CocoaConfigScroller.overlay.bar.alpha;
scroller.setAlphaValue( effect.currentAlpha );
scroller.setHidden( False );
scroller.setNeedsDisplay_( true );