Showing
4 changed files
with
171 additions
and
45 deletions
| @@ -60,6 +60,7 @@ class MyHomePage extends StatefulWidget { | @@ -60,6 +60,7 @@ class MyHomePage extends StatefulWidget { | ||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | class _MyHomePageState extends State<MyHomePage> { | 62 | class _MyHomePageState extends State<MyHomePage> { |
| 63 | + TextDirection _direction = TextDirection.ltr; | ||
| 63 | final TextEditingController _controller = TextEditingController(text: r''' | 64 | final TextEditingController _controller = TextEditingController(text: r''' |
| 64 | # hi how are you?$my is^2$ | 65 | # hi how are you?$my is^2$ |
| 65 | ## hi how are you$(\frac ab)^2$? | 66 | ## hi how are you$(\frac ab)^2$? |
| @@ -97,6 +98,14 @@ $hello$ | @@ -97,6 +98,14 @@ $hello$ | ||
| 97 | title: Text(widget.title), | 98 | title: Text(widget.title), |
| 98 | actions: [ | 99 | actions: [ |
| 99 | IconButton( | 100 | IconButton( |
| 101 | + onPressed: () { | ||
| 102 | + setState(() { | ||
| 103 | + _direction = TextDirection.values[(_direction.index + 1) % 2]; | ||
| 104 | + }); | ||
| 105 | + }, | ||
| 106 | + icon: const [Text("LTR"), Text("RTL")][_direction.index], | ||
| 107 | + ), | ||
| 108 | + IconButton( | ||
| 100 | onPressed: widget.onPressed, | 109 | onPressed: widget.onPressed, |
| 101 | icon: const Icon(Icons.sunny), | 110 | icon: const Icon(Icons.sunny), |
| 102 | ), | 111 | ), |
| @@ -123,16 +132,20 @@ $hello$ | @@ -123,16 +132,20 @@ $hello$ | ||
| 123 | LayoutBuilder(builder: (context, constraints) { | 132 | LayoutBuilder(builder: (context, constraints) { |
| 124 | return SingleChildScrollView( | 133 | return SingleChildScrollView( |
| 125 | scrollDirection: Axis.horizontal, | 134 | scrollDirection: Axis.horizontal, |
| 126 | - child: TexMarkdown( | ||
| 127 | - _controller.text, | ||
| 128 | - textDirection: TextDirection.rtl, | ||
| 129 | - onLinkTab: (url, title) { | ||
| 130 | - log(title, name: "title"); | ||
| 131 | - log(url, name: "url"); | ||
| 132 | - }, | ||
| 133 | - style: const TextStyle( | ||
| 134 | - // color: Colors.green, | ||
| 135 | - ), | 135 | + reverse: _direction == TextDirection.rtl, |
| 136 | + child: SizedBox( | ||
| 137 | + width: 400, | ||
| 138 | + child: TexMarkdown( | ||
| 139 | + _controller.text, | ||
| 140 | + textDirection: _direction, | ||
| 141 | + onLinkTab: (url, title) { | ||
| 142 | + log(title, name: "title"); | ||
| 143 | + log(url, name: "url"); | ||
| 144 | + }, | ||
| 145 | + style: const TextStyle( | ||
| 146 | + // color: Colors.green, | ||
| 147 | + ), | ||
| 148 | + ), | ||
| 136 | ), | 149 | ), |
| 137 | ); | 150 | ); |
| 138 | }), | 151 | }), |
| @@ -10,11 +10,17 @@ enum CustomRbSlot { | @@ -10,11 +10,17 @@ enum CustomRbSlot { | ||
| 10 | 10 | ||
| 11 | class CustomRb | 11 | class CustomRb |
| 12 | extends SlottedMultiChildRenderObjectWidget<CustomRbSlot, RenderBox> { | 12 | extends SlottedMultiChildRenderObjectWidget<CustomRbSlot, RenderBox> { |
| 13 | - const CustomRb( | ||
| 14 | - {super.key, this.spacing = 5, required this.child, required this.value}); | 13 | + const CustomRb({ |
| 14 | + super.key, | ||
| 15 | + this.spacing = 5, | ||
| 16 | + required this.child, | ||
| 17 | + this.textDirection = TextDirection.ltr, | ||
| 18 | + required this.value, | ||
| 19 | + }); | ||
| 15 | final Widget child; | 20 | final Widget child; |
| 16 | final bool value; | 21 | final bool value; |
| 17 | final double spacing; | 22 | final double spacing; |
| 23 | + final TextDirection textDirection; | ||
| 18 | 24 | ||
| 19 | @override | 25 | @override |
| 20 | Widget? childForSlot(CustomRbSlot slot) { | 26 | Widget? childForSlot(CustomRbSlot slot) { |
| @@ -34,13 +40,14 @@ class CustomRb | @@ -34,13 +40,14 @@ class CustomRb | ||
| 34 | @override | 40 | @override |
| 35 | SlottedContainerRenderObjectMixin<CustomRbSlot, RenderBox> createRenderObject( | 41 | SlottedContainerRenderObjectMixin<CustomRbSlot, RenderBox> createRenderObject( |
| 36 | BuildContext context) { | 42 | BuildContext context) { |
| 37 | - return RenderCustomRb(spacing); | 43 | + return RenderCustomRb(spacing, textDirection); |
| 38 | } | 44 | } |
| 39 | 45 | ||
| 40 | @override | 46 | @override |
| 41 | void updateRenderObject( | 47 | void updateRenderObject( |
| 42 | BuildContext context, covariant RenderCustomRb renderObject) { | 48 | BuildContext context, covariant RenderCustomRb renderObject) { |
| 43 | renderObject.spacing = spacing; | 49 | renderObject.spacing = spacing; |
| 50 | + renderObject.textDirection = textDirection; | ||
| 44 | } | 51 | } |
| 45 | 52 | ||
| 46 | @override | 53 | @override |
| @@ -49,8 +56,17 @@ class CustomRb | @@ -49,8 +56,17 @@ class CustomRb | ||
| 49 | 56 | ||
| 50 | class RenderCustomRb extends RenderBox | 57 | class RenderCustomRb extends RenderBox |
| 51 | with SlottedContainerRenderObjectMixin<CustomRbSlot, RenderBox> { | 58 | with SlottedContainerRenderObjectMixin<CustomRbSlot, RenderBox> { |
| 52 | - RenderCustomRb(this._spacing); | 59 | + RenderCustomRb(this._spacing, this._textDirection); |
| 53 | double _spacing; | 60 | double _spacing; |
| 61 | + TextDirection _textDirection; | ||
| 62 | + set textDirection(TextDirection value) { | ||
| 63 | + if (_textDirection == value) { | ||
| 64 | + return; | ||
| 65 | + } | ||
| 66 | + _textDirection = value; | ||
| 67 | + markNeedsLayout(); | ||
| 68 | + } | ||
| 69 | + | ||
| 54 | set spacing(double value) { | 70 | set spacing(double value) { |
| 55 | if (_spacing == value) { | 71 | if (_spacing == value) { |
| 56 | return; | 72 | return; |
| @@ -80,14 +96,24 @@ class RenderCustomRb extends RenderBox | @@ -80,14 +96,24 @@ class RenderCustomRb extends RenderBox | ||
| 80 | body!, | 96 | body!, |
| 81 | BoxConstraints( | 97 | BoxConstraints( |
| 82 | maxWidth: constraints.maxWidth - rbSize.width - _spacing)); | 98 | maxWidth: constraints.maxWidth - rbSize.width - _spacing)); |
| 83 | - body!.parentData = BoxParentData() | ||
| 84 | - ..offset = Offset(rbSize.width + _spacing, 0); | ||
| 85 | - rb!.parentData = BoxParentData() | ||
| 86 | - ..offset = Offset( | ||
| 87 | - 0, | ||
| 88 | - body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - | ||
| 89 | - rb!.size.height / 1.5, | ||
| 90 | - ); | 99 | + if (_textDirection == TextDirection.ltr) { |
| 100 | + body!.parentData = BoxParentData() | ||
| 101 | + ..offset = Offset(rbSize.width + _spacing, 0); | ||
| 102 | + rb!.parentData = BoxParentData() | ||
| 103 | + ..offset = Offset( | ||
| 104 | + 0, | ||
| 105 | + body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - | ||
| 106 | + rb!.size.height / 1.5, | ||
| 107 | + ); | ||
| 108 | + } else { | ||
| 109 | + body!.parentData = BoxParentData()..offset = Offset(-_spacing, 0); | ||
| 110 | + rb!.parentData = BoxParentData() | ||
| 111 | + ..offset = Offset( | ||
| 112 | + bodySize.width, | ||
| 113 | + body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - | ||
| 114 | + rb!.size.height / 1.5, | ||
| 115 | + ); | ||
| 116 | + } | ||
| 91 | size = constraints.constrain(Size(bodySize.width + rbSize.width + _spacing, | 117 | size = constraints.constrain(Size(bodySize.width + rbSize.width + _spacing, |
| 92 | max(rbSize.height, bodySize.height))); | 118 | max(rbSize.height, bodySize.height))); |
| 93 | } | 119 | } |
| @@ -132,8 +158,13 @@ enum CustomCbSlot { | @@ -132,8 +158,13 @@ enum CustomCbSlot { | ||
| 132 | class CustomCb | 158 | class CustomCb |
| 133 | extends SlottedMultiChildRenderObjectWidget<CustomCbSlot, RenderBox> { | 159 | extends SlottedMultiChildRenderObjectWidget<CustomCbSlot, RenderBox> { |
| 134 | const CustomCb( | 160 | const CustomCb( |
| 135 | - {super.key, this.spacing = 5, required this.child, required this.value}); | 161 | + {super.key, |
| 162 | + this.spacing = 5, | ||
| 163 | + this.textDirection = TextDirection.ltr, | ||
| 164 | + required this.child, | ||
| 165 | + required this.value}); | ||
| 136 | final Widget child; | 166 | final Widget child; |
| 167 | + final TextDirection textDirection; | ||
| 137 | final bool value; | 168 | final bool value; |
| 138 | final double spacing; | 169 | final double spacing; |
| 139 | 170 | ||
| @@ -150,13 +181,14 @@ class CustomCb | @@ -150,13 +181,14 @@ class CustomCb | ||
| 150 | @override | 181 | @override |
| 151 | SlottedContainerRenderObjectMixin<CustomCbSlot, RenderBox> createRenderObject( | 182 | SlottedContainerRenderObjectMixin<CustomCbSlot, RenderBox> createRenderObject( |
| 152 | BuildContext context) { | 183 | BuildContext context) { |
| 153 | - return RenderCustomCb(spacing); | 184 | + return RenderCustomCb(spacing, textDirection); |
| 154 | } | 185 | } |
| 155 | 186 | ||
| 156 | @override | 187 | @override |
| 157 | void updateRenderObject( | 188 | void updateRenderObject( |
| 158 | BuildContext context, covariant RenderCustomCb renderObject) { | 189 | BuildContext context, covariant RenderCustomCb renderObject) { |
| 159 | renderObject.spacing = spacing; | 190 | renderObject.spacing = spacing; |
| 191 | + renderObject.textDirection = textDirection; | ||
| 160 | } | 192 | } |
| 161 | 193 | ||
| 162 | @override | 194 | @override |
| @@ -165,8 +197,17 @@ class CustomCb | @@ -165,8 +197,17 @@ class CustomCb | ||
| 165 | 197 | ||
| 166 | class RenderCustomCb extends RenderBox | 198 | class RenderCustomCb extends RenderBox |
| 167 | with SlottedContainerRenderObjectMixin<CustomCbSlot, RenderBox> { | 199 | with SlottedContainerRenderObjectMixin<CustomCbSlot, RenderBox> { |
| 168 | - RenderCustomCb(this._spacing); | 200 | + RenderCustomCb(this._spacing, this._textDirection); |
| 169 | double _spacing; | 201 | double _spacing; |
| 202 | + TextDirection _textDirection; | ||
| 203 | + set textDirection(TextDirection value) { | ||
| 204 | + if (_textDirection == value) { | ||
| 205 | + return; | ||
| 206 | + } | ||
| 207 | + _textDirection = value; | ||
| 208 | + markNeedsLayout(); | ||
| 209 | + } | ||
| 210 | + | ||
| 170 | set spacing(double value) { | 211 | set spacing(double value) { |
| 171 | if (_spacing == value) { | 212 | if (_spacing == value) { |
| 172 | return; | 213 | return; |
| @@ -196,13 +237,22 @@ class RenderCustomCb extends RenderBox | @@ -196,13 +237,22 @@ class RenderCustomCb extends RenderBox | ||
| 196 | body!, | 237 | body!, |
| 197 | BoxConstraints( | 238 | BoxConstraints( |
| 198 | maxWidth: constraints.maxWidth - rbSize.width - _spacing)); | 239 | maxWidth: constraints.maxWidth - rbSize.width - _spacing)); |
| 199 | - body!.parentData = BoxParentData() | ||
| 200 | - ..offset = Offset(rbSize.width + _spacing, 0); | ||
| 201 | - rb!.parentData = BoxParentData() | ||
| 202 | - ..offset = Offset( | ||
| 203 | - 0, | ||
| 204 | - body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - | ||
| 205 | - rb!.size.height / 1.5); | 240 | + if (_textDirection == TextDirection.ltr) { |
| 241 | + body!.parentData = BoxParentData() | ||
| 242 | + ..offset = Offset(rbSize.width + _spacing, 0); | ||
| 243 | + rb!.parentData = BoxParentData() | ||
| 244 | + ..offset = Offset( | ||
| 245 | + 0, | ||
| 246 | + body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - | ||
| 247 | + rb!.size.height / 1.5); | ||
| 248 | + } else { | ||
| 249 | + body!.parentData = BoxParentData()..offset = Offset(-_spacing, 0); | ||
| 250 | + rb!.parentData = BoxParentData() | ||
| 251 | + ..offset = Offset( | ||
| 252 | + bodySize.width, | ||
| 253 | + body!.computeDistanceToActualBaseline(TextBaseline.alphabetic)! - | ||
| 254 | + rb!.size.height / 1.5); | ||
| 255 | + } | ||
| 206 | size = constraints.constrain(Size(bodySize.width + rbSize.width + _spacing, | 256 | size = constraints.constrain(Size(bodySize.width + rbSize.width + _spacing, |
| 207 | max(rbSize.height, bodySize.height))); | 257 | max(rbSize.height, bodySize.height))); |
| 208 | } | 258 | } |
| @@ -8,10 +8,12 @@ class UnorderedListView extends SingleChildRenderObjectWidget { | @@ -8,10 +8,12 @@ class UnorderedListView extends SingleChildRenderObjectWidget { | ||
| 8 | this.padding = 10, | 8 | this.padding = 10, |
| 9 | this.bulletColor, | 9 | this.bulletColor, |
| 10 | this.bulletSize = 4, | 10 | this.bulletSize = 4, |
| 11 | + this.textDirection = TextDirection.ltr, | ||
| 11 | required super.child}); | 12 | required super.child}); |
| 12 | final double bulletSize; | 13 | final double bulletSize; |
| 13 | final double spacing; | 14 | final double spacing; |
| 14 | final double padding; | 15 | final double padding; |
| 16 | + final TextDirection textDirection; | ||
| 15 | final Color? bulletColor; | 17 | final Color? bulletColor; |
| 16 | 18 | ||
| 17 | @override | 19 | @override |
| @@ -20,6 +22,7 @@ class UnorderedListView extends SingleChildRenderObjectWidget { | @@ -20,6 +22,7 @@ class UnorderedListView extends SingleChildRenderObjectWidget { | ||
| 20 | spacing, | 22 | spacing, |
| 21 | padding, | 23 | padding, |
| 22 | bulletColor ?? Theme.of(context).colorScheme.onSurface, | 24 | bulletColor ?? Theme.of(context).colorScheme.onSurface, |
| 25 | + textDirection, | ||
| 23 | bulletSize, | 26 | bulletSize, |
| 24 | ); | 27 | ); |
| 25 | } | 28 | } |
| @@ -32,6 +35,7 @@ class UnorderedListView extends SingleChildRenderObjectWidget { | @@ -32,6 +35,7 @@ class UnorderedListView extends SingleChildRenderObjectWidget { | ||
| 32 | renderObject.bulletSize = bulletSize; | 35 | renderObject.bulletSize = bulletSize; |
| 33 | renderObject.spacing = spacing; | 36 | renderObject.spacing = spacing; |
| 34 | renderObject.padding = padding; | 37 | renderObject.padding = padding; |
| 38 | + renderObject.textDirection = textDirection; | ||
| 35 | } | 39 | } |
| 36 | } | 40 | } |
| 37 | 41 | ||
| @@ -40,15 +44,18 @@ class UnorderedListRenderObject extends RenderProxyBox { | @@ -40,15 +44,18 @@ class UnorderedListRenderObject extends RenderProxyBox { | ||
| 40 | double spacing, | 44 | double spacing, |
| 41 | double padding, | 45 | double padding, |
| 42 | Color bulletColor, | 46 | Color bulletColor, |
| 47 | + TextDirection textDirection, | ||
| 43 | this._bulletSize, { | 48 | this._bulletSize, { |
| 44 | RenderBox? child, | 49 | RenderBox? child, |
| 45 | }) : _bulletColor = bulletColor, | 50 | }) : _bulletColor = bulletColor, |
| 46 | _spacing = spacing, | 51 | _spacing = spacing, |
| 47 | _padding = padding, | 52 | _padding = padding, |
| 53 | + _textDirection = textDirection, | ||
| 48 | super(child); | 54 | super(child); |
| 49 | double _spacing; | 55 | double _spacing; |
| 50 | double _padding; | 56 | double _padding; |
| 51 | Offset _bulletOffset = Offset.zero; | 57 | Offset _bulletOffset = Offset.zero; |
| 58 | + TextDirection _textDirection; | ||
| 52 | set spacing(double value) { | 59 | set spacing(double value) { |
| 53 | if (_spacing == value) { | 60 | if (_spacing == value) { |
| 54 | return; | 61 | return; |
| @@ -65,6 +72,15 @@ class UnorderedListRenderObject extends RenderProxyBox { | @@ -65,6 +72,15 @@ class UnorderedListRenderObject extends RenderProxyBox { | ||
| 65 | markNeedsLayout(); | 72 | markNeedsLayout(); |
| 66 | } | 73 | } |
| 67 | 74 | ||
| 75 | + set textDirection(TextDirection value) { | ||
| 76 | + if (_textDirection == value) { | ||
| 77 | + return; | ||
| 78 | + } | ||
| 79 | + _textDirection = value; | ||
| 80 | + markNeedsLayout(); | ||
| 81 | + markNeedsPaint(); | ||
| 82 | + } | ||
| 83 | + | ||
| 68 | Color _bulletColor; | 84 | Color _bulletColor; |
| 69 | double _bulletSize; | 85 | double _bulletSize; |
| 70 | set bulletSize(double value) { | 86 | set bulletSize(double value) { |
| @@ -139,10 +155,20 @@ class UnorderedListRenderObject extends RenderProxyBox { | @@ -139,10 +155,20 @@ class UnorderedListRenderObject extends RenderProxyBox { | ||
| 139 | constraints.maxWidth - _spacing - 6 - _bulletSize - _padding, | 155 | constraints.maxWidth - _spacing - 6 - _bulletSize - _padding, |
| 140 | ), | 156 | ), |
| 141 | parentUsesSize: true); | 157 | parentUsesSize: true); |
| 142 | - child!.parentData = BoxParentData() | ||
| 143 | - ..offset = Offset(_spacing + _padding + 6 + _bulletSize, 0); | ||
| 144 | - var value = child!.computeDistanceToActualBaseline(TextBaseline.alphabetic); | ||
| 145 | - _bulletOffset = Offset(4 + _padding, value! - _bulletSize); | 158 | + if (_textDirection == TextDirection.ltr) { |
| 159 | + child!.parentData = BoxParentData() | ||
| 160 | + ..offset = Offset(_spacing + _padding + 6 + _bulletSize, 0); | ||
| 161 | + var value = | ||
| 162 | + child!.computeDistanceToActualBaseline(TextBaseline.alphabetic); | ||
| 163 | + _bulletOffset = Offset(4 + _padding, value! - _bulletSize); | ||
| 164 | + } else { | ||
| 165 | + child!.parentData = BoxParentData() | ||
| 166 | + ..offset = Offset(-_spacing - _padding + 6 + _bulletSize, 0); | ||
| 167 | + var value = | ||
| 168 | + child!.computeDistanceToActualBaseline(TextBaseline.alphabetic); | ||
| 169 | + _bulletOffset = | ||
| 170 | + Offset(child!.size.width - 4 + _padding, value! - _bulletSize); | ||
| 171 | + } | ||
| 146 | size = constraints.constrain(Size( | 172 | size = constraints.constrain(Size( |
| 147 | child!.size.width + _spacing + _padding + 6 + _bulletSize, | 173 | child!.size.width + _spacing + _padding + 6 + _bulletSize, |
| 148 | child!.size.height)); | 174 | child!.size.height)); |
| @@ -153,10 +179,17 @@ class UnorderedListRenderObject extends RenderProxyBox { | @@ -153,10 +179,17 @@ class UnorderedListRenderObject extends RenderProxyBox { | ||
| 153 | if (child == null) { | 179 | if (child == null) { |
| 154 | return; | 180 | return; |
| 155 | } | 181 | } |
| 156 | - context.paintChild( | ||
| 157 | - child!, offset + (child!.parentData as BoxParentData).offset); | ||
| 158 | - context.canvas.drawCircle( | ||
| 159 | - offset + _bulletOffset, _bulletSize, Paint()..color = _bulletColor); | 182 | + if (_textDirection == TextDirection.ltr) { |
| 183 | + context.paintChild( | ||
| 184 | + child!, offset + (child!.parentData as BoxParentData).offset); | ||
| 185 | + context.canvas.drawCircle( | ||
| 186 | + offset + _bulletOffset, _bulletSize, Paint()..color = _bulletColor); | ||
| 187 | + } else { | ||
| 188 | + context.paintChild( | ||
| 189 | + child!, offset + (child!.parentData as BoxParentData).offset); | ||
| 190 | + context.canvas.drawCircle( | ||
| 191 | + offset + _bulletOffset, _bulletSize, Paint()..color = _bulletColor); | ||
| 192 | + } | ||
| 160 | } | 193 | } |
| 161 | } | 194 | } |
| 162 | 195 | ||
| @@ -170,9 +203,11 @@ class OrderedListView extends SingleChildRenderObjectWidget { | @@ -170,9 +203,11 @@ class OrderedListView extends SingleChildRenderObjectWidget { | ||
| 170 | this.padding = 10, | 203 | this.padding = 10, |
| 171 | TextStyle? style, | 204 | TextStyle? style, |
| 172 | required super.child, | 205 | required super.child, |
| 206 | + this.textDirection = TextDirection.ltr, | ||
| 173 | required this.no}) | 207 | required this.no}) |
| 174 | : _style = style; | 208 | : _style = style; |
| 175 | final TextStyle? _style; | 209 | final TextStyle? _style; |
| 210 | + final TextDirection textDirection; | ||
| 176 | 211 | ||
| 177 | TextStyle getStyle(BuildContext context) { | 212 | TextStyle getStyle(BuildContext context) { |
| 178 | if (_style == null || _style!.inherit) { | 213 | if (_style == null || _style!.inherit) { |
| @@ -187,6 +222,7 @@ class OrderedListView extends SingleChildRenderObjectWidget { | @@ -187,6 +222,7 @@ class OrderedListView extends SingleChildRenderObjectWidget { | ||
| 187 | no, | 222 | no, |
| 188 | spacing, | 223 | spacing, |
| 189 | padding, | 224 | padding, |
| 225 | + textDirection, | ||
| 190 | getStyle(context), | 226 | getStyle(context), |
| 191 | ); | 227 | ); |
| 192 | } | 228 | } |
| @@ -198,6 +234,7 @@ class OrderedListView extends SingleChildRenderObjectWidget { | @@ -198,6 +234,7 @@ class OrderedListView extends SingleChildRenderObjectWidget { | ||
| 198 | renderObject.spacing = spacing; | 234 | renderObject.spacing = spacing; |
| 199 | renderObject.padding = padding; | 235 | renderObject.padding = padding; |
| 200 | renderObject.style = getStyle(context); | 236 | renderObject.style = getStyle(context); |
| 237 | + renderObject.textDirection = textDirection; | ||
| 201 | } | 238 | } |
| 202 | } | 239 | } |
| 203 | 240 | ||
| @@ -206,15 +243,18 @@ class OrderedListRenderObject extends RenderProxyBox { | @@ -206,15 +243,18 @@ class OrderedListRenderObject extends RenderProxyBox { | ||
| 206 | String no, | 243 | String no, |
| 207 | double spacing, | 244 | double spacing, |
| 208 | double padding, | 245 | double padding, |
| 246 | + TextDirection textDirection, | ||
| 209 | TextStyle style, { | 247 | TextStyle style, { |
| 210 | RenderBox? child, | 248 | RenderBox? child, |
| 211 | }) : _no = no, | 249 | }) : _no = no, |
| 212 | _style = style, | 250 | _style = style, |
| 213 | _spacing = spacing, | 251 | _spacing = spacing, |
| 214 | _padding = padding, | 252 | _padding = padding, |
| 253 | + _textDirection = textDirection, | ||
| 215 | super(child); | 254 | super(child); |
| 216 | double _spacing; | 255 | double _spacing; |
| 217 | double _padding; | 256 | double _padding; |
| 257 | + TextDirection _textDirection; | ||
| 218 | Offset _ptOffset = Offset.zero; | 258 | Offset _ptOffset = Offset.zero; |
| 219 | set spacing(double value) { | 259 | set spacing(double value) { |
| 220 | if (_spacing == value) { | 260 | if (_spacing == value) { |
| @@ -232,6 +272,15 @@ class OrderedListRenderObject extends RenderProxyBox { | @@ -232,6 +272,15 @@ class OrderedListRenderObject extends RenderProxyBox { | ||
| 232 | markNeedsLayout(); | 272 | markNeedsLayout(); |
| 233 | } | 273 | } |
| 234 | 274 | ||
| 275 | + set textDirection(TextDirection value) { | ||
| 276 | + if (_textDirection == value) { | ||
| 277 | + return; | ||
| 278 | + } | ||
| 279 | + _textDirection = value; | ||
| 280 | + markNeedsLayout(); | ||
| 281 | + markNeedsPaint(); | ||
| 282 | + } | ||
| 283 | + | ||
| 235 | TextStyle _style; | 284 | TextStyle _style; |
| 236 | set style(TextStyle value) { | 285 | set style(TextStyle value) { |
| 237 | _style = value; | 286 | _style = value; |
| @@ -292,11 +341,21 @@ class OrderedListRenderObject extends RenderProxyBox { | @@ -292,11 +341,21 @@ class OrderedListRenderObject extends RenderProxyBox { | ||
| 292 | maxWidth: constraints.maxWidth - pt.width - _spacing - _padding, | 341 | maxWidth: constraints.maxWidth - pt.width - _spacing - _padding, |
| 293 | ), | 342 | ), |
| 294 | parentUsesSize: true); | 343 | parentUsesSize: true); |
| 295 | - child!.parentData = BoxParentData() | ||
| 296 | - ..offset = Offset(_spacing + _padding + pt.width, 0); | ||
| 297 | - var value = child!.computeDistanceToActualBaseline(TextBaseline.alphabetic); | ||
| 298 | - _ptOffset = Offset(_padding, | ||
| 299 | - value! - pt.computeDistanceToActualBaseline(TextBaseline.alphabetic)); | 344 | + if (_textDirection == TextDirection.ltr) { |
| 345 | + child!.parentData = BoxParentData() | ||
| 346 | + ..offset = Offset(_spacing + _padding + pt.width, 0); | ||
| 347 | + var value = | ||
| 348 | + child!.computeDistanceToActualBaseline(TextBaseline.alphabetic); | ||
| 349 | + _ptOffset = Offset(_padding, | ||
| 350 | + value! - pt.computeDistanceToActualBaseline(TextBaseline.alphabetic)); | ||
| 351 | + } else { | ||
| 352 | + child!.parentData = BoxParentData() | ||
| 353 | + ..offset = Offset(-_spacing - _padding + pt.width, 0); | ||
| 354 | + var value = | ||
| 355 | + child!.computeDistanceToActualBaseline(TextBaseline.alphabetic); | ||
| 356 | + _ptOffset = Offset(child!.size.width + _padding - 4, | ||
| 357 | + value! - pt.computeDistanceToActualBaseline(TextBaseline.alphabetic)); | ||
| 358 | + } | ||
| 300 | size = constraints.constrain(Size( | 359 | size = constraints.constrain(Size( |
| 301 | child!.size.width + _spacing + _padding + pt.width, | 360 | child!.size.width + _spacing + _padding + pt.width, |
| 302 | child!.size.height)); | 361 | child!.size.height)); |
| @@ -275,6 +275,7 @@ class CheckBoxMd extends BlockMd { | @@ -275,6 +275,7 @@ class CheckBoxMd extends BlockMd { | ||
| 275 | var match = exp.firstMatch(text.trim()); | 275 | var match = exp.firstMatch(text.trim()); |
| 276 | return CustomCb( | 276 | return CustomCb( |
| 277 | value: ("${match?[1]}" == "x"), | 277 | value: ("${match?[1]}" == "x"), |
| 278 | + textDirection: textDirection, | ||
| 278 | child: MdWidget( | 279 | child: MdWidget( |
| 279 | "${match?[2]}", | 280 | "${match?[2]}", |
| 280 | onLinkTab: onLinkTab, | 281 | onLinkTab: onLinkTab, |
| @@ -309,6 +310,7 @@ class RadioButtonMd extends BlockMd { | @@ -309,6 +310,7 @@ class RadioButtonMd extends BlockMd { | ||
| 309 | var match = exp.firstMatch(text.trim()); | 310 | var match = exp.firstMatch(text.trim()); |
| 310 | return CustomRb( | 311 | return CustomRb( |
| 311 | value: ("${match?[1]}" == "x"), | 312 | value: ("${match?[1]}" == "x"), |
| 313 | + textDirection: textDirection, | ||
| 312 | child: MdWidget( | 314 | child: MdWidget( |
| 313 | "${match?[2]}", | 315 | "${match?[2]}", |
| 314 | onLinkTab: onLinkTab, | 316 | onLinkTab: onLinkTab, |
| @@ -343,6 +345,7 @@ class UnOrderedList extends BlockMd { | @@ -343,6 +345,7 @@ class UnOrderedList extends BlockMd { | ||
| 343 | var match = exp.firstMatch(text.trim()); | 345 | var match = exp.firstMatch(text.trim()); |
| 344 | return UnorderedListView( | 346 | return UnorderedListView( |
| 345 | bulletColor: style?.color, | 347 | bulletColor: style?.color, |
| 348 | + textDirection: textDirection, | ||
| 346 | child: MdWidget( | 349 | child: MdWidget( |
| 347 | "${match?[2]}", | 350 | "${match?[2]}", |
| 348 | onLinkTab: onLinkTab, | 351 | onLinkTab: onLinkTab, |
| @@ -380,6 +383,7 @@ class OrderedList extends BlockMd { | @@ -380,6 +383,7 @@ class OrderedList extends BlockMd { | ||
| 380 | var match = exp.firstMatch(text.trim()); | 383 | var match = exp.firstMatch(text.trim()); |
| 381 | return OrderedListView( | 384 | return OrderedListView( |
| 382 | no: "${match?[1]}", | 385 | no: "${match?[1]}", |
| 386 | + textDirection: textDirection, | ||
| 383 | style: (style ?? const TextStyle()).copyWith(fontWeight: FontWeight.bold), | 387 | style: (style ?? const TextStyle()).copyWith(fontWeight: FontWeight.bold), |
| 384 | child: MdWidget( | 388 | child: MdWidget( |
| 385 | "${match?[2]}", | 389 | "${match?[2]}", |
-
Please register or login to post a comment