summaryrefslogtreecommitdiff
path: root/library/src/layout/grid.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-12 12:57:40 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-12 12:57:40 +0100
commit01a62a690b0f46b13a3190d8e1a20c00fb8b14fd (patch)
tree38ed17261ffba36e03c82cb0585b422bfe1a867f /library/src/layout/grid.rs
parent8951b1923a581f7454ddf4dbe3e55f69ce5799f9 (diff)
Make grid RTL aware
Diffstat (limited to 'library/src/layout/grid.rs')
-rw-r--r--library/src/layout/grid.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs
index 544b76ed..818bf53d 100644
--- a/library/src/layout/grid.rs
+++ b/library/src/layout/grid.rs
@@ -1,4 +1,5 @@
use crate::prelude::*;
+use crate::text::TextNode;
use super::Spacing;
@@ -218,6 +219,8 @@ struct GridLayouter<'a, 'v> {
vt: &'a mut Vt<'v>,
/// The grid cells.
cells: &'a [Content],
+ /// Whether this is an RTL grid.
+ rtl: bool,
/// The column tracks including gutter tracks.
cols: Vec<TrackSizing>,
/// The row tracks including gutter tracks.
@@ -299,6 +302,12 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
cols.pop();
rows.pop();
+ // Reverse for RTL.
+ let rtl = styles.get(TextNode::DIR) == Dir::RTL;
+ if rtl {
+ cols.reverse();
+ }
+
let full = regions.first.y;
let rcols = vec![Abs::zero(); cols.len()];
let lrows = vec![];
@@ -311,6 +320,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
Self {
vt,
cells,
+ rtl,
cols,
rows,
regions,
@@ -680,10 +690,15 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
///
/// Returns `None` if it's a gutter cell.
#[track_caller]
- fn cell(&self, x: usize, y: usize) -> Option<&'a Content> {
+ fn cell(&self, mut x: usize, y: usize) -> Option<&'a Content> {
assert!(x < self.cols.len());
assert!(y < self.rows.len());
+ // Columns are reorded, but the cell slice is not.
+ if self.rtl {
+ x = self.cols.len() - 1 - x;
+ }
+
// Even columns and rows are children, odd ones are gutter.
if x % 2 == 0 && y % 2 == 0 {
let c = 1 + self.cols.len() / 2;