mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 07:18:15 +00:00
[Gallery] Fix directory structure (#312)
This commit is contained in:
42
gallery/lib/layout/text_scale.dart
Normal file
42
gallery/lib/layout/text_scale.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:gallery/data/gallery_options.dart';
|
||||
|
||||
double _textScaleFactor(BuildContext context) {
|
||||
return GalleryOptions.of(context).textScaleFactor(context);
|
||||
}
|
||||
|
||||
// When text is larger, this factor becomes larger, but at half the rate.
|
||||
//
|
||||
// | Text scaling | Text scale factor | reducedTextScale(context) |
|
||||
// |--------------|-------------------|---------------------------|
|
||||
// | Small | 0.8 | 1.0 |
|
||||
// | Normal | 1.0 | 1.0 |
|
||||
// | Large | 2.0 | 1.5 |
|
||||
// | Huge | 3.0 | 2.0 |
|
||||
|
||||
double reducedTextScale(BuildContext context) {
|
||||
double textScaleFactor = _textScaleFactor(context);
|
||||
return textScaleFactor >= 1 ? (1 + textScaleFactor) / 2 : 1;
|
||||
}
|
||||
|
||||
// When text is larger, this factor becomes larger at the same rate.
|
||||
// But when text is smaller, this factor stays at 1.
|
||||
//
|
||||
// | Text scaling | Text scale factor | cappedTextScale(context) |
|
||||
// |--------------|-------------------|---------------------------|
|
||||
// | Small | 0.8 | 1.0 |
|
||||
// | Normal | 1.0 | 1.0 |
|
||||
// | Large | 2.0 | 2.0 |
|
||||
// | Huge | 3.0 | 3.0 |
|
||||
|
||||
double cappedTextScale(BuildContext context) {
|
||||
double textScaleFactor = _textScaleFactor(context);
|
||||
return max(textScaleFactor, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user