Skip to content

Commit

Permalink
split verses to fix overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Cordero committed Feb 9, 2023
1 parent 08f1b29 commit fb15081
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 41 deletions.
Binary file added fonts/SEGOEUI.TTF
Binary file not shown.
36 changes: 36 additions & 0 deletions lib/core/helper_functions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
import 'package:flutter/painting.dart';

import '../models/scripture_reference_model.dart';

String scriptureRefToRefString(ScriptureReference ref) {
return '${ref.translation} ${ref.book} ${ref.chapter}:${ref.verse!.verseString}';
}

//TODO refactor
int maxCharacters(
String text,
TextStyle style,
) {
final TextPainter heightPainter = TextPainter(
text: TextSpan(text: text, style: style),
maxLines: 1,
textDirection: TextDirection.ltr,
)..layout(minWidth: 0, maxWidth: double.infinity);

final TextPainter widthPainter = TextPainter(
// M as text because it probably is the widest
text: TextSpan(text: 'M', style: style),
maxLines: 1,
textDirection: TextDirection.ltr,
)..layout(minWidth: 0, maxWidth: double.infinity);

double height = heightPainter.height;
double paddingSize = 30;
int maxLines = (1080 - (2 * paddingSize) - 100) ~/ height;

final TextPainter textPainter = TextPainter(
text: TextSpan(
text: text,
style: style,
),
maxLines: maxLines,
textDirection: TextDirection.ltr,
)..layout(minWidth: 0, maxWidth: 1920 - 30 - 30);

return ((textPainter.width ~/ widthPainter.width) * maxLines) - 5;
}
21 changes: 12 additions & 9 deletions lib/media_center/widgets/playlist_preview_panel.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freecps/core/helper_functions.dart';
import 'package:freecps/media_center/media_center_providers.dart';
import 'package:freecps/models/saved_verse_slides.dart';

import '../../core/file_utils.dart';
import '../../core/helper_functions.dart';
import '../../models/playlist_model.dart';
import '../../models/saved_verse_slides.dart';
import '../../models/song_model.dart';
import '../media_center_providers.dart';

