...
This commit is contained in:
parent
745caa28b4
commit
a2623494b9
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
@interface CustomVolumeSlider : NSSliderCell
|
||||
|
||||
// Add a property to track the hover state
|
||||
// This property will control whether the knob is visible.
|
||||
@property (nonatomic, assign) BOOL isHovered;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
[fg fill];
|
||||
}
|
||||
|
||||
// **MODIFIED:** The knob is now drawn only when the isHovered property is true.
|
||||
- (void)drawKnob:(NSRect)knobRect {
|
||||
if (self.isHovered) {
|
||||
CGFloat d = 12;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// HoverSlider.h
|
||||
// Volume Control
|
||||
//
|
||||
// Created by Andrea Alberti on 26.10.25.
|
||||
//
|
||||
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
An NSSlider subclass that detects mouse hover events (mouseEntered:/mouseExited:)
|
||||
and communicates the hover state to its CustomVolumeSlider cell.
|
||||
*/
|
||||
@interface HoverSlider : NSSlider
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// HoverSlider.m
|
||||
// Volume Control
|
||||
//
|
||||
// Created by Andrea Alberti on 26.10.25.
|
||||
//
|
||||
|
||||
#import "HoverSlider.h"
|
||||
#import "CustomVolumeSlider.h" // We need this to access the 'isHovered' property
|
||||
|
||||
@implementation HoverSlider
|
||||
|
||||
// This method sets up the tracking area that allows us to receive mouse events.
|
||||
- (void)updateTrackingAreas {
|
||||
[super updateTrackingAreas];
|
||||
|
||||
// Remove any old tracking areas to prevent duplicates
|
||||
for (NSTrackingArea *area in self.trackingAreas) {
|
||||
[self removeTrackingArea:area];
|
||||
}
|
||||
|
||||
// **MODIFIED:** Changed the tracking option to be always active.
|
||||
NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
||||
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
|
||||
options:options
|
||||
owner:self
|
||||
userInfo:nil];
|
||||
[self addTrackingArea:trackingArea];
|
||||
}
|
||||
|
||||
// Called when the mouse cursor enters the slider's bounds.
|
||||
- (void)mouseEntered:(NSEvent *)event {
|
||||
NSLog(@"DFd");
|
||||
[super mouseEntered:event];
|
||||
if ([self.cell isKindOfClass:[CustomVolumeSlider class]]) {
|
||||
// Tell our custom cell that it's being hovered
|
||||
((CustomVolumeSlider *)self.cell).isHovered = YES;
|
||||
// Trigger a redraw to show the knob
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the mouse cursor leaves the slider's bounds.
|
||||
- (void)mouseExited:(NSEvent *)event {
|
||||
[super mouseExited:event];
|
||||
if ([self.cell isKindOfClass:[CustomVolumeSlider class]]) {
|
||||
// Tell our custom cell that the hover is over
|
||||
((CustomVolumeSlider *)self.cell).isHovered = NO;
|
||||
// Trigger a redraw to hide the knob
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#import "CustomVolumeSlider.h"
|
||||
#import <AppKit/NSGlassEffectView.h>
|
||||
#import "HUDPanel.h"
|
||||
#import "HoverSlider.h"
|
||||
|
||||
// Product Module Name: Volume_Control
|
||||
#import "Volume_Control-Swift.h" // exposes LiquidGlassView to ObjC
|
||||
|
|
@ -217,6 +218,10 @@ static const CGFloat kSideInset = 12.0; // left/right margin
|
|||
[glass setVariantIfAvailable:5];
|
||||
[glass setScrimStateIfAvailable:0];
|
||||
[glass setSubduedStateIfAvailable:0];
|
||||
|
||||
// [glass setValue:@(YES) forKey:@"_useReducedShadowRadius"]; // smaller or sharper rim
|
||||
// [glass setValue:@(0) forKey:@"_adaptiveAppearance"]; adapts rim contrast to dark/light mode
|
||||
// [glass setValue:@(0) forKey:@"_contentLensing"]; // if 1, simulates focus depth
|
||||
|
||||
// Optional SwiftUI-like post-filters:
|
||||
//[glass applyVisualAdjustmentsWithSaturation:1.5 brightness:0.2 blur:0.25];
|
||||
|
|
@ -224,6 +229,7 @@ static const CGFloat kSideInset = 12.0; // left/right margin
|
|||
|
||||
#pragma mark - Content
|
||||
|
||||
|
||||
- (NSView *)buildSliderStrip {
|
||||
NSView *strip = [NSView new];
|
||||
strip.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
|
@ -246,12 +252,18 @@ static const CGFloat kSideInset = 12.0; // left/right margin
|
|||
[iconRight setContentHuggingPriority:251 forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||
[iconRight setContentCompressionResistancePriority:751 forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||
|
||||
// Slider (custom white cell)
|
||||
NSSlider *slider = [NSSlider sliderWithValue:0.6 minValue:0.0 maxValue:1.0 target:self action:@selector(sliderChanged:)];
|
||||
// <-- 2. USE THE NEW HoverSlider CLASS
|
||||
HoverSlider *slider = [HoverSlider new];
|
||||
slider.minValue = 0.0;
|
||||
slider.maxValue = 1.0;
|
||||
slider.doubleValue = 0.6; // initial value
|
||||
slider.target = self;
|
||||
slider.action = @selector(sliderChanged:);
|
||||
|
||||
slider.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
slider.controlSize = NSControlSizeSmall;
|
||||
|
||||
CustomVolumeSlider *cell = [CustomVolumeSlider new]; // NSSliderCell subclass
|
||||
CustomVolumeSlider *cell = [CustomVolumeSlider new];
|
||||
cell.minValue = 0.0;
|
||||
cell.maxValue = 1.0;
|
||||
cell.controlSize = NSControlSizeSmall;
|
||||
|
|
|
|||
Loading…
Reference in New Issue