TextPainter RTL (#11888)
This commit is contained in:
7
examples/hello_world/README.md
Normal file
7
examples/hello_world/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
```
|
||||
# To run the Hello World demo:
|
||||
flutter run
|
||||
|
||||
# To run the Hello World demo showing Arabic:
|
||||
flutter run lib/arabic.dart
|
||||
```
|
||||
7
examples/hello_world/lib/arabic.dart
Normal file
7
examples/hello_world/lib/arabic.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() => runApp(const Center(child: const Text('برنامج أهلا بالعالم', textDirection: TextDirection.rtl)));
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() => runApp(const Center(child: const Text('Hello, world!')));
|
||||
void main() => runApp(const Center(child: const Text('Hello, world!', textDirection: TextDirection.ltr)));
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() => runApp(const Center(child: const Text('flutter run -t xxx/yyy.dart')));
|
||||
void main() => runApp(const Center(child: const Text('flutter run -t xxx/yyy.dart', textDirection: TextDirection.ltr)));
|
||||
|
||||
@@ -11,7 +11,9 @@ void beginFrame(Duration timeStamp) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
|
||||
|
||||
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
|
||||
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder(
|
||||
new ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
..addText('Hello, world.');
|
||||
final ui.Paragraph paragraph = paragraphBuilder.build()
|
||||
..layout(new ui.ParagraphConstraints(width: logicalSize.width));
|
||||
|
||||
@@ -52,7 +52,13 @@ void beginFrame(Duration timeStamp) {
|
||||
|
||||
void main() {
|
||||
// To create a paragraph of text, we use ParagraphBuilder.
|
||||
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(new ui.ParagraphStyle())
|
||||
final ui.ParagraphBuilder builder = new ui.ParagraphBuilder(
|
||||
// The text below has a primary direction of left-to-right.
|
||||
// The embedded text has other directions.
|
||||
// If this was TextDirection.rtl, the "Hello, world" text would end up on
|
||||
// the other side of the right-to-left text.
|
||||
new ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
// We first push a style that turns the text blue.
|
||||
..pushStyle(new ui.TextStyle(color: const ui.Color(0xFF0000FF)))
|
||||
..addText('Hello, ')
|
||||
|
||||
@@ -14,24 +14,36 @@ void main() {
|
||||
|
||||
void addAlignmentRow(CrossAxisAlignment crossAxisAlignment) {
|
||||
TextStyle style = const TextStyle(color: const Color(0xFF000000));
|
||||
final RenderParagraph paragraph = new RenderParagraph(new TextSpan(style: style, text: '$crossAxisAlignment'));
|
||||
final RenderParagraph paragraph = new RenderParagraph(
|
||||
new TextSpan(style: style, text: '$crossAxisAlignment'),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
|
||||
final RenderFlex row = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic);
|
||||
style = const TextStyle(fontSize: 15.0, color: const Color(0xFF000000));
|
||||
row.add(new RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: const Color(0x7FFFCCCC)),
|
||||
child: new RenderParagraph(new TextSpan(style: style, text: 'foo foo foo'))
|
||||
child: new RenderParagraph(
|
||||
new TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
));
|
||||
style = const TextStyle(fontSize: 10.0, color: const Color(0xFF000000));
|
||||
row.add(new RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: const Color(0x7FCCFFCC)),
|
||||
child: new RenderParagraph(new TextSpan(style: style, text: 'foo foo foo'))
|
||||
child: new RenderParagraph(
|
||||
new TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
));
|
||||
final RenderFlex subrow = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic);
|
||||
style = const TextStyle(fontSize: 25.0, color: const Color(0xFF000000));
|
||||
subrow.add(new RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: const Color(0x7FCCCCFF)),
|
||||
child: new RenderParagraph(new TextSpan(style: style, text: 'foo foo foo foo'))
|
||||
child: new RenderParagraph(
|
||||
new TextSpan(style: style, text: 'foo foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
));
|
||||
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
|
||||
row.add(subrow);
|
||||
@@ -48,7 +60,10 @@ void main() {
|
||||
|
||||
void addJustificationRow(MainAxisAlignment justify) {
|
||||
const TextStyle style = const TextStyle(color: const Color(0xFF000000));
|
||||
final RenderParagraph paragraph = new RenderParagraph(new TextSpan(style: style, text: '$justify'));
|
||||
final RenderParagraph paragraph = new RenderParagraph(
|
||||
new TextSpan(style: style, text: '$justify'),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
|
||||
final RenderFlex row = new RenderFlex(direction: Axis.horizontal);
|
||||
row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0)));
|
||||
|
||||
@@ -16,7 +16,14 @@ void main() {
|
||||
alignment: FractionalOffset.center,
|
||||
// We use a RenderParagraph to display the text 'Hello, world.' without
|
||||
// any explicit styling.
|
||||
child: new RenderParagraph(const TextSpan(text: 'Hello, world.'))
|
||||
child: new RenderParagraph(
|
||||
const TextSpan(text: 'Hello, world.'),
|
||||
// The text is in English so we specify the text direction as
|
||||
// left-to-right. If the text had been in Hebrew or Arabic, we would
|
||||
// have specified right-to-left. The Flutter framework does not assume a
|
||||
// particular text direction.
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -104,8 +104,9 @@ void main() {
|
||||
final RenderParagraph paragraph = new RenderParagraph(
|
||||
const TextSpan(
|
||||
style: const TextStyle(color: Colors.black87),
|
||||
text: "Touch me!"
|
||||
)
|
||||
text: "Touch me!",
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
// A stack is a render object that layers its children on top of each other.
|
||||
// The bottom later is our RenderDots object, and on top of that we show the
|
||||
@@ -114,7 +115,7 @@ void main() {
|
||||
children: <RenderBox>[
|
||||
new RenderDots(),
|
||||
paragraph,
|
||||
]
|
||||
],
|
||||
);
|
||||
// The "parentData" field of a render object is controlled by the render
|
||||
// object's parent render object. Now that we've added the paragraph as a
|
||||
|
||||
13
examples/layers/test/smoketests/lib/main_test.dart
Normal file
13
examples/layers/test/smoketests/lib/main_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../lib/main.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for lib/main.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/raw/canvas_test.dart
Normal file
13
examples/layers/test/smoketests/raw/canvas_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../raw/canvas.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for raw/canvas.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/raw/hello_world_test.dart
Normal file
13
examples/layers/test/smoketests/raw/hello_world_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../raw/hello_world.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for raw/hello_world.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../raw/spinning_square.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for raw/spinning_square.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/raw/text_test.dart
Normal file
13
examples/layers/test/smoketests/raw/text_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../raw/text.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for raw/text.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/raw/touch_input_test.dart
Normal file
13
examples/layers/test/smoketests/raw/touch_input_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../raw/touch_input.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for raw/touch_input.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../rendering/custom_coordinate_systems.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/custom_coordinate_systems.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../rendering/flex_layout.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/flex_layout.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../rendering/hello_world.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/hello_world.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../rendering/spinning_square.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/spinning_square.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../rendering/touch_input.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/touch_input.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/services/isolate_test.dart
Normal file
13
examples/layers/test/smoketests/services/isolate_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../services/isolate.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for services/isolate.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/services/lifecycle_test.dart
Normal file
13
examples/layers/test/smoketests/services/lifecycle_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../services/lifecycle.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for services/lifecycle.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/custom_render_box.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/custom_render_box.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/widgets/gestures_test.dart
Normal file
13
examples/layers/test/smoketests/widgets/gestures_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/gestures.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/gestures.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/hello_world.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/hello_world.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/media_query.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/media_query.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
13
examples/layers/test/smoketests/widgets/sectors_test.dart
Normal file
13
examples/layers/test/smoketests/widgets/sectors_test.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/sectors.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/sectors.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/spinning_mixed.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/spinning_mixed.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/spinning_square.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/spinning_square.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../widgets/styled_text.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/styled_text.dart', () {
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() => runApp(const Center(child: const Text('Hello, world!')));
|
||||
void main() => runApp(const Center(child: const Text('Hello, world!', textDirection: TextDirection.ltr)));
|
||||
|
||||
@@ -37,40 +37,43 @@ BuildOwner owner = new BuildOwner();
|
||||
void attachWidgetTreeToRenderTree(RenderProxyBox container) {
|
||||
element = new RenderObjectToWidgetAdapter<RenderBox>(
|
||||
container: container,
|
||||
child: new Container(
|
||||
height: 300.0,
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
const Rectangle(const Color(0xFF00FFFF)),
|
||||
new Material(
|
||||
child: new Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
margin: const EdgeInsets.all(10.0),
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
new RaisedButton(
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
new Image.network('https://flutter.io/images/favicon.png'),
|
||||
const Text('PRESS ME'),
|
||||
]
|
||||
child: new Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: new Container(
|
||||
height: 300.0,
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
const Rectangle(const Color(0xFF00FFFF)),
|
||||
new Material(
|
||||
child: new Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
margin: const EdgeInsets.all(10.0),
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
new RaisedButton(
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
new Image.network('https://flutter.io/images/favicon.png'),
|
||||
const Text('PRESS ME'),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
value = value == null ? 0.1 : (value + 0.1) % 1.0;
|
||||
attachWidgetTreeToRenderTree(container);
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
value = value == null ? 0.1 : (value + 0.1) % 1.0;
|
||||
attachWidgetTreeToRenderTree(container);
|
||||
}
|
||||
),
|
||||
new CircularProgressIndicator(value: value),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround
|
||||
)
|
||||
)
|
||||
),
|
||||
const Rectangle(const Color(0xFFFFFF00)),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween
|
||||
)
|
||||
)
|
||||
new CircularProgressIndicator(value: value),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Rectangle(const Color(0xFFFFFF00)),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
),
|
||||
),
|
||||
),
|
||||
).attachToRenderTree(owner, element);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user