pub struct LayoutBox<'a> {
pub dimensions: Dimensions,
pub box_type: BoxType<'a>,
pub children: Vec<LayoutBox<'a>>,
}Fields§
§dimensions: Dimensions§box_type: BoxType<'a>§children: Vec<LayoutBox<'a>>Implementations§
Source§impl<'a> LayoutBox<'a>
impl<'a> LayoutBox<'a>
Sourcefn translate_y(&mut self, dy: i32)
fn translate_y(&mut self, dy: i32)
自身と全子孫の絶対 y 座標を dy だけ平行移動する(table セルの vertical-align 実装用)。
各ボックスの content.y は既に絶対ピクセル座標として確定しているため、
この再帰1回で子孫すべての位置がまとめてずれる。
Sourcefn translate(&mut self, dx: i32, dy: i32)
fn translate(&mut self, dx: i32, dy: i32)
自身と全子孫の絶対座標を (dx, dy) だけ平行移動する。
多段組で「通常フローで積み終えた子を列の位置へ移す」ために使う。
translate_y の 2 軸版で、考え方は同じ(content 座標が絶対値なので
再帰 1 回で子孫がまとめてずれる)。
Sourcefn layout_captions_at(
&mut self,
indices: &[usize],
base_x: i32,
y: i32,
width: i32,
) -> i32
fn layout_captions_at( &mut self, indices: &[usize], base_x: i32, y: i32, width: i32, ) -> i32
indices で指定した caption 群を y から順に縦積みでレイアウトし、消費した合計高さを返す。
caption-side:top(既定)/bottom どちらの配置にも使う共通ヘルパー。
fn layout(&mut self, containing_block: Dimensions)
Sourcefn establish_abs_cb(&self) -> Option<(i32, i32, i32, i32)>
fn establish_abs_cb(&self) -> Option<(i32, i32, i32, i32)>
この要素が positioned(relative/absolute/fixed)なら、子孫 absolute の包含ブロック
(ABS_CB)を self の content box に切替え、切替前の値を返す。戻り値は
restore_abs_cb に渡して復元する。非 positioned なら None。
content.width / content.height が確定済みであることを前提とする(bottom/right 解決のため)。
Sourcefn child_is_out_of_flow(child: &LayoutBox<'_>) -> bool
fn child_is_out_of_flow(child: &LayoutBox<'_>) -> bool
子のうち out-of-flow(absolute / fixed)なものを判定するヘルパ。
Sourcefn apply_positioned_offsets(&mut self)
fn apply_positioned_offsets(&mut self)
position 後処理。全フォーマッティングコンテキスト(block/flex/grid/table)で共有。
- relative: フロー確定位置から top/left(または bottom/right の符号反転)でオフセット。
- absolute: 最近傍 positioned 祖先(ABS_CB、昇り解決済み)基準で top/left/right/bottom 配置。
- fixed: ビューポート原点基準で配置。
- transform: translate を最後に視覚シフトとして適用(兄弟は再フローしない=仕様通り)。
self.dimensions.content.{width,height} が確定済みであることを前提とする。
Sourcefn layout_grid(&mut self, containing_block: Dimensions)
fn layout_grid(&mut self, containing_block: Dimensions)
テーブルレイアウト (RFC 風の簡易固定/自動テーブル)。
- 列数 = 最大セル数の行
- 列幅 = 各列セルの intrinsic 幅の最大値。総和が利用幅を超えたら比例縮小、 下回ったら余りを均等配分して幅いっぱいに広げる
- 各行は縦に積み、行内のセルは列幅で横並び、行高さ = セル最大高さに揃える
fn layout_table(&mut self, containing_block: Dimensions)
fn layout_flex(&mut self, containing_block: Dimensions)
Sourcefn layout_flex_wrapped(
&mut self,
is_row: bool,
is_reverse: bool,
wrap_reverse: bool,
justify_content: &str,
align_items: &str,
align_content: &str,
gap_main: i32,
gap_cross: i32,
height_val: Option<String>,
)
fn layout_flex_wrapped( &mut self, is_row: bool, is_reverse: bool, wrap_reverse: bool, justify_content: &str, align_items: &str, align_content: &str, gap_main: i32, gap_cross: i32, height_val: Option<String>, )
flex-wrap: wrap / wrap-reverse のレイアウト。 子を主軸に沿って並べ、コンテナ主軸長を超えたら次の行へ折り返す。 各行ごとに justify-content(主軸)と align-items / align-self(交差軸)を適用する。
fn layout_block(&mut self, containing_block: Dimensions)
Sourcefn intrinsic_inline_size_ext(&self, avail_hint: i32, pure: bool) -> (i32, i32)
fn intrinsic_inline_size_ext(&self, avail_hint: i32, pure: bool) -> (i32, i32)
avail_hint: 包含ブロックのコンテンツ幅。テキスト折り返し計測に使う。
(以前は固定 800px フォールバックだったため、実コンテナ幅と食い違い
layout の行数 < flatten の行数 となって後続要素と重なるバグがあった)
内容ベースの寸法を返す。avail_hint は折り返しに使える幅。
pure が真なら現在の箱の幅を見ない。内在幅
(min-content / max-content)の算出専用の入口で、
block_intrinsic_widths だけが真を渡す。
内在幅は「今どう組まれているか」に依存してはいけない値だが、 この関数は内在幅以外の用途(表の列幅・インライン配置など)でも 呼ばれており、そちらは現在の幅を前提にしている。 【2026-09-05】一度この区別をせずに順序だけ入れ替えたところ、 ヒーローの見出しが 2 行に折り返す退行を招いて戻した。 入口を分けることで、内在幅の算出だけを正す。
Sourcefn intrinsic_inline_size(&self, avail_hint: i32) -> (i32, i32)
fn intrinsic_inline_size(&self, avail_hint: i32) -> (i32, i32)
従来どおりの入口(現在の箱の幅を見る)。
fn layout_inline(&mut self, containing_block: Dimensions, _block_like: bool)
Sourcefn finalize_inline_line_vertical_align(
&mut self,
start: usize,
end: usize,
line_h: i32,
max_w: i32,
)
fn finalize_inline_line_vertical_align( &mut self, start: usize, end: usize, line_h: i32, max_w: i32, )
インラインの1行ぶん([start, end) の子要素)に vertical-align を適用する。
簡略化: top/baseline/sub/super/text-top はいずれも無調整(top相当)、
middle は行の中央、bottom/text-bottom は行の下端に揃える。table セルの
vertical-align(内容のみシフト)とは異なり、ここでは子要素自身(背景/境界線含む)を
まるごとシフトする(インラインボックス自体の行内配置を変えるのが目的のため)。
Sourcefn resolve_sizing_value(&self, value: Option<String>, base: i32) -> Option<i32>
fn resolve_sizing_value(&self, value: Option<String>, base: i32) -> Option<i32>
min-width/max-width 等のサイジング値を解決する。px/% は base 基準、
min-content/max-content/fit-content は内容計測で解決。auto/未指定は None。
Sourcefn block_intrinsic_widths(&self) -> (i32, i32)
fn block_intrinsic_widths(&self) -> (i32, i32)
ブロック要素の内容ベース幅を返す: (min_content, max_content)。 max_content = 折返しなしの最大行幅、min_content = 最大限折返したときの最小幅。 直下の子(inline/text/block)を計測して集約する。