Created
March 17, 2022 09:49
-
-
Save hotdang-ca/c6b6d1568a90602126aa3afbb36a412f to your computer and use it in GitHub Desktop.
Screen resolutions, in Dart
This file contains hidden or 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
| /// Describes a television screen resolution | |
| class ResolutionSize { | |
| /// The natural width of this resolution | |
| final int width; | |
| /// The natural height of this resolution | |
| final int height; | |
| /// A shorter technical name | |
| final String name; | |
| /// A longer marketing name | |
| final String marketingName; | |
| ResolutionSize({ | |
| required this.width, | |
| required this.height, | |
| required this.name, | |
| required this.marketingName, | |
| }); | |
| /// If we are a vertical or portrait orientation, the width | |
| int get widthAsVertical => height; | |
| /// If we are a vertical or portrait orientation, the width | |
| int get widthAsPortrait => height; | |
| /// If we are a vertical or portrait orientation, the height | |
| int get heightAsVertical => width; | |
| /// If we are a vertical or portrait orientation, the height | |
| int get heightAsPortrait => width; | |
| /// If we are a horizontal or landscape orientation, the width | |
| int get widthAsHorizontal => width; | |
| /// If we are a horizontal or landscape orientation, the height | |
| int get heightAsHorizontal => height; | |
| /// If we are a horizontal or landscape orientation, the width | |
| int get widthAsLandscape => width; | |
| /// If we are a horizontal or landscape orientation, the height | |
| int get heightAsLandscape => height; | |
| /// Pixel count of [this] | |
| int get pixelCount => height * width; | |
| } | |
| class Resolution { | |
| /// Do you remember the 90s? I remember the 90s... This is the standard resolution | |
| static ResolutionSize SD = ResolutionSize(width: 640, height: 480, name: '480p', marketingName: 'Standard Definition'); | |
| /// Standard HD, 720p | |
| static ResolutionSize HD = ResolutionSize(width: 1280, height: 720, name: '720p', marketingName: 'HD-Ready'); | |
| /// Full HD, 1080p | |
| static ResolutionSize FHD = ResolutionSize(width: 1920, height: 1080, name: '1080p', marketingName: 'Full HD'); | |
| /// Quad HD, 1440p | |
| static ResolutionSize QHD = ResolutionSize(width: 2560, height: 1440, name: '1440p', marketingName: 'Quad HD'); | |
| /// Ultra HD or '4K', 2160p | |
| static ResolutionSize UHD = ResolutionSize(width: 3840, height: 2160, name: '2160p', marketingName: '4K Ultra HD'); | |
| /// Quad Ultra HD or '8K', 4320p | |
| static ResolutionSize QUHD = ResolutionSize(width: 7680, height: 4320, name: '4320p', marketingName: '8K Ultra HD'); | |
| } | |
| void main() { | |
| for (final ResolutionSize resolution in <ResolutionSize>[ | |
| Resolution.SD, | |
| Resolution.HD, | |
| Resolution.FHD, | |
| Resolution.QHD, | |
| Resolution.UHD, | |
| Resolution.QUHD, | |
| ]) { | |
| print ('Horizontal ${resolution.marketingName}: ${resolution.widthAsHorizontal} x ${resolution.heightAsHorizontal} (${resolution.name})'); | |
| print ('Vertical ${resolution.marketingName}: ${resolution.widthAsVertical} x ${resolution.heightAsVertical} (${resolution.name})'); | |
| print ('${resolution.marketingName} pixels: ${resolution.pixelCount}'); | |
| print (''); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment