Fix time label and slider

This commit is contained in:
Mikhail Lobotskiy
2025-07-04 19:16:52 +04:00
parent 954972f19c
commit 3c4ca06b60
4 changed files with 13 additions and 13 deletions

View File

@ -11,7 +11,6 @@
@interface NSFooterPanel : NSView<StyledView>
{
// TODO: provide function interface instead of exposing UI data
@public
// buttons
NSIconPushButton* m_btn_play;
@ -23,8 +22,6 @@
// sliders
NSStyledSlider* m_slider_video;
NSStyledSlider* m_slider_volume;
// volume control rect
NSSubPanel* m_panel_volume;
}
- (instancetype)initWithFrame:(NSRect)frame_rect superview:(NSView*)parent;
// appearance

View File

@ -22,6 +22,8 @@ void setRightConstraintsToView(NSView* view, NSLayoutYAxisAnchor* top_anchor, NS
{
// skin
CFooterSkin m_skin;
// volume control rect
NSSubPanel* m_panel_volume;
// constraints
NSLayoutConstraint* m_time_label_width_constraint;
NSLayoutConstraint* m_time_label_height_constraint;

View File

@ -65,7 +65,6 @@
[m_footer->m_btn_rewind_forward setAction:@selector(onBtnRewindForwardPressed:)];
[m_footer->m_btn_rewind_back setTarget:self];
[m_footer->m_btn_rewind_back setAction:@selector(onBtnRewindBackPressed:)];
}
return self;
}
@ -86,7 +85,7 @@
CMTime curr_time = m_player.currentTime;
double curr_time_sec = CMTimeGetSeconds(curr_time);
CMTime seek_time = CMTimeMakeWithSeconds(std::min(curr_time_sec + 5, duration_sec), NSEC_PER_SEC);
[m_player seekToTime:seek_time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimePositiveInfinity];
[m_player seekToTime:seek_time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}
}
@ -98,7 +97,7 @@
CMTime curr_time = m_player.currentTime;
double curr_time_sec = CMTimeGetSeconds(curr_time);
CMTime seek_time = CMTimeMakeWithSeconds(std::max(curr_time_sec - 5, 0.0), NSEC_PER_SEC);
[m_player seekToTime:seek_time toleranceBefore:kCMTimePositiveInfinity toleranceAfter:kCMTimeZero];
[m_player seekToTime:seek_time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}
}
@ -109,7 +108,7 @@
if (std::isfinite(duration_sec)) {
double seek_sec = (sender.doubleValue / sender.maxValue) * duration_sec;
CMTime seek_time = CMTimeMakeWithSeconds(seek_sec, NSEC_PER_SEC);
[m_player seekToTime:seek_time];
[m_player seekToTime:seek_time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}
}
@ -127,8 +126,7 @@
double time_value = (time_sec / duration_sec) * m_footer->m_slider_video.maxValue;
[m_footer->m_slider_video setDoubleValue:time_value];
// update time label
// TODO: fix
// [m_footer->m_time_label setTime:time_sec];
[m_footer->m_time_label setTime:time_sec];
}
}

View File

@ -33,7 +33,6 @@
}
- (void)setText:(NSString*)text {
NSLog(@"debug: set text: %@", text);
NSAttributedString* attr_string = [[NSAttributedString alloc] initWithString:NSLocalizedString(text, nil) attributes:m_attributes];
[self setAttributedStringValue:attr_string];
#if !__has_feature(objc_arc)
@ -56,13 +55,16 @@
// get color
NSColor* color = NSColorFromHex(m_style->color);
// update attributes
m_attributes = @{
#if !__has_feature(objc_arc)
[m_attributes release];
#endif
m_attributes = [@{
NSFontAttributeName: font,
NSForegroundColorAttributeName: color
};
} retain];
// update text bounding box size
m_bounding_box_size = [@"00:00:00" sizeWithAttributes:m_attributes];
m_bounding_box_size.width += 2; // add extra couple of pixels
m_bounding_box_size.width += 2; // add extra couple of pixels just in case
// update current text
[self setText:self.stringValue];
}
@ -88,6 +90,7 @@
- (void)dealloc {
NSLog(@"debug: time label deallocated");
#if !__has_feature(objc_arc)
[m_attributes release];
[super dealloc];
#endif
}