class PlaylistPreviewPanel extends ConsumerWidget {
const PlaylistPreviewPanel({super.key});
Expand Down Expand Up @@ -70,12 +70,15 @@ class PlaylistPreviewPanel extends ConsumerWidget {
children: [
...playlist.verses.map(
(e) => ListTile(
key: ValueKey(e.hashCode),
onTap: () {
ref.read(playlistPreviewSelectedObjectProvider.notifier).state = e;
},
selected: selected is SavedVerseSlides && selected == e,
title: Text(scriptureRefToRefString(e.scriptureRef))),
key: ValueKey(e.hashCode),
onTap: () {
ref.read(playlistPreviewSelectedObjectProvider.notifier).state = e;
},
selected: selected is SavedVerseSlides && selected == e,
title: Text(
scriptureRefToRefString(e.scriptureRef),
),
),
),
],
onReorder: (oldIndex, newIndex) {
Expand Down
2 changes: 1 addition & 1 deletion lib/notifiers/projected_slide_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ProjectedSlideNotifier extends StateNotifier<int?> {

if (slide.slideType == SlideType.song) {
ProjectionUtils.showSlide(slide.text, isLive);
} else {
} else if (slide.slideType == SlideType.scripture) {
String arguments = '${slide.text}<split>${slide.reference}';
ProjectionUtils.showSlide(arguments, isLive);
}
Expand Down
99 changes: 86 additions & 13 deletions lib/notifiers/slides_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,105 @@ class SlidesNotifier extends StateNotifier<List<Slide>> {
}

void _setMultipleScriptureSlides(Scripture scripture, int startVerse, int endVerse) {
state = scripture.verses!
List<Slide> temp = [];

scripture.verses!
.getRange(
startVerse - 1,
endVerse,
)
.map(
.forEach(
(verse) {
return Slide(
text: _getTextWithSuperscript(verse.num, verse.text),
reference: _scriptureRefToString(scripture.scriptureRef),
slideType: SlideType.scripture,
String text = _getTextWithSuperscript(verse.num, verse.text);

int maxChars = maxCharacters(
text,
const TextStyle(
fontFamily: 'LemonMilk',
fontSize: 80,
color: Colors.white,
),
);

if (text.length > maxChars) {
splitSlides(text, maxChars, scripture);

temp.addAll(splitSlides(text, maxChars, scripture));
} else {
temp.add(
Slide(
text: text,
reference: _scriptureRefToString(scripture.scriptureRef),
slideType: SlideType.scripture,
),
);
}
},
).toList();
);

state = temp;
}

void _setSingleScriptureSlide(Scripture scripture, int startVerse) {
Verse verse = scripture.verses![startVerse - 1];

state = [
Slide(
text: _getTextWithSuperscript(verse.num, verse.text),
reference: _scriptureRefToString(scripture.scriptureRef),
slideType: SlideType.scripture,
String text = _getTextWithSuperscript(verse.num, verse.text).trim();

int maxChars = maxCharacters(
text,
const TextStyle(
fontFamily: 'LemonMilk',
fontSize: 80,
color: Colors.white,
),
];
);

if (text.length > maxChars) {
state = splitSlides(text, maxChars, scripture);
} else {
state = [
Slide(
text: text,
reference: _scriptureRefToString(scripture.scriptureRef),
slideType: SlideType.scripture,
),
];
}
}

List<Slide> splitSlides(String text, int maxChars, Scripture scripture) {
int slideCount = text.length ~/ maxChars;

int charsPerSlide = text.length ~/ slideCount;

// split verse into slide count

List<Slide> temp = [];

int offset = 0;
for (var i = 0; i < slideCount; i++) {
int start = (i * charsPerSlide) - offset;
int end = start + charsPerSlide;

while (text[end - 1] != ' ') {
end--;
offset++;
}

if (i == slideCount - 1) end = text.length;

String slideText = text.substring(start, end);

temp.add(
Slide(
text: slideText,
reference: _scriptureRefToString(scripture.scriptureRef),
slideType: SlideType.scripture,
),
);
}

return temp;
}

String _getTextWithSuperscript(int number, String text) {
Expand Down
39 changes: 29 additions & 10 deletions lib/widgets/projection_slide_widget.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../core/constants.dart';

class ProjectionTextWidget extends StatelessWidget {
const ProjectionTextWidget({super.key, required this.text, required this.reference});
const ProjectionTextWidget({super.key, required this.text, required this.reference, required this.slideType});

final String reference;
final String text;
final SlideType slideType;

@override
Widget build(BuildContext context) {
Expand All @@ -19,15 +22,31 @@ class ProjectionTextWidget extends StatelessWidget {
children: [
Expanded(
child: Center(
child: Text(
text,
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: 'LemonMilk',
fontSize: 80,
color: Colors.white,
),
),
child: slideType == SlideType.song
? Text(
text,
maxLines: 10,
softWrap: true,
textAlign: TextAlign.center,
overflow: TextOverflow.fade,
style: const TextStyle(
fontFamily: 'LemonMilk',
fontSize: 80,
color: Colors.white,
),
)
: Text(
text,
maxLines: 10,
softWrap: true,
textAlign: TextAlign.center,
overflow: TextOverflow.fade,
style: const TextStyle(
fontFamily: 'SegoeUI',
fontSize: 80,
color: Colors.white,
),
),
),
),
if (reference.isNotEmpty)
Expand Down
14 changes: 6 additions & 8 deletions lib/windows/projection_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:dart_vlc/dart_vlc.dart';
import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:freecps/core/constants.dart';
import 'package:window_manager/window_manager.dart';

import '../widgets/projection_slide_widget.dart';
Expand All @@ -26,8 +27,6 @@ class _ProjectionWindowState extends State<ProjectionWindow> {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
// floatingActionButton: FloatingActionButton(onPressed: () {}),
// floatingActionButtonLocation: FloatingActionButtonLocation.miniStartFloat,
body: SizedBox.expand(
child: Stack(
children: [
Expand Down Expand Up @@ -80,14 +79,11 @@ class _ProjectionWindowState extends State<ProjectionWindow> {
List<String> args = (call.arguments as String).split('<split>');

if (args.length == 1) {
showNextSlide(args.first, '');
showNextSlide(args.first, '', SlideType.song);
return;
}

showNextSlide(
args[0],
args[1],
);
showNextSlide(args[0], args[1], SlideType.scripture);
}
},
);
Expand All @@ -109,17 +105,19 @@ class _ProjectionWindowState extends State<ProjectionWindow> {
player.open(file);
}

void showNextSlide(String text, String reference) {
void showNextSlide(String text, String reference, SlideType slideType) {
setState(() {
if (showingFirst) {
second = ProjectionTextWidget(
text: text,
reference: reference,
slideType: slideType,
);
} else {
first = ProjectionTextWidget(
text: text,
reference: reference,
slideType: slideType,
);
}

Expand Down
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ flutter:
- asset: fonts/LEMONMILK-Regular.otf
- asset: fonts/LEMONMILK-Bold.otf
weight: 700
- family: SegoeUI
fonts:
- asset: fonts/SEGOEUI.TTF

# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
Expand Down

0 comments on commit fb15081

Please sign in to comment.