mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Make grid RTL aware
This commit is contained in:
parent
8951b1923a
commit
01a62a690b
@ -131,7 +131,7 @@ impl Layout for ColumnsNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let width = frame.width();
|
let width = frame.width();
|
||||||
let x = if dir.is_positive() {
|
let x = if dir == Dir::LTR {
|
||||||
cursor
|
cursor
|
||||||
} else {
|
} else {
|
||||||
regions.first.x - cursor - width
|
regions.first.x - cursor - width
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::text::TextNode;
|
||||||
|
|
||||||
use super::Spacing;
|
use super::Spacing;
|
||||||
|
|
||||||
@ -218,6 +219,8 @@ struct GridLayouter<'a, 'v> {
|
|||||||
vt: &'a mut Vt<'v>,
|
vt: &'a mut Vt<'v>,
|
||||||
/// The grid cells.
|
/// The grid cells.
|
||||||
cells: &'a [Content],
|
cells: &'a [Content],
|
||||||
|
/// Whether this is an RTL grid.
|
||||||
|
rtl: bool,
|
||||||
/// The column tracks including gutter tracks.
|
/// The column tracks including gutter tracks.
|
||||||
cols: Vec<TrackSizing>,
|
cols: Vec<TrackSizing>,
|
||||||
/// The row tracks including gutter tracks.
|
/// The row tracks including gutter tracks.
|
||||||
@ -299,6 +302,12 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
cols.pop();
|
cols.pop();
|
||||||
rows.pop();
|
rows.pop();
|
||||||
|
|
||||||
|
// Reverse for RTL.
|
||||||
|
let rtl = styles.get(TextNode::DIR) == Dir::RTL;
|
||||||
|
if rtl {
|
||||||
|
cols.reverse();
|
||||||
|
}
|
||||||
|
|
||||||
let full = regions.first.y;
|
let full = regions.first.y;
|
||||||
let rcols = vec![Abs::zero(); cols.len()];
|
let rcols = vec![Abs::zero(); cols.len()];
|
||||||
let lrows = vec![];
|
let lrows = vec![];
|
||||||
@ -311,6 +320,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
Self {
|
Self {
|
||||||
vt,
|
vt,
|
||||||
cells,
|
cells,
|
||||||
|
rtl,
|
||||||
cols,
|
cols,
|
||||||
rows,
|
rows,
|
||||||
regions,
|
regions,
|
||||||
@ -680,10 +690,15 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
///
|
///
|
||||||
/// Returns `None` if it's a gutter cell.
|
/// Returns `None` if it's a gutter cell.
|
||||||
#[track_caller]
|
#[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!(x < self.cols.len());
|
||||||
assert!(y < self.rows.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.
|
// Even columns and rows are children, odd ones are gutter.
|
||||||
if x % 2 == 0 && y % 2 == 0 {
|
if x % 2 == 0 && y % 2 == 0 {
|
||||||
let c = 1 + self.cols.len() / 2;
|
let c = 1 + self.cols.len() / 2;
|
||||||
|
BIN
tests/ref/layout/grid-rtl.png
Normal file
BIN
tests/ref/layout/grid-rtl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
9
tests/typ/layout/grid-rtl.typ
Normal file
9
tests/typ/layout/grid-rtl.typ
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Test RTL grid.
|
||||||
|
|
||||||
|
---
|
||||||
|
#set text(dir: rtl)
|
||||||
|
- מימין לשמאל
|
||||||
|
|
||||||
|
---
|
||||||
|
#set text(dir: rtl)
|
||||||
|
#table(columns: 2, gutter: 5pt)[A][B][C][D]
|
Loading…
x
Reference in New Issue
Block a user