布局引擎 API¶
布局模块包含 CSS Grid 求解器,负责轨道尺寸计算、子项放置和对齐。
模块概览¶
| 类 | 职责 |
|---|---|
GridSolver |
Grid 布局求解器主类 |
TrackDef |
轨道定义(fixed/fr/auto/minmax/etc.) |
Track |
求解后的轨道(含实际尺寸) |
GridItem |
包装子节点的 Grid 项 |
SizeType |
尺寸类型枚举 |
GridSolver¶
from latticesvg.layout.grid_solver import GridSolver
from latticesvg import GridContainer, LayoutConstraints
grid = GridContainer(style={"grid-template-columns": "1fr 2fr", "width": 600})
solver = GridSolver(grid)
solver.solve(LayoutConstraints(available_width=600))
自动生成的 API 文档¶
grid_solver ¶
CSS Grid Level 1 layout solver.
Implements track sizing, item placement, coordinate computation, and alignment — the heart of the LatticeSVG layout engine.
TrackDef
dataclass
¶
TrackDef(size_type: SizeType, value: float = 0.0, min_track: Optional['TrackDef'] = None, max_track: Optional['TrackDef'] = None)
Parsed definition for one grid track (column or row).
Track
dataclass
¶
Track(definition: TrackDef, base_size: float = 0.0, growth_limit: float = float('inf'), final_size: float = 0.0)
Runtime state for a single track during sizing.
GridItem
dataclass
¶
A child node with its resolved grid placement.
GridSolver ¶
Performs CSS Grid layout on a :class:GridContainer.
Source code in src/latticesvg/layout/grid_solver.py
solve ¶
Run the complete grid layout algorithm.
Source code in src/latticesvg/layout/grid_solver.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
measure ¶
Measure the grid container's intrinsic sizes.