Repository navigation
Conversation
…g order, and LayoutDirection A small rect-based layout over SceneLayout's rects. Items state their size; placing sets resting positions once. Leading and trailing mirror in a right-to-left language; direction(_:) keeps a physical subtree as drawn. LayoutDirection.current follows Typography.follow's language, with forced for a debug override. SceneLayout's corner and edge helpers take a HorizontalEdge.
|
|
||
| private func place(in rect: CGRect, direction inherited: LayoutDirection, hDefault: HAlign, vDefault: VAlign) { | ||
| let direction = fixedDirection ?? inherited | ||
| let frame = frame(in: rect, direction: direction, h: hAlign ?? hDefault, v: vAlign ?? vDefault) |
There was a problem hiding this comment.
direction(_:) changes where the item stands in its parent's rect, not just how its contents are laid out: this frame is worked out with fixedDirection in place of the inherited direction (and frame(in:) at line 218 does the same). So .leading/.trailing on a fixed-direction item, or the .leading it gets from a column, picks the physical side. Example in Arabic: .column([title, track.direction(.leftToRight)], align: .leading) puts the title on the right but the track on the left, and board.direction(.leftToRight).aligned(.leading, .top) in an overlay goes to the top left. UIKit's semanticContentAttribute only affects the view's subviews; the view's own place follows its superview. The AGENTS.md rule ("keeps its own with direction(_:)") reads the same way. Work out this frame with inherited, and apply fixedDirection only to the children, i.e. to the direction passed down and used for rightToLeft/insets.
There was a problem hiding this comment.
Fixed in the latest push. The frame is now worked out with the inherited direction (in place and in frame(in:)), and fixedDirection applies only to the contents: the direction passed down, rows, grids and insets. A new test, aFixedDirectionItemStandsByItsParents, covers both examples: in right-to-left, a left-to-right track in a leading column stands on the right with its contents in left-to-right order, and a fixed-direction board aligned leading in an overlay goes to the top right. AGENTS.md and the README now say the same.
|
Claude review (house rules) |
|
Claude review (house rules): correction to the comment above. This repository does have a CONTRIBUTING.md. I've now read it, and it doesn't change the review: still 1 inline comment. |
…ts it; only its contents keep its own
| item.size = CGSize(width: width ?? size.width, height: height ?? size.height) | ||
| return item | ||
| } | ||
|
|
||
| /// What this item holds laid out in `direction` whatever the language: | ||
| /// for what shows a physical direction (a board, a track). Where the | ||
| /// item itself stands in its parent still follows the parent's. | ||
| public func direction(_ direction: LayoutDirection) -> LayoutItem { |
There was a problem hiding this comment.
The anchor is read from label.horizontalAlignmentMode once, when the item is built. Anything that changes the mode later leaves the label positioned for the old mode. The third row of the PR's own Before / after table does exactly that: it sets text.horizontalAlignmentMode = LayoutDirection.current.labelAlignment(.leading) after .label(text, …) and .place(in:). The label is built .center, so it gets anchor 0.5 and its position lands on the middle of its slot. Switching to .left then starts the text there, half its width toward the trailing side of where the row put it. In right-to-left, .right ends the text at that middle point instead. Reading the mode inside the place closure would help when it's set between building and placing. The documented pattern also needs to set the alignment before building the item.
|
Claude review (house rules) |
A small rect-based layout engine in
PlatformSprite, with reading direction built in from the start, so screens stop being position arithmetic and mirror for right-to-left languages (Arabic, Hebrew, Persian, Urdu).What it adds
LayoutItem: rows and columns with gaps, grids, overlays and insets, laid out in the rectsSceneLayoutgives.place(in:)sets each leaf's resting position once, on load and when the layout changes, never per frame. It leaves running actions alone.node(_:size:anchor:),label(_:height:),space, andleaf(_:place:)for anything else.aligned,inset,sizedanddirection..fillalignment takes the whole rect, for a panel's face behind its content.leading/trailingalignment and insets mirror in a right-to-left language.direction(_:)keeps what a subtree that shows a physical direction (a board, a track) holds as drawn. The subtree itself still stands where its parent's direction puts it, as UIKit'ssemanticContentAttributeaffects only a view's subviews.LayoutDirection:currentfollows the game's language.Typography.followsets it, so games that already call it get it with no change.forcedlets a game mirror the interface from a debug launch argument.side(_:)andx(_:of:)turn an edge into a side or an x,labelAlignment(_:)aligns a label, andmirrorScaleflips directional art such as a back chevron.LocalizationLanguage.layoutDirectiongives a language's direction from its code.SceneLayout:cornerButtonCenter,edgeButtonXandedgeXalso take aHorizontalEdge, so a back button stands in the leading top corner.LayoutItem, name places leading/trailing) and a README toolkit entry.Before / after
Verification
LayoutItemTestsandLayoutDirectionTestscover:sized, each in both directions;SceneLayouthelpers against the side-based ones.Checks:
swift testswift test --package-path PlatformScripts/check-android.sh arm64-v8aPlatform/'s tests on Mac Catalyst, and builds for iOS and tvOSNo game moves onto it in this PR, so nothing on screen changes. The first adopters follow as game PRs that move their submodule.