Created with <3 with dartpad.dev.
Created
January 19, 2024 23:17
-
-
Save yjbanov/6b256a1c2df5657f6a5a3a07cf2eb03d to your computer and use it in GitHub Desktop.
hollow-durian-8275
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui' as ui; | |
void main() { | |
// Create a paragraph | |
var paragraphStyle = ui.ParagraphStyle( | |
fontFamily: 'Roboto', | |
textDirection: ui.TextDirection.ltr, | |
maxLines: 10, | |
); | |
var paragraphBuilder = ui.ParagraphBuilder(paragraphStyle); | |
paragraphBuilder.addText('Hello, World!'); | |
var paragraph = paragraphBuilder.build(); | |
// Lay out a paragraph | |
paragraph.layout(const ui.ParagraphConstraints( | |
width: 30, | |
)); | |
print('height: ${paragraph.height}'); // 64 | |
print('width: ${paragraph.width}'); // 30 | |
print('longestLine: ${paragraph.longestLine}'); // 28.328125 | |
print('maxIntrinsicWidth: ${paragraph.maxIntrinsicWidth}'); // 78.216796875 | |
print('minIntrinsicWidth: ${paragraph.minIntrinsicWidth}'); // 36.2236328125 | |
// Render a paragraph | |
var recorder = ui.PictureRecorder(); | |
var canvas = ui.Canvas(recorder); | |
canvas.drawColor(const ui.Color(0xFFFFFFFF), ui.BlendMode.dstOver); | |
canvas.drawParagraph(paragraph, const ui.Offset(10, 10)); | |
var picture = recorder.endRecording(); | |
// Present to screen | |
var dispatcher = ui.PlatformDispatcher.instance; | |
dispatcher.onDrawFrame = () { | |
var sb = ui.SceneBuilder(); | |
sb.pushOffset(0, 0); | |
sb.addPicture(ui.Offset.zero, picture); | |
sb.pop(); | |
var scene = sb.build(); | |
dispatcher.implicitView!.render(scene); | |
}; | |
dispatcher.scheduleFrame(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment