mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
fix: Adjust subtitle offset to avoid overlap with visible menu
This commit is contained in:
parent
c7afade615
commit
b9f87bbc5e
2 changed files with 192 additions and 150 deletions
|
|
@ -196,6 +196,7 @@ class LibMPV extends BasePlayer {
|
|||
class _VideoSubtitles extends ConsumerStatefulWidget {
|
||||
final VideoController controller;
|
||||
final bool showOverlay;
|
||||
|
||||
const _VideoSubtitles({
|
||||
required this.controller,
|
||||
this.showOverlay = false,
|
||||
|
|
@ -211,12 +212,14 @@ class _VideoSubtitlesState extends ConsumerState<_VideoSubtitles> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
subscription = widget.controller.player.stream.subtitle.listen((value) {
|
||||
setState(() {
|
||||
subtitle = value;
|
||||
});
|
||||
});
|
||||
super.initState();
|
||||
subscription = widget.controller.player.stream.subtitle.listen((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
subtitle = value;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -225,24 +228,52 @@ class _VideoSubtitlesState extends ConsumerState<_VideoSubtitles> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
/// Calculate subtitle offset based on menu visibility
|
||||
double _calculateSubtitleOffset(SubtitleSettingsModel settings) {
|
||||
if (!widget.showOverlay) {
|
||||
return settings.verticalOffset;
|
||||
}
|
||||
|
||||
// Estimate the menu area (bottom ~15% of screen typically contains controls)
|
||||
const menuAreaThreshold = 0.15;
|
||||
|
||||
// If subtitles are already positioned above the menu area, leave them alone
|
||||
if (settings.verticalOffset >= menuAreaThreshold) {
|
||||
return settings.verticalOffset;
|
||||
}
|
||||
|
||||
// When menu is visible and subtitles are in the menu area,
|
||||
// move them up slightly to avoid overlap
|
||||
const menuAvoidanceOffset = 0.1;
|
||||
final adjustedOffset = settings.verticalOffset + menuAvoidanceOffset;
|
||||
|
||||
// Clamp to reasonable bounds (don't go too high or too low)
|
||||
return math.min(adjustedOffset, 0.85); // Max 85% up from bottom
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = ref.watch(subtitleSettingsProvider);
|
||||
final padding = MediaQuery.of(context).padding;
|
||||
final text = [
|
||||
for (final line in subtitle)
|
||||
if (line.trim().isNotEmpty) line.trim(),
|
||||
].join('\n');
|
||||
|
||||
// Process subtitle text
|
||||
final text = subtitle.where((line) => line.trim().isNotEmpty).map((line) => line.trim()).join('\n');
|
||||
|
||||
// Return empty widget if libass is enabled (native subtitle rendering)
|
||||
if (widget.controller.player.platform?.configuration.libass ?? false) {
|
||||
return const IgnorePointer(child: SizedBox.shrink());
|
||||
} else {
|
||||
return SubtitleText(
|
||||
subModel: settings,
|
||||
padding: padding,
|
||||
offset: settings.verticalOffset, // Always use user's preferred position
|
||||
text: text,
|
||||
);
|
||||
}
|
||||
|
||||
// Return empty widget if no subtitle text
|
||||
if (text.isEmpty) {
|
||||
return const IgnorePointer(child: SizedBox.shrink());
|
||||
}
|
||||
|
||||
return SubtitleText(
|
||||
subModel: settings,
|
||||
padding: padding,
|
||||
offset: _calculateSubtitleOffset(settings),
|
||||
text: text,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue