---
title: "Layout Group 은 칸을 먼저 나누고 그 안에 자식을 놓는다"
description: "Figma Auto Layout 과 닮았지만 규칙이 다릅니다. Control Child Size 와 Child Force Expand 가 버튼 모양을 어떻게 네 가지로 바꾸는지, 글에 맞춰 커지는 말풍선이 어떻게 만들어지는지 그림으로 봅니다."
author: "유니얼"
pubDate: 2026-09-10
category: "game-dev/unity/ui"
tags: ["Unity", "UI", "uGUI"]
canonical: https://blog.unialgames.com/posts/unity-ui-layout-group/
---
Figma 에서 버튼 셋을 Auto Layout 으로 가로로 묶었습니다. 간격은 12, 버튼은 글자에 맞춰 줄어듭니다.

Unity 에서 같은 버튼 셋에 **Horizontal Layout Group** 을 붙이면 모양이 다르게 나옵니다.
버튼 사이가 제멋대로 벌어지기도 하고, 버튼이 부모를 꽉 채우도록 늘어나기도 합니다.

**체크박스 두 개 때문입니다.** 이름만 봐서는 무엇을 하는지 짐작하기 어려운 두 칸이 버튼 줄을 네 가지 모양으로 바꿉니다.

## 그룹을 붙이면 자식의 자리는 그룹이 정한다

Layout Group 은 셋입니다. **Horizontal** 은 가로 한 줄, **Vertical** 은 세로 한 줄, **Grid** 는 격자입니다.
가로와 세로는 방향만 다르고 설정이 같아서, 이 글은 Horizontal 로 봅니다.

그룹을 붙이는 순간 자식의 RectTransform 일부가 회색으로 잠깁니다.

<figure class="diagram">
<svg viewBox="0 0 680 150" role="img" aria-label="Horizontal Layout Group 아래에 넣은 버튼의 RectTransform 은 Pos X, Pos Y, Width, Height 칸이 회색으로 잠기고 Some values driven by HorizontalLayoutGroup 문구가 뜬다는 그림">
<rect x="20" y="14" width="400" height="124" rx="4" stroke="var(--border)" fill="var(--bg)"></rect>
<line x1="20" y1="42" x2="420" y2="42" stroke="var(--border)"></line>
<polygon points="34,24 44,24 39,32" fill="var(--text-muted)"></polygon>
<text x="52" y="33" font-size="13" fill="var(--text)">Rect Transform</text>
<rect x="34" y="52" width="372" height="24" rx="3" fill="var(--bg-subtle)"></rect>
<text x="44" y="68" font-size="12" fill="var(--text-muted)">Some values driven by HorizontalLayoutGroup.</text>
<text x="120" y="96" font-size="11" fill="var(--text-muted)">Pos X</text>
<rect x="120" y="102" width="62" height="22" rx="3" stroke="var(--border)" fill="var(--bg-subtle)"></rect>
<text x="128" y="117" font-size="12" font-family="var(--font-mono)" fill="var(--text-muted)" fill-opacity="0.6">24</text>
<text x="192" y="96" font-size="11" fill="var(--text-muted)">Pos Y</text>
<rect x="192" y="102" width="62" height="22" rx="3" stroke="var(--border)" fill="var(--bg-subtle)"></rect>
<text x="200" y="117" font-size="12" font-family="var(--font-mono)" fill="var(--text-muted)" fill-opacity="0.6">-40</text>
<text x="264" y="96" font-size="11" fill="var(--text-muted)">Width</text>
<rect x="264" y="102" width="62" height="22" rx="3" stroke="var(--border)" fill="var(--bg-subtle)"></rect>
<text x="272" y="117" font-size="12" font-family="var(--font-mono)" fill="var(--text-muted)" fill-opacity="0.6">72</text>
<text x="336" y="96" font-size="11" fill="var(--text-muted)">Height</text>
<rect x="336" y="102" width="62" height="22" rx="3" stroke="var(--border)" fill="var(--bg-subtle)"></rect>
<text x="344" y="117" font-size="12" font-family="var(--font-mono)" fill="var(--text-muted)" fill-opacity="0.6">44</text>
<text x="34" y="117" font-size="12" fill="var(--text-muted)">잠긴 칸</text>
<g stroke="var(--border)"><line x1="424" y1="64" x2="450" y2="64"></line><line x1="424" y1="113" x2="450" y2="113"></line></g>
<text x="460" y="60" font-size="12" fill="var(--text)">그룹이 정하고 있다는 표시</text>
<text x="460" y="78" font-size="12" fill="var(--text-muted)">여기 숫자를 고쳐도 되돌아갑니다</text>
<text x="460" y="110" font-size="12" fill="var(--text)">회색 칸은 직접 못 고칩니다</text>
<text x="460" y="128" font-size="12" fill="var(--text-muted)">그룹 설정이나 순서로 옮깁니다</text>
</svg>
<figcaption>앵커와 위치를 자식에서 직접 고칠 수 없게 됩니다. 순서는 하이어라키 순서를 따릅니다.</figcaption>
</figure>

그룹의 설정은 이렇게 생겼습니다.

<figure class="diagram">
<svg viewBox="0 0 680 330" role="img" aria-label="Horizontal Layout Group 인스펙터를 옮겨 그린 그림. Padding, Spacing, Child Alignment, Reverse Arrangement, Control Child Size, Use Child Scale, Child Force Expand 칸이 있다">
<rect x="20" y="14" width="400" height="302" rx="4" stroke="var(--border)" fill="var(--bg)"></rect>
<line x1="20" y1="42" x2="420" y2="42" stroke="var(--border)"></line>
<polygon points="34,24 44,24 39,32" fill="var(--text-muted)"></polygon>
<text x="52" y="33" font-size="13" fill="var(--text)">Horizontal Layout Group</text>
<text x="36" y="70" font-size="12" fill="var(--text-muted)">Padding</text>
<text x="190" y="70" font-size="11" fill="var(--text-muted)">L</text><rect x="202" y="55" width="38" height="22" rx="3" stroke="var(--border)" fill="var(--bg)"></rect><text x="210" y="70" font-size="12" font-family="var(--font-mono)" fill="var(--text)">12</text>
<text x="246" y="70" font-size="11" fill="var(--text-muted)">R</text><rect x="258" y="55" width="38" height="22" rx="3" stroke="var(--border)" fill="var(--bg)"></rect><text x="266" y="70" font-size="12" font-family="var(--font-mono)" fill="var(--text)">12</text>
<text x="302" y="70" font-size="11" fill="var(--text-muted)">T</text><rect x="314" y="55" width="38" height="22" rx="3" stroke="var(--border)" fill="var(--bg)"></rect><text x="322" y="70" font-size="12" font-family="var(--font-mono)" fill="var(--text)">12</text>
<text x="358" y="70" font-size="11" fill="var(--text-muted)">B</text><rect x="370" y="55" width="38" height="22" rx="3" stroke="var(--border)" fill="var(--bg)"></rect><text x="378" y="70" font-size="12" font-family="var(--font-mono)" fill="var(--text)">12</text>
<text x="36" y="110" font-size="12" fill="var(--text-muted)">Spacing</text><rect x="202" y="95" width="204" height="22" rx="3" stroke="var(--border)" fill="var(--bg)"></rect><text x="210" y="110" font-size="12" font-family="var(--font-mono)" fill="var(--text)">12</text>
<text x="36" y="150" font-size="12" fill="var(--text-muted)">Child Alignment</text><rect x="202" y="135" width="204" height="22" rx="3" stroke="var(--border)" fill="var(--bg)"></rect><text x="210" y="150" font-size="12" font-family="var(--font-mono)" fill="var(--text)">Middle Left</text><polygon points="390,144 398,144 394,149" fill="var(--text-muted)"></polygon>
<text x="36" y="190" font-size="12" fill="var(--text-muted)">Reverse Arrangement</text><rect x="202" y="178" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--bg)"></rect>
<text x="36" y="230" font-size="12" fill="var(--text-muted)">Control Child Size</text>
<rect x="202" y="218" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--bg)"></rect><text x="224" y="230" font-size="12" fill="var(--text-muted)">Width</text>
<rect x="290" y="218" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--bg)"></rect><text x="312" y="230" font-size="12" fill="var(--text-muted)">Height</text>
<text x="36" y="270" font-size="12" fill="var(--text-muted)">Use Child Scale</text>
<rect x="202" y="258" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--bg)"></rect><text x="224" y="270" font-size="12" fill="var(--text-muted)">Width</text>
<rect x="290" y="258" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--bg)"></rect><text x="312" y="270" font-size="12" fill="var(--text-muted)">Height</text>
<text x="36" y="300" font-size="12" fill="var(--text-muted)">Child Force Expand</text>
<rect x="202" y="288" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--accent)"></rect><polyline points="206,296 209,300 214,292" fill="none" stroke="var(--on-accent)" stroke-width="2"></polyline><text x="224" y="300" font-size="12" fill="var(--text-muted)">Width</text>
<rect x="290" y="288" width="16" height="16" rx="3" stroke="var(--text-muted)" fill="var(--accent)"></rect><polyline points="294,296 297,300 302,292" fill="none" stroke="var(--on-accent)" stroke-width="2"></polyline><text x="312" y="300" font-size="12" fill="var(--text-muted)">Height</text>
<line x1="410" y1="66" x2="440" y2="66" stroke="var(--border)"></line>
<circle cx="452" cy="66" r="9" stroke="var(--accent)" fill="var(--bg)"></circle>
<text x="452" y="70" font-size="11" text-anchor="middle" fill="var(--accent)">1</text>
<text x="468" y="70" font-size="12" fill="var(--text-muted)">안쪽 여백. Figma 의 Padding</text>
<line x1="410" y1="106" x2="440" y2="106" stroke="var(--border)"></line>
<circle cx="452" cy="106" r="9" stroke="var(--accent)" fill="var(--bg)"></circle>
<text x="452" y="110" font-size="11" text-anchor="middle" fill="var(--accent)">2</text>
<text x="468" y="110" font-size="12" fill="var(--text-muted)">자식 사이 간격. Figma 의 Gap</text>
<line x1="410" y1="146" x2="440" y2="146" stroke="var(--border)"></line>
<circle cx="452" cy="146" r="9" stroke="var(--accent)" fill="var(--bg)"></circle>
<text x="452" y="150" font-size="11" text-anchor="middle" fill="var(--accent)">3</text>
<text x="468" y="150" font-size="12" fill="var(--text-muted)">남는 공간이 있을 때 붙을 쪽</text>
<line x1="410" y1="186" x2="440" y2="186" stroke="var(--border)"></line>
<circle cx="452" cy="186" r="9" stroke="var(--accent)" fill="var(--bg)"></circle>
<text x="452" y="190" font-size="11" text-anchor="middle" fill="var(--accent)">4</text>
<text x="468" y="190" font-size="12" fill="var(--text-muted)">순서를 거꾸로</text>
<line x1="410" y1="226" x2="440" y2="226" stroke="var(--border)"></line>
<circle cx="452" cy="226" r="9" stroke="var(--accent)" fill="var(--accent)"></circle>
<text x="452" y="230" font-size="11" text-anchor="middle" fill="var(--on-accent)">5</text>
<text x="468" y="230" font-size="12" fill="var(--text)">그룹이 자식 크기까지 정할지</text>
<line x1="410" y1="266" x2="440" y2="266" stroke="var(--border)"></line>
<circle cx="452" cy="266" r="9" stroke="var(--accent)" fill="var(--bg)"></circle>
<text x="452" y="270" font-size="11" text-anchor="middle" fill="var(--accent)">6</text>
<text x="468" y="270" font-size="12" fill="var(--text-muted)">자식의 Scale 을 크기로 칠지</text>
<line x1="410" y1="296" x2="440" y2="296" stroke="var(--border)"></line>
<circle cx="452" cy="296" r="9" stroke="var(--accent)" fill="var(--accent)"></circle>
<text x="452" y="300" font-size="11" text-anchor="middle" fill="var(--on-accent)">7</text>
<text x="468" y="300" font-size="12" fill="var(--text)">남는 공간을 자식에게 나눠 줄지</text>
</svg>
<figcaption>Horizontal Layout Group 인스펙터를 옮겨 그렸습니다. 이 글의 주인공은 5 번과 7 번입니다.</figcaption>
</figure>

1 부터 3 까지는 Figma 에서 쓰던 그대로입니다. 문제는 5 와 7 입니다.
두 칸을 이해하려면 먼저 **자식이 그룹에게 무엇을 알려 주는지** 알아야 합니다.

## 자식은 크기 셋을 알려 준다

그룹은 자식에게 "얼마나 커야 하니" 를 세 가지로 묻습니다.

| 값 | 뜻 | 따로 안 정하면 |
| --- | --- | --- |
| **Min** | 이보다 작아지지 않는 크기 | 대부분 0 |
| **Preferred** | 공간이 되면 갖고 싶은 크기 | 텍스트는 글자 폭, Simple 이미지는 원본 크기 |
| **Flexible** | 그러고도 남는 공간을 나눠 받는 비율 | 0 (안 받음) |

값을 직접 정하고 싶으면 자식에 **Layout Element** 를 붙입니다. 칸 앞의 체크박스를 켠 값만 쓰이고, 켠 값이 텍스트나 이미지가 알려 주는 값을 이깁니다.

그룹은 이 셋을 **순서대로** 나눠 줍니다.

<figure class="diagram">
<svg viewBox="0 0 680 250" role="img" aria-label="자식 A 와 B 가 Min 40, Preferred 100 이고 B 만 Flexible 1 일 때, 부모가 150 이면 둘 다 75 로 줄고, 200 이면 둘 다 100, 440 이면 A 는 100 에 멈추고 B 가 남는 240 을 전부 받아 340 이 된다는 그림">
<text x="170" y="22" font-size="12" fill="var(--text-muted)">A: Min 40 · Preferred 100 · Flexible 0</text>
<text x="450" y="22" font-size="12" fill="var(--text-muted)">B: 같고 Flexible 만 1</text>
<text x="20" y="66" font-size="13" fill="var(--text)">공간이 모자랄 때</text>
<text x="20" y="84" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 150</text>
<rect x="170" y="46" width="150" height="48" rx="3" stroke="var(--text)" fill="none"></rect>
<rect x="170" y="52" width="40" height="36" fill="var(--accent)" fill-opacity="0.75"></rect>
<rect x="210" y="52" width="35" height="36" fill="var(--accent)" fill-opacity="0.3"></rect>
<rect x="170" y="52" width="75" height="36" fill="none" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="207.5" y="75" font-size="12" text-anchor="middle" fill="var(--text)">A 75</text>
<rect x="245" y="52" width="40" height="36" fill="var(--accent)" fill-opacity="0.75"></rect>
<rect x="285" y="52" width="35" height="36" fill="var(--accent)" fill-opacity="0.3"></rect>
<rect x="245" y="52" width="75" height="36" fill="none" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="282.5" y="75" font-size="12" text-anchor="middle" fill="var(--text)">B 75</text>
<text x="20" y="126" font-size="13" fill="var(--text)">딱 Preferred 만큼</text>
<text x="20" y="144" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 200</text>
<rect x="170" y="106" width="200" height="48" rx="3" stroke="var(--text)" fill="none"></rect>
<rect x="170" y="112" width="40" height="36" fill="var(--accent)" fill-opacity="0.75"></rect>
<rect x="210" y="112" width="60" height="36" fill="var(--accent)" fill-opacity="0.3"></rect>
<rect x="170" y="112" width="100" height="36" fill="none" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="220" y="135" font-size="12" text-anchor="middle" fill="var(--text)">A 100</text>
<rect x="270" y="112" width="40" height="36" fill="var(--accent)" fill-opacity="0.75"></rect>
<rect x="310" y="112" width="60" height="36" fill="var(--accent)" fill-opacity="0.3"></rect>
<rect x="270" y="112" width="100" height="36" fill="none" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="320" y="135" font-size="12" text-anchor="middle" fill="var(--text)">B 100</text>
<text x="20" y="186" font-size="13" fill="var(--text)">공간이 남을 때</text>
<text x="20" y="204" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 440</text>
<rect x="170" y="166" width="440" height="48" rx="3" stroke="var(--text)" fill="none"></rect>
<rect x="170" y="172" width="40" height="36" fill="var(--accent)" fill-opacity="0.75"></rect>
<rect x="210" y="172" width="60" height="36" fill="var(--accent)" fill-opacity="0.3"></rect>
<rect x="170" y="172" width="100" height="36" fill="none" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="220" y="195" font-size="12" text-anchor="middle" fill="var(--text)">A 100</text>
<rect x="270" y="172" width="40" height="36" fill="var(--accent)" fill-opacity="0.75"></rect>
<rect x="310" y="172" width="60" height="36" fill="var(--accent)" fill-opacity="0.3"></rect>
<rect x="370" y="172" width="240" height="36" fill="var(--accent2)" fill-opacity="0.45"></rect>
<rect x="270" y="172" width="340" height="36" fill="none" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="440" y="195" font-size="12" text-anchor="middle" fill="var(--text)">B 340</text>
<rect x="170" y="228" width="20" height="12" fill="var(--accent)" fill-opacity="0.75"></rect><text x="196" y="238" font-size="12" fill="var(--text-muted)">1. Min 먼저</text>
<rect x="300" y="228" width="20" height="12" fill="var(--accent)" fill-opacity="0.3"></rect><text x="326" y="238" font-size="12" fill="var(--text-muted)">2. 되면 Preferred 까지</text>
<rect x="470" y="228" width="20" height="12" fill="var(--accent2)" fill-opacity="0.45"></rect><text x="496" y="238" font-size="12" fill="var(--text-muted)">3. 남으면 Flexible 비율로</text>
</svg>
<figcaption>Min 을 먼저 주고, 공간이 되면 Preferred 까지 벌리고, 그래도 남으면 Flexible 이 있는 자식만 더 받습니다.</figcaption>
</figure>

- **공간이 모자라면** Min 과 Preferred 사이에서 같은 비율로 줄입니다. Min 보다는 작아지지 않습니다
- **Preferred 합만큼 되면** 모두 Preferred 입니다
- **남으면** Flexible 비율대로 나눕니다. Flexible 이 0 인 A 는 100 에서 멈추고 B 가 남는 공간을 전부 가져갑니다

Unity 6.6 부터는 Layout Element 에 **Max Width, Max Height** 도 생겼습니다. 그보다 앞선 버전에는 최대 크기를 정하는 칸이 없습니다.

## 두 체크박스가 만드는 네 가지 모양

이제 5 번 **Control Child Size** 와 7 번 **Child Force Expand** 를 봅니다.

<figure class="diagram">
<svg viewBox="0 0 680 290" role="img" aria-label="Control Child Size 와 Child Force Expand 를 켜고 끈 네 조합. 둘 다 끄면 버튼이 붙어서 왼쪽에 모이고, Force Expand 만 켜면 칸만 넓어져 버튼 사이가 벌어지고, Control 만 켜면 버튼이 글자에 맞춰 줄고, 둘 다 켜면 부모를 꽉 채운다">
<text x="280" y="24" font-size="13" text-anchor="middle" fill="var(--text)">Child Force Expand 끔</text>
<text x="540" y="24" font-size="13" text-anchor="middle" fill="var(--text)">Child Force Expand 켬</text>
<text x="20" y="74" font-size="13" fill="var(--text)">Control Child Size</text>
<text x="20" y="92" font-size="13" fill="var(--text)">끔</text>
<rect x="160" y="48" width="240" height="64" rx="4" stroke="var(--text)" fill="var(--bg)"></rect>
<rect x="168" y="54" width="56" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="168" y="64" width="56" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="196" y="84" font-size="11" text-anchor="middle" fill="var(--text)">확인</text>
<rect x="232" y="54" width="56" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="232" y="64" width="56" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="260" y="84" font-size="11" text-anchor="middle" fill="var(--text)">취소</text>
<rect x="296" y="54" width="56" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="296" y="64" width="56" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="324" y="84" font-size="11" text-anchor="middle" fill="var(--text)">다시 보기</text>
<text x="280.0" y="132" font-size="12" text-anchor="middle" fill="var(--text-muted)">붙어서 왼쪽에 모인다</text>
<rect x="420" y="48" width="240" height="64" rx="4" stroke="var(--text)" fill="var(--bg)"></rect>
<rect x="428" y="54" width="69.3333" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="428" y="64" width="56" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="456" y="84" font-size="11" text-anchor="middle" fill="var(--text)">확인</text>
<rect x="505.333" y="54" width="69.3333" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="505.333" y="64" width="56" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="533.333" y="84" font-size="11" text-anchor="middle" fill="var(--text)">취소</text>
<rect x="582.667" y="54" width="69.3333" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="582.667" y="64" width="56" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="610.667" y="84" font-size="11" text-anchor="middle" fill="var(--text)">다시 보기</text>
<text x="540.0" y="132" font-size="12" text-anchor="middle" fill="var(--warn)">칸만 넓어져 사이가 벌어진다</text>
<text x="20" y="194" font-size="13" fill="var(--text)">Control Child Size</text>
<text x="20" y="212" font-size="13" fill="var(--text)">켬</text>
<rect x="160" y="168" width="240" height="64" rx="4" stroke="var(--text)" fill="var(--bg)"></rect>
<rect x="168" y="174" width="36" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="168" y="184" width="36" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="186" y="204" font-size="11" text-anchor="middle" fill="var(--text)">확인</text>
<rect x="212" y="174" width="36" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="212" y="184" width="36" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="230" y="204" font-size="11" text-anchor="middle" fill="var(--text)">취소</text>
<rect x="256" y="174" width="64" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="256" y="184" width="64" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="288" y="204" font-size="11" text-anchor="middle" fill="var(--text)">다시 보기</text>
<text x="280.0" y="252" font-size="12" text-anchor="middle" fill="var(--text-muted)">글자에 맞춰 줄어든다 (Hug)</text>
<rect x="420" y="168" width="240" height="64" rx="4" stroke="var(--text)" fill="var(--bg)"></rect>
<rect x="428" y="174" width="60" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="428" y="184" width="60" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="458" y="204" font-size="11" text-anchor="middle" fill="var(--text)">확인</text>
<rect x="496" y="174" width="60" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="496" y="184" width="60" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="526" y="204" font-size="11" text-anchor="middle" fill="var(--text)">취소</text>
<rect x="564" y="174" width="88" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="564" y="184" width="88" height="32" rx="4" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="608" y="204" font-size="11" text-anchor="middle" fill="var(--text)">다시 보기</text>
<text x="540.0" y="252" font-size="12" text-anchor="middle" fill="var(--text-muted)">부모를 꽉 채운다 (Fill)</text>
</svg>
<figcaption>점선이 그룹이 나눠 준 칸, 채운 사각형이 버튼입니다. 오른쪽 위에서만 칸과 버튼이 어긋납니다.</figcaption>
</figure>

**Control Child Size** 는 "그룹이 자식 크기까지 정할까" 입니다.

- **끄면** 자식은 자기 RectTransform 의 Width 를 그대로 갖습니다. 그룹은 위치만 정합니다
- **켜면** 그룹이 앞에서 본 Min, Preferred, Flexible 로 크기를 정합니다

**Child Force Expand** 는 "남는 공간을 자식마다 나눠 줄까" 입니다. 정확히는 모든 자식의 Flexible 을 최소 1 로 올립니다.

여기서 헷갈리는 자리가 나옵니다. **그룹이 나눠 주는 것은 칸** 입니다.
Control Child Size 가 꺼져 있으면 그룹은 자식 크기를 못 건드리니, **칸만 넓어지고 버튼은 그대로** 입니다.
버튼은 넓어진 칸 안에서 Child Alignment 대로 놓이고, 그래서 **버튼 사이가 벌어집니다.**
처음에 본 "버튼 사이가 제멋대로 벌어진다" 가 바로 오른쪽 위 모양입니다.

직접 켜고 꺼 보면 더 분명합니다. 부모 너비를 바꾸면 공간이 모자랄 때와 남을 때도 볼 수 있습니다.

<x-hlg>
<script type="application/json">
{
  "label": "Horizontal Layout Group 을 직접 켜고 끄기",
  "children": [
    {
      "label": "확인",
      "width": 120,
      "min": 48,
      "preferred": 72
    },
    {
      "label": "취소",
      "width": 120,
      "min": 48,
      "preferred": 72
    },
    {
      "label": "다시 보기",
      "width": 120,
      "min": 48,
      "preferred": 120
    }
  ],
  "widths": [
    [
      "좁게",
      240
    ],
    [
      "보통",
      520
    ],
    [
      "넓게",
      640
    ]
  ],
  "padding": 12,
  "spacing": 12,
  "default": {
    "width": 1,
    "align": 0,
    "control": false,
    "expand": true
  },
  "note": "버튼 셋 모두 자기 Width 는 120 입니다. 그룹이 크기를 정할 때 쓰는 값은 Min 48, Preferred 72 / 72 / 120 입니다. 계산은 uGUI 의 HorizontalLayoutGroup 과 같습니다."
}
</script>
</x-hlg>

## Figma Auto Layout 에서 넘어올 때

**Padding, Gap, 정렬은 이름만 다르고 그대로 옮겨집니다.**

<figure class="diagram">
<svg viewBox="0 0 680 210" role="img" aria-label="Figma 의 Padding, Gap, 정렬이 Unity 의 Padding, Spacing, Child Alignment 로 이름만 바뀌어 옮겨진다는 그림">
<rect x="40" y="40" width="330" height="100" rx="6" fill="var(--bg)" stroke="var(--text)"></rect>
<rect x="60" y="60" width="290" height="60" fill="none" stroke="var(--border)" stroke-dasharray="3 3"></rect>
<rect x="60" y="60" width="64" height="34" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="92" y="81" font-size="12" text-anchor="middle" fill="var(--text)">확인</text>
<line x1="124" y1="128" x2="140" y2="128" stroke="var(--accent)" stroke-width="2"></line>
<rect x="140" y="60" width="64" height="34" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="172" y="81" font-size="12" text-anchor="middle" fill="var(--text)">취소</text>
<line x1="204" y1="128" x2="220" y2="128" stroke="var(--accent)" stroke-width="2"></line>
<rect x="220" y="60" width="96" height="34" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="268" y="81" font-size="12" text-anchor="middle" fill="var(--text)">다시 보기</text>
<line x1="40" y1="77" x2="60" y2="77" stroke="var(--warn)" stroke-width="2"></line>
<line x1="190" y1="40" x2="190" y2="60" stroke="var(--warn)" stroke-width="2"></line>
<text x="40" y="28" font-size="12" fill="var(--text-muted)">Figma 프레임 (Auto Layout)</text>
<text x="40" y="164" font-size="12" fill="var(--warn)">주황: Padding</text>
<text x="150" y="164" font-size="12" fill="var(--accent)">파랑: Gap</text>
<text x="400" y="58" font-size="13" fill="var(--text-muted)">Padding</text>
<line x1="480" y1="54" x2="510" y2="54" stroke="var(--text-muted)"></line><polygon points="510,50 517,54 510,58" fill="var(--text-muted)"></polygon>
<text x="526" y="58" font-size="13" fill="var(--text)">Padding</text>
<text x="400" y="92" font-size="13" fill="var(--text-muted)">Gap</text>
<line x1="480" y1="88" x2="510" y2="88" stroke="var(--text-muted)"></line><polygon points="510,84 517,88 510,92" fill="var(--text-muted)"></polygon>
<text x="526" y="92" font-size="13" fill="var(--text)">Spacing</text>
<text x="400" y="126" font-size="13" fill="var(--text-muted)">Alignment</text>
<line x1="480" y1="122" x2="510" y2="122" stroke="var(--text-muted)"></line><polygon points="510,118 517,122 510,126" fill="var(--text-muted)"></polygon>
<text x="526" y="126" font-size="13" fill="var(--text)">Child Alignment</text>
<rect x="400" y="150" width="12" height="12" rx="2" fill="var(--accent)" stroke="var(--text-muted)"></rect>
<rect x="414" y="150" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="428" y="150" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="400" y="164" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="414" y="164" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="428" y="164" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="400" y="178" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="414" y="178" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<rect x="428" y="178" width="12" height="12" rx="2" fill="var(--bg)" stroke="var(--text-muted)"></rect>
<text x="454" y="164" font-size="12" fill="var(--text-muted)">정렬 3 × 3 칸이 그대로</text>
<text x="454" y="182" font-size="12" fill="var(--text-muted)">Upper Left 부터 Lower Right 까지</text>
</svg>
<figcaption>Gap 은 Spacing 으로, 정렬 아홉 칸은 Child Alignment 의 아홉 이름으로 바뀝니다.</figcaption>
</figure>

**달라지는 것은 자식 크기입니다.**
Figma 는 자식마다 W 를 Hug, Fixed, Fill 중에서 고릅니다.
Unity 의 Control Child Size 와 Child Force Expand 는 **그룹에 붙어 있어서 모든 자식에 한꺼번에** 걸립니다.
그래서 자식마다 다르게 하려면 순서를 이렇게 잡습니다.

1. 그룹에서 **Control Child Size 는 켜고, Child Force Expand 는 끕니다.** 이러면 모든 자식이 Hug 로 시작합니다
2. Fixed 나 Fill 이어야 하는 자식에만 **Layout Element** 를 붙여 바꿉니다

Child Force Expand 를 켜 두면 모든 자식의 Flexible 이 1 이상이 되어, Fixed 로 둔 자식까지 늘어납니다. 섞어 쓰려면 꺼 둬야 합니다.
아래 그림은 모두 이 설정에서 출발합니다.

### Hug: 글자에 맞춰 줄어들기

<figure class="diagram">
<svg viewBox="0 0 680 364" role="img" aria-label="Hug: 버튼마다 Horizontal Layout Group 을 붙여 글자 폭에 Padding 을 더한 만큼만 차지하고, 부모 폭이 520 이든 360 이든 64, 64, 104 로 같다">
<rect x="20" y="12" width="270" height="136" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<rect x="350" y="12" width="310" height="136" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<text x="34" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Figma</text>
<text x="364" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Unity</text>
<text x="34" y="56" font-size="12" fill="var(--text-muted)">확인, 취소, 다시 보기</text>
<text x="34" y="76" font-size="12" fill="var(--text)">W  Hug contents</text>
<text x="34" y="96" font-size="12" fill="var(--text-muted)">버튼 프레임에도 Auto Layout</text>
<text x="34" y="116" font-size="12" fill="var(--text-muted)">좌우 Padding 16</text>
<text x="364" y="56" font-size="12" fill="var(--text)">부모: Horizontal Layout Group</text>
<text x="364" y="76" font-size="12" fill="var(--text-muted)">Control Child Size 켬</text>
<text x="364" y="96" font-size="12" fill="var(--text-muted)">Child Force Expand 끔</text>
<text x="364" y="116" font-size="12" fill="var(--text)">버튼마다: Horizontal Layout Group</text>
<text x="364" y="136" font-size="12" fill="var(--text-muted)">Padding 16, Control Child Size 켬</text>
<line x1="298" y1="80" x2="336" y2="80" stroke="var(--text-muted)" stroke-width="1.5"></line><polygon points="336,75 344,80 336,85" fill="var(--text-muted)"></polygon>
<text x="20" y="200" font-size="12" fill="var(--text)">넓을 때</text>
<text x="20" y="218" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 520</text>
<rect x="150" y="182" width="505" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="157.769" y="190" width="62.1538" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<rect x="173.308" y="196" width="31.0769" height="18" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 2"></rect>
<text x="188.846" y="209" font-size="12" text-anchor="middle" fill="var(--text)">확인</text>
<text x="188.846" y="244" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<rect x="227.692" y="190" width="62.1538" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<rect x="243.231" y="196" width="31.0769" height="18" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 2"></rect>
<text x="258.769" y="209" font-size="12" text-anchor="middle" fill="var(--text)">취소</text>
<text x="258.769" y="244" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<rect x="297.615" y="190" width="101" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<rect x="313.154" y="196" width="69.9231" height="18" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 2"></rect>
<text x="348.115" y="209" font-size="12" text-anchor="middle" fill="var(--text)">다시 보기</text>
<text x="348.115" y="244" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">104</text>
<text x="20" y="284" font-size="12" fill="var(--text)">좁을 때</text>
<text x="20" y="302" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 360</text>
<rect x="150" y="266" width="349.615" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="157.769" y="274" width="62.1538" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<rect x="173.308" y="280" width="31.0769" height="18" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 2"></rect>
<text x="188.846" y="293" font-size="12" text-anchor="middle" fill="var(--text)">확인</text>
<text x="188.846" y="328" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<rect x="227.692" y="274" width="62.1538" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<rect x="243.231" y="280" width="31.0769" height="18" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 2"></rect>
<text x="258.769" y="293" font-size="12" text-anchor="middle" fill="var(--text)">취소</text>
<text x="258.769" y="328" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<rect x="297.615" y="274" width="101" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<rect x="313.154" y="280" width="69.9231" height="18" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 2"></rect>
<text x="348.115" y="293" font-size="12" text-anchor="middle" fill="var(--text)">다시 보기</text>
<text x="348.115" y="328" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">104</text>
<rect x="150" y="342" width="20" height="12" rx="2" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)"></rect>
<text x="176" y="352" font-size="12" fill="var(--text-muted)">Hug</text>
</svg>
<figcaption>버튼 안의 점선이 글자 영역입니다. 부모 폭이 바뀌어도 버튼 폭은 그대로이고 남는 공간은 Child Alignment 쪽에 모입니다.</figcaption>
</figure>

부모 그룹의 Control Child Size 가 켜져 있으면 버튼 폭은 **버튼의 Preferred** 가 됩니다.

여기서 한 번 더 걸리는 곳이 있습니다. 버튼 오브젝트는 이미지라서 Preferred 가 **글자와 상관없는 값** 입니다.
버튼이 글자에 맞추려면 **버튼에도 Horizontal Layout Group 을 붙여서** Preferred 를 "글자 폭 + Padding" 으로 만들어야 합니다.
Figma 에서 버튼 프레임에도 Auto Layout 을 거는 것과 같은 일입니다.

### Fixed: 폭 고정

<figure class="diagram">
<svg viewBox="0 0 680 428" role="img" aria-label="Fixed: 뒤로 버튼의 Layout Element 에 Preferred Width 120 만 두면 부모가 240 일 때 90 으로 줄고, Min Width 도 120 으로 두면 120 을 지킨다">
<rect x="20" y="12" width="270" height="116" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<rect x="350" y="12" width="310" height="116" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<text x="34" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Figma</text>
<text x="364" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Unity</text>
<text x="34" y="56" font-size="12" fill="var(--text-muted)">뒤로</text>
<text x="34" y="76" font-size="12" fill="var(--text)">W  Fixed 120</text>
<text x="34" y="96" font-size="12" fill="var(--text-muted)">제목, 확인: Hug</text>
<text x="364" y="56" font-size="12" fill="var(--text)">뒤로: Layout Element</text>
<text x="364" y="76" font-size="12" fill="var(--text-muted)">Preferred Width 120</text>
<text x="364" y="96" font-size="12" fill="var(--text-muted)">Min Width 120</text>
<text x="364" y="116" font-size="12" fill="var(--text-muted)">부모 그룹: Control 켬, Expand 끔</text>
<line x1="298" y1="70" x2="336" y2="70" stroke="var(--text-muted)" stroke-width="1.5"></line><polygon points="336,65 344,70 336,75" fill="var(--text-muted)"></polygon>
<text x="20" y="180" font-size="12" fill="var(--text)">넓을 때</text>
<text x="20" y="198" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 400</text>
<rect x="150" y="162" width="400" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="158" y="170" width="120" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="218" y="189" font-size="12" text-anchor="middle" fill="var(--text)">뒤로</text>
<text x="218" y="224" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">120</text>
<rect x="286" y="170" width="72" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="322" y="189" font-size="12" text-anchor="middle" fill="var(--text)">제목</text>
<text x="322" y="224" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">72</text>
<rect x="366" y="170" width="64" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="398" y="189" font-size="12" text-anchor="middle" fill="var(--text)">확인</text>
<text x="398" y="224" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<text x="20" y="264" font-size="12" fill="var(--text)">좁고 Min 없음</text>
<text x="20" y="282" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 240</text>
<rect x="150" y="246" width="240" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="158" y="254" width="90" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="203" y="273" font-size="12" text-anchor="middle" fill="var(--text)">뒤로</text>
<text x="203" y="308" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">90</text>
<rect x="256" y="254" width="62" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="287" y="273" font-size="12" text-anchor="middle" fill="var(--text)">제목</text>
<text x="287" y="308" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">62</text>
<rect x="326" y="254" width="56" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="354" y="273" font-size="12" text-anchor="middle" fill="var(--text)">확인</text>
<text x="354" y="308" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">56</text>
<text x="20" y="348" font-size="12" fill="var(--text)">좁고 Min 120</text>
<text x="20" y="366" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 240</text>
<rect x="150" y="330" width="240" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="158" y="338" width="120" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="218" y="357" font-size="12" text-anchor="middle" fill="var(--text)">뒤로</text>
<text x="218" y="392" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">120</text>
<rect x="286" y="338" width="45.3333" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="308.667" y="357" font-size="12" text-anchor="middle" fill="var(--text)">제목</text>
<text x="308.667" y="392" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">45</text>
<rect x="339.333" y="338" width="42.6667" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="360.667" y="357" font-size="12" text-anchor="middle" fill="var(--text)">확인</text>
<text x="360.667" y="392" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">43</text>
<rect x="150" y="406" width="20" height="12" rx="2" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)"></rect>
<text x="176" y="416" font-size="12" fill="var(--text-muted)">Fixed</text>
<rect x="240" y="406" width="20" height="12" rx="2" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)"></rect>
<text x="266" y="416" font-size="12" fill="var(--text-muted)">Hug</text>
</svg>
<figcaption>Preferred Width 만 두면 좁아질 때 뒤로 버튼도 같이 줄어듭니다. Min Width 까지 같게 두어야 120 을 지킵니다.</figcaption>
</figure>

자식에 Layout Element 를 붙이고 **Preferred Width 를 120** 으로 둡니다.

**Min Width 도 120 으로 같이** 둡니다. 앞에서 본 대로 공간이 모자라면 그룹은 Min 과 Preferred 사이에서 줄이니, Preferred 만 두면 좁은 화면에서 줄어듭니다.
Figma 의 Fixed 는 줄지 않으니 둘을 같게 둬야 같은 뜻이 됩니다.

부모 그룹의 Control Child Size 를 끄는 방법도 있지만, 그러면 **모든 자식** 이 자기 RectTransform 의 Width 를 쓰게 되어 Hug 나 Fill 과 섞을 수 없습니다.

### Fill: 남는 공간 채우기

<figure class="diagram">
<svg viewBox="0 0 680 408" role="img" aria-label="Fill: 검색창의 Layout Element 에 Flexible Width 1 을 두면 부모가 넓어질 때 검색창만 늘어나고, Flexible 1 과 2 는 남는 공간을 1 대 2 로 나눈다">
<rect x="20" y="12" width="270" height="96" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<rect x="350" y="12" width="310" height="96" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<text x="34" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Figma</text>
<text x="364" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Unity</text>
<text x="34" y="56" font-size="12" fill="var(--text-muted)">검색창</text>
<text x="34" y="76" font-size="12" fill="var(--text)">W  Fill container</text>
<text x="34" y="96" font-size="12" fill="var(--text-muted)">검색 버튼: Hug</text>
<text x="364" y="56" font-size="12" fill="var(--text)">검색창: Layout Element</text>
<text x="364" y="76" font-size="12" fill="var(--text-muted)">Flexible Width 1</text>
<text x="364" y="96" font-size="12" fill="var(--text-muted)">부모 그룹: Control 켬, Expand 끔</text>
<line x1="298" y1="60" x2="336" y2="60" stroke="var(--text-muted)" stroke-width="1.5"></line><polygon points="336,55 344,60 336,65" fill="var(--text-muted)"></polygon>
<text x="20" y="160" font-size="12" fill="var(--text)">좁을 때</text>
<text x="20" y="178" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 360</text>
<rect x="150" y="142" width="303" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="156.733" y="150" width="228.933" height="30" rx="4" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)" stroke-width="1.5"></rect>
<text x="271.2" y="169" font-size="12" text-anchor="middle" fill="var(--text)">검색창</text>
<text x="271.2" y="204" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">272</text>
<rect x="392.4" y="150" width="53.8667" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="419.333" y="169" font-size="12" text-anchor="middle" fill="var(--text)">검색</text>
<text x="419.333" y="204" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<text x="20" y="244" font-size="12" fill="var(--text)">넓을 때</text>
<text x="20" y="262" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 600</text>
<rect x="150" y="226" width="505" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="156.733" y="234" width="430.933" height="30" rx="4" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)" stroke-width="1.5"></rect>
<text x="372.2" y="253" font-size="12" text-anchor="middle" fill="var(--text)">검색창</text>
<text x="372.2" y="288" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">512</text>
<rect x="594.4" y="234" width="53.8667" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="621.333" y="253" font-size="12" text-anchor="middle" fill="var(--text)">검색</text>
<text x="621.333" y="288" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<text x="20" y="328" font-size="12" fill="var(--text)">Flexible 1 과 2</text>
<text x="20" y="346" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 600</text>
<rect x="150" y="310" width="505" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="156.733" y="318" width="184.044" height="30" rx="4" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)" stroke-width="1.5"></rect>
<text x="248.756" y="337" font-size="12" text-anchor="middle" fill="var(--text)">A (1)</text>
<text x="248.756" y="372" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">219</text>
<rect x="347.511" y="318" width="300.756" height="30" rx="4" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)" stroke-width="1.5"></rect>
<text x="497.889" y="337" font-size="12" text-anchor="middle" fill="var(--text)">B (2)</text>
<text x="497.889" y="372" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">357</text>
<rect x="150" y="386" width="20" height="12" rx="2" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)"></rect>
<text x="176" y="396" font-size="12" fill="var(--text-muted)">Fill</text>
<rect x="240" y="386" width="20" height="12" rx="2" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)"></rect>
<text x="266" y="396" font-size="12" fill="var(--text-muted)">Hug</text>
</svg>
<figcaption>Flexible 1 과 2 는 전체 폭이 아니라 남는 공간을 1 : 2 로 나눕니다. 그래서 B 가 A 의 두 배보다 작습니다.</figcaption>
</figure>

자식에 Layout Element 를 붙이고 **Flexible Width 를 1** 로 둡니다.

- Flexible 은 **비율** 입니다. 둘 다 Preferred 80 에서 출발하고, 남는 416 을 1 : 2 로 나눠 A 는 219, B 는 357 이 됩니다
- 모든 자식이 Fill 이면 그룹의 Child Force Expand 를 켜는 것과 같습니다

### 섞어 쓰기: 검색 바

<figure class="diagram">
<svg viewBox="0 0 680 344" role="img" aria-label="섞어 쓰기: 뒤로는 Fixed 48, 검색창은 Fill, 필터는 Hug 로 두면 부모가 넓어질 때 검색창만 늘어난다">
<rect x="20" y="12" width="270" height="116" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<rect x="350" y="12" width="310" height="116" rx="6" fill="var(--bg)" stroke="var(--border)"></rect>
<text x="34" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Figma</text>
<text x="364" y="34" font-size="12" font-weight="600" fill="var(--text-muted)">Unity</text>
<text x="34" y="56" font-size="12" fill="var(--text)">뒤로  W Fixed 48</text>
<text x="34" y="76" font-size="12" fill="var(--text)">검색창  W Fill container</text>
<text x="34" y="96" font-size="12" fill="var(--text)">필터  W Hug contents</text>
<text x="364" y="56" font-size="12" fill="var(--text-muted)">뒤로: Min, Preferred Width 48</text>
<text x="364" y="76" font-size="12" fill="var(--text-muted)">검색창: Flexible Width 1</text>
<text x="364" y="96" font-size="12" fill="var(--text-muted)">필터: 설정 없음</text>
<text x="364" y="116" font-size="12" fill="var(--text-muted)">부모 그룹: Control 켬, Expand 끔</text>
<line x1="298" y1="70" x2="336" y2="70" stroke="var(--text-muted)" stroke-width="1.5"></line><polygon points="336,65 344,70 336,75" fill="var(--text-muted)"></polygon>
<text x="20" y="180" font-size="12" fill="var(--text)">좁을 때</text>
<text x="20" y="198" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 360</text>
<rect x="150" y="162" width="303" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="156.733" y="170" width="40.4" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="176.933" y="189" font-size="12" text-anchor="middle" fill="var(--text)">뒤로</text>
<text x="176.933" y="224" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">48</text>
<rect x="203.867" y="170" width="181.8" height="30" rx="4" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)" stroke-width="1.5"></rect>
<text x="294.767" y="189" font-size="12" text-anchor="middle" fill="var(--text)">검색창</text>
<text x="294.767" y="224" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">216</text>
<rect x="392.4" y="170" width="53.8667" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="419.333" y="189" font-size="12" text-anchor="middle" fill="var(--text)">필터</text>
<text x="419.333" y="224" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<text x="20" y="264" font-size="12" fill="var(--text)">넓을 때</text>
<text x="20" y="282" font-size="11" font-family="var(--font-mono)" fill="var(--text-muted)">부모 600</text>
<rect x="150" y="246" width="505" height="46" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="156.733" y="254" width="40.4" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="176.933" y="273" font-size="12" text-anchor="middle" fill="var(--text)">뒤로</text>
<text x="176.933" y="308" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">48</text>
<rect x="203.867" y="254" width="383.8" height="30" rx="4" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)" stroke-width="1.5"></rect>
<text x="395.767" y="273" font-size="12" text-anchor="middle" fill="var(--text)">검색창</text>
<text x="395.767" y="308" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">456</text>
<rect x="594.4" y="254" width="53.8667" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="621.333" y="273" font-size="12" text-anchor="middle" fill="var(--text)">필터</text>
<text x="621.333" y="308" font-size="11" text-anchor="middle" font-family="var(--font-mono)" fill="var(--text-muted)">64</text>
<rect x="150" y="322" width="20" height="12" rx="2" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)"></rect>
<text x="176" y="332" font-size="12" fill="var(--text-muted)">Fixed</text>
<rect x="240" y="322" width="20" height="12" rx="2" fill="var(--accent2)" fill-opacity="0.3" stroke="var(--accent2)"></rect>
<text x="266" y="332" font-size="12" fill="var(--text-muted)">Fill</text>
<rect x="330" y="322" width="20" height="12" rx="2" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)"></rect>
<text x="356" y="332" font-size="12" fill="var(--text-muted)">Hug</text>
</svg>
<figcaption>넓어진 만큼을 검색창 혼자 받습니다. 뒤로는 48, 필터는 글자 폭 그대로입니다.</figcaption>
</figure>

실제 화면은 대부분 이렇게 섞여 있습니다. 설정은 위 셋을 자식마다 붙인 것뿐입니다.
최대 폭이 필요하면 Unity 6.6 부터 Layout Element 의 **Max Width** 를 씁니다.

### Absolute position: Ignore Layout

Figma 에서 Auto Layout 안의 한 요소만 **Absolute position** 으로 빼면 흐름에서 빠지고 자유롭게 놓입니다.
Unity 에서는 그 자식의 Layout Element 에서 **Ignore Layout** 을 켭니다.

<x-tabs>
<figure class="diagram" data-tab="Ignore Layout 끔">
<svg viewBox="0 0 680 150" role="img" aria-label="Ignore Layout 끔">
<text x="100" y="28" font-size="12" fill="var(--text-muted)">탭 바 (Horizontal Layout Group, Control 켬, Expand 켬)</text>
<rect x="100" y="40" width="480" height="60" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="106" y="46" width="112.5" height="48" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="162.25" y="74" font-size="12" text-anchor="middle" fill="var(--text)">장비</text>
<rect x="224.5" y="46" width="112.5" height="48" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="280.75" y="74" font-size="12" text-anchor="middle" fill="var(--text)">재료</text>
<rect x="343" y="46" width="112.5" height="48" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="399.25" y="74" font-size="12" text-anchor="middle" fill="var(--text)">소모품</text>
<rect x="461.5" y="46" width="112.5" height="48" rx="4" fill="var(--warn)" fill-opacity="0.3" stroke="var(--warn)" stroke-width="1.5"></rect>
<text x="517.75" y="74" font-size="12" text-anchor="middle" fill="var(--text)">밑줄</text>
<text x="580" y="124" font-size="12" text-anchor="end" fill="var(--warn)">밑줄이 네 번째 탭처럼 칸을 받았다</text>
</svg>
<figcaption>밑줄도 그룹의 자식이라 탭들과 똑같이 칸을 나눠 받습니다.</figcaption>
</figure>
<figure class="diagram" data-tab="Ignore Layout 켬">
<svg viewBox="0 0 680 150" role="img" aria-label="Ignore Layout 켬">
<text x="100" y="28" font-size="12" fill="var(--text-muted)">탭 바 (Horizontal Layout Group, Control 켬, Expand 켬)</text>
<rect x="100" y="40" width="480" height="60" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="106" y="46" width="152" height="48" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="182" y="74" font-size="12" text-anchor="middle" fill="var(--text)">장비</text>
<rect x="264" y="46" width="152" height="48" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="340" y="74" font-size="12" text-anchor="middle" fill="var(--text)">재료</text>
<rect x="422" y="46" width="152" height="48" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="498" y="74" font-size="12" text-anchor="middle" fill="var(--text)">소모품</text>
<rect x="276" y="86" width="128" height="5" rx="2" fill="var(--warn)"></rect>
<line x1="340" y1="94" x2="340" y2="118" stroke="var(--warn)"></line>
<text x="340" y="132" font-size="12" text-anchor="middle" fill="var(--warn)">밑줄: 칸을 안 받고 자기 자리에</text>
</svg>
<figcaption>그룹이 밑줄을 건너뛰고 탭 셋만 나눕니다. 밑줄은 자기 RectTransform 대로 놓이니 코드로 옮길 수 있습니다.</figcaption>
</figure>
</x-tabs>

선택된 탭 아래를 따라다니는 밑줄, 버튼 모서리에 겹치는 알림 점처럼 **줄에 끼면 안 되는 장식** 에 씁니다.

### Gap 의 Auto 는 똑같이 만들 수 없다

Figma 의 Gap 을 **Auto** 로 두면 양끝 요소가 가장자리에 붙고 사이만 벌어집니다. Unity 에는 같은 설정이 없습니다.

<figure class="diagram">
<svg viewBox="0 0 680 230" role="img" aria-label="Figma 의 Gap Auto 는 양끝 요소가 가장자리에 붙지만, Unity 에서 가장 가까운 설정은 칸 안에서 가운데라 양끝에도 여백이 생긴다">
<text x="20" y="50" font-size="12" fill="var(--text)">Figma</text><text x="20" y="68" font-size="11" fill="var(--text-muted)">Gap: Auto</text>
<rect x="150" y="30" width="420" height="50" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="162" y="40" width="70" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="197" y="59" font-size="12" text-anchor="middle" fill="var(--text)">A</text>
<rect x="325" y="40" width="70" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="360" y="59" font-size="12" text-anchor="middle" fill="var(--text)">B</text>
<rect x="488" y="40" width="70" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="523" y="59" font-size="12" text-anchor="middle" fill="var(--text)">C</text>
<text x="580" y="60" font-size="12" fill="var(--text-muted)">양끝이 붙는다</text>
<text x="20" y="134" font-size="12" fill="var(--text)">Unity</text><text x="20" y="152" font-size="11" fill="var(--text-muted)">Control 끔</text><text x="20" y="168" font-size="11" fill="var(--text-muted)">Expand 켬, 가운데</text>
<rect x="150" y="120" width="420" height="50" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="162" y="124" width="132" height="42" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="193" y="130" width="70" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="228" y="149" font-size="12" text-anchor="middle" fill="var(--text)">A</text>
<rect x="294" y="124" width="132" height="42" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="325" y="130" width="70" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="360" y="149" font-size="12" text-anchor="middle" fill="var(--text)">B</text>
<rect x="426" y="124" width="132" height="42" fill="none" stroke="var(--text-muted)" stroke-dasharray="4 3"></rect>
<rect x="457" y="130" width="70" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="492" y="149" font-size="12" text-anchor="middle" fill="var(--text)">C</text>
<line x1="162" y1="182" x2="193" y2="182" stroke="var(--warn)" stroke-width="2"></line>
<text x="162" y="200" font-size="11" fill="var(--warn)">양끝에도 여백 31</text>
<text x="580" y="150" font-size="12" fill="var(--text-muted)">칸 안에서 가운데</text>
</svg>
<figcaption>Unity 는 칸을 똑같이 나누고 칸 안에서 정렬하므로, 양끝에도 여백이 남습니다.</figcaption>
</figure>

양끝을 꼭 붙여야 하면 가장 왼쪽과 가장 오른쪽 요소를 그룹 밖으로 빼서 앵커로 모서리에 붙이는 편이 정확합니다.

### 크기가 다른 요소의 줄바꿈은 없다

Figma 의 **Wrap** 은 폭이 제각각인 요소를 줄바꿈하며 채웁니다. Unity 기본 컴포넌트에는 이것이 없습니다.

<figure class="diagram">
<svg viewBox="0 0 680 270" role="img" aria-label="Figma 의 Wrap 은 폭이 다른 태그가 줄바꿈되며 채워지지만, Unity 의 Grid Layout Group 은 모든 칸이 같은 크기로 줄바꿈된다">
<text x="20" y="44" font-size="12" fill="var(--text)">Figma</text><text x="20" y="62" font-size="11" fill="var(--text-muted)">Wrap</text>
<rect x="150" y="24" width="360" height="96" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="160" y="34" width="56" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="188" y="53" font-size="12" text-anchor="middle" fill="var(--text)">전사</text>
<rect x="224" y="34" width="72" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="260" y="53" font-size="12" text-anchor="middle" fill="var(--text)">마법사</text>
<rect x="304" y="34" width="56" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="332" y="53" font-size="12" text-anchor="middle" fill="var(--text)">궁수</text>
<rect x="368" y="34" width="56" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="396" y="53" font-size="12" text-anchor="middle" fill="var(--text)">치유</text>
<rect x="160" y="74" width="104" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="212" y="93" font-size="12" text-anchor="middle" fill="var(--text)">원거리 딜러</text>
<rect x="272" y="74" width="56" height="30" rx="4" fill="var(--accent-soft)" fill-opacity="1" stroke="var(--accent)" stroke-width="1.5"></rect>
<text x="300" y="93" font-size="12" text-anchor="middle" fill="var(--text)">탱커</text>
<text x="522" y="64" font-size="12" fill="var(--text-muted)">폭이 제각각인 채로</text><text x="522" y="82" font-size="12" fill="var(--text-muted)">줄이 넘어간다</text>
<text x="20" y="170" font-size="12" fill="var(--text)">Unity</text><text x="20" y="188" font-size="11" fill="var(--text-muted)">Grid Layout Group</text>
<rect x="150" y="150" width="360" height="96" rx="4" fill="none" stroke="var(--text)"></rect>
<rect x="160" y="160" width="106" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="213" y="179" font-size="12" text-anchor="middle" fill="var(--text)">전사</text>
<rect x="274" y="160" width="106" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="327" y="179" font-size="12" text-anchor="middle" fill="var(--text)">마법사</text>
<rect x="388" y="160" width="106" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="441" y="179" font-size="12" text-anchor="middle" fill="var(--text)">궁수</text>
<rect x="160" y="200" width="106" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="213" y="219" font-size="12" text-anchor="middle" fill="var(--text)">치유</text>
<rect x="274" y="200" width="106" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="327" y="219" font-size="12" text-anchor="middle" fill="var(--text)">원거리 딜러</text>
<rect x="388" y="200" width="106" height="30" rx="4" fill="var(--bg-subtle)" fill-opacity="1" stroke="var(--text)" stroke-width="1.5"></rect>
<text x="441" y="219" font-size="12" text-anchor="middle" fill="var(--text)">탱커</text>
<text x="522" y="190" font-size="12" fill="var(--text-muted)">모든 칸이 Cell Size</text><text x="522" y="208" font-size="12" fill="var(--text-muted)">하나로 같다</text>
</svg>
<figcaption>줄바꿈을 하는 것은 Grid Layout Group 뿐인데, 칸 크기가 모두 같습니다.</figcaption>
</figure>

태그 목록처럼 폭이 다른 요소를 줄바꿈해야 하면 프로그래머가 따로 만들어야 합니다. 시안에서 Wrap 을 썼다면 미리 알려 주세요.

## 글에 맞춰 커지는 박스: Content Size Fitter

Layout Group 은 자식을 배치할 뿐, **자기 크기는 바꾸지 않습니다.**
자기 크기를 내용에 맞추는 것이 **Content Size Fitter** 입니다. 가로와 세로를 따로 고릅니다.

| Fit | 하는 일 |
| --- | --- |
| Unconstrained | 크기를 건드리지 않습니다 |
| Min Size | Min 크기로 맞춥니다 |
| **Preferred Size** | Preferred 크기로 맞춥니다. 거의 이것을 씁니다 |

캐릭터 머리 위 말풍선이 대표적인 예입니다. 말풍선 이미지에 Horizontal Layout Group 과 Content Size Fitter 를 같이 붙이고, 안에 글자를 넣습니다.
그룹의 Preferred 는 **글자 폭에 Padding 을 더한 값** 이라, Content Size Fitter 가 말풍선을 딱 그만큼으로 맞춥니다.

<x-tabs>
<figure class="diagram" data-tab="짧은 글">
<svg viewBox="0 0 680 210" role="img" aria-label="짧은 글: 말풍선 너비 74, 줄 수 1">
<circle cx="60" cy="178" r="22" fill="var(--bg)" stroke="var(--text-muted)"></circle>
<text x="60" y="182" font-size="11" text-anchor="middle" fill="var(--text-muted)">캐릭터</text>
<line x1="420" y1="20" x2="420" y2="190" stroke="var(--warn)" stroke-dasharray="5 4"></line>
<text x="414" y="200" font-size="11" text-anchor="end" fill="var(--warn)">Max Width 320</text>
<rect x="100" y="112" width="74" height="52" rx="12" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<polygon points="110,164 126,164 104,176" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></polygon>
<line x1="111" y1="164" x2="125" y2="164" stroke="var(--accent-soft)" stroke-width="3"></line>
<text x="116" y="142" font-size="14" fill="var(--text)">안녕!</text>
<rect x="116" y="124" width="42" height="28" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 3"></rect>
<circle cx="100" cy="164" r="4" stroke="var(--warn)" stroke-width="2" fill="var(--bg)"></circle>
<text x="94" y="186" font-size="11" fill="var(--text-muted)">피벗 (0, 0)</text>
<text x="460" y="26" font-size="12" fill="var(--text)">말풍선 (Image, 9-slice)</text>
<text x="474" y="46" font-size="12" fill="var(--text-muted)">Horizontal Layout Group</text>
<text x="488" y="66" font-size="12" fill="var(--text-muted)">Padding 16</text>
<text x="488" y="86" font-size="12" fill="var(--text-muted)">Control Child Size 켬</text>
<text x="474" y="106" font-size="12" fill="var(--text-muted)">Content Size Fitter</text>
<text x="488" y="126" font-size="12" fill="var(--text-muted)">가로 세로 Preferred Size</text>
<text x="474" y="146" font-size="12" fill="var(--text-muted)">Layout Element</text>
<text x="488" y="166" font-size="12" fill="var(--text-muted)">Max Width 320</text>
<text x="474" y="186" font-size="12" fill="var(--text)">글자 (TextMeshPro)</text>
</svg>
<figcaption>글자 폭에 Padding 을 더한 만큼만 커집니다.</figcaption>
</figure>
<figure class="diagram" data-tab="긴 글">
<svg viewBox="0 0 680 210" role="img" aria-label="긴 글: 말풍선 너비 270, 줄 수 1">
<circle cx="60" cy="178" r="22" fill="var(--bg)" stroke="var(--text-muted)"></circle>
<text x="60" y="182" font-size="11" text-anchor="middle" fill="var(--text-muted)">캐릭터</text>
<line x1="420" y1="20" x2="420" y2="190" stroke="var(--warn)" stroke-dasharray="5 4"></line>
<text x="414" y="200" font-size="11" text-anchor="end" fill="var(--warn)">Max Width 320</text>
<rect x="100" y="112" width="270" height="52" rx="12" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<polygon points="110,164 126,164 104,176" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></polygon>
<line x1="111" y1="164" x2="125" y2="164" stroke="var(--accent-soft)" stroke-width="3"></line>
<text x="116" y="142" font-size="14" fill="var(--text)">던전 보상은 우편함으로 보냈어요</text>
<rect x="116" y="124" width="238" height="28" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 3"></rect>
<circle cx="100" cy="164" r="4" stroke="var(--warn)" stroke-width="2" fill="var(--bg)"></circle>
<text x="94" y="186" font-size="11" fill="var(--text-muted)">피벗 (0, 0)</text>
<line x1="378" y1="138.0" x2="406" y2="138.0" stroke="var(--accent)" stroke-width="2"></line><polygon points="406,133.0 414,138.0 406,143.0" fill="var(--accent)"></polygon>
<text x="460" y="26" font-size="12" fill="var(--text)">말풍선 (Image, 9-slice)</text>
<text x="474" y="46" font-size="12" fill="var(--text-muted)">Horizontal Layout Group</text>
<text x="488" y="66" font-size="12" fill="var(--text-muted)">Padding 16</text>
<text x="488" y="86" font-size="12" fill="var(--text-muted)">Control Child Size 켬</text>
<text x="474" y="106" font-size="12" fill="var(--text-muted)">Content Size Fitter</text>
<text x="488" y="126" font-size="12" fill="var(--text-muted)">가로 세로 Preferred Size</text>
<text x="474" y="146" font-size="12" fill="var(--text-muted)">Layout Element</text>
<text x="488" y="166" font-size="12" fill="var(--text-muted)">Max Width 320</text>
<text x="474" y="186" font-size="12" fill="var(--text)">글자 (TextMeshPro)</text>
</svg>
<figcaption>피벗이 왼쪽 아래라서 오른쪽으로만 넓어집니다. 캐릭터 쪽 꼬리는 제자리입니다.</figcaption>
</figure>
<figure class="diagram" data-tab="Max Width 에 닿으면">
<svg viewBox="0 0 680 210" role="img" aria-label="Max Width 에 닿으면: 말풍선 너비 320, 줄 수 2">
<circle cx="60" cy="178" r="22" fill="var(--bg)" stroke="var(--text-muted)"></circle>
<text x="60" y="182" font-size="11" text-anchor="middle" fill="var(--text-muted)">캐릭터</text>
<line x1="420" y1="20" x2="420" y2="190" stroke="var(--warn)" stroke-dasharray="5 4"></line>
<text x="414" y="200" font-size="11" text-anchor="end" fill="var(--warn)">Max Width 320</text>
<rect x="100" y="88" width="320" height="76" rx="12" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></rect>
<polygon points="110,164 126,164 104,176" fill="var(--accent-soft)" stroke="var(--accent)" stroke-width="1.5"></polygon>
<line x1="111" y1="164" x2="125" y2="164" stroke="var(--accent-soft)" stroke-width="3"></line>
<text x="116" y="118" font-size="14" fill="var(--text)">던전 보상은 우편함으로 보냈어요.</text>
<text x="116" y="140" font-size="14" fill="var(--text)">기한은 7일이니 꼭 받으세요</text>
<rect x="116" y="100" width="288" height="52" fill="none" stroke="var(--text-muted)" stroke-dasharray="3 3"></rect>
<circle cx="100" cy="164" r="4" stroke="var(--warn)" stroke-width="2" fill="var(--bg)"></circle>
<text x="94" y="186" font-size="11" fill="var(--text-muted)">피벗 (0, 0)</text>
<line x1="390" y1="80" x2="390" y2="58" stroke="var(--accent)" stroke-width="2"></line><polygon points="385,58 390,50 395,58" fill="var(--accent)"></polygon>
<text x="460" y="26" font-size="12" fill="var(--text)">말풍선 (Image, 9-slice)</text>
<text x="474" y="46" font-size="12" fill="var(--text-muted)">Horizontal Layout Group</text>
<text x="488" y="66" font-size="12" fill="var(--text-muted)">Padding 16</text>
<text x="488" y="86" font-size="12" fill="var(--text-muted)">Control Child Size 켬</text>
<text x="474" y="106" font-size="12" fill="var(--text-muted)">Content Size Fitter</text>
<text x="488" y="126" font-size="12" fill="var(--text-muted)">가로 세로 Preferred Size</text>
<text x="474" y="146" font-size="12" fill="var(--text-muted)">Layout Element</text>
<text x="488" y="166" font-size="12" fill="var(--text-muted)">Max Width 320</text>
<text x="474" y="186" font-size="12" fill="var(--text)">글자 (TextMeshPro)</text>
</svg>
<figcaption>넓이는 320 에서 멈추고 글이 줄바꿈되며, 이번에는 위로 커집니다.</figcaption>
</figure>
</x-tabs>

- **커지는 방향은 피벗이 정합니다.** 앞에서 본 대로 크기는 피벗을 중심으로 바뀝니다. 말풍선은 꼬리가 캐릭터에 붙어 있어야 하니 피벗을 꼬리 쪽 모서리에 둡니다
- Unity 6.6 부터는 **Preferred Size 가 Layout Element 의 Max Width 를 넘지 않습니다.** 그래서 넓어지다가 최대 폭에서 멈추고 줄바꿈되는 말풍선을 설정만으로 만들 수 있습니다. 같은 버전에 **Clamped** 모드도 생겼는데, 크기를 직접 정하지 않고 Min 과 Max 사이를 벗어나지 않게만 막습니다

**Layout Group 의 자식에는 Content Size Fitter 를 붙이지 않습니다.**
자식 크기는 부모 그룹이 정하는 자리라 둘이 같은 값을 두고 싸우고, Unity 도 경고를 띄웁니다.
("A child of a layout group should not have a Content Size Fitter component, since it should be driven by the layout group.")
자식을 내용에 맞추고 싶으면 **부모 그룹의 Control Child Size 를 켭니다.**

## 시안을 넘길 때 적어 주면 좋은 것

| 적어 줄 것 | 무엇이 정해지나 |
| --- | --- |
| 줄의 **방향, 간격, 안쪽 여백** | Layout Group 종류, Spacing, Padding |
| 요소가 **글에 맞춰 줄어드는지(Hug), 줄을 꽉 채우는지(Fill), 고정 폭인지** | Control Child Size, Child Force Expand, Layout Element |
| 남는 공간이 생기면 **어느 쪽으로 붙는지** | Child Alignment |
| 늘어나는 요소의 **최소, 최대 폭** | Layout Element 의 Min Width, Max Width |
| 글이 길어질 때 **박스가 어느 방향으로 커지는지** | Content Size Fitter, 피벗 |

Figma 에서 Auto Layout 의 Hug, Fill, Fixed 를 정확히 걸어 두면 위 표의 두 번째 줄은 대부분 전달됩니다.

## 정리

- Layout Group 을 붙이면 자식의 위치(와 켜면 크기)를 그룹이 정합니다. 자식의 RectTransform 은 회색으로 잠깁니다
- 자식은 **Min, Preferred, Flexible** 을 알려 주고, 그룹은 이 순서대로 공간을 나눕니다
- **Control Child Size** 는 그룹이 자식 크기까지 정할지, **Child Force Expand** 는 남는 공간을 자식마다 나눠 줄지입니다
- 그룹이 나눠 주는 것은 **칸** 입니다. Control Child Size 가 꺼진 채 Force Expand 만 켜면 칸만 넓어져 버튼 사이가 벌어집니다
- Figma 처럼 자식마다 Hug, Fixed, Fill 을 다르게 하려면 그룹은 Control 켬, Expand 끔으로 두고 자식마다 Layout Element 로 정합니다. Fixed 는 Min 과 Preferred 를 같게, Fill 은 Flexible 1
- 내용에 맞춰 **자기 크기** 를 바꾸는 것은 Content Size Fitter 이고, 커지는 방향은 피벗이 정합니다. Layout Group 의 자식에는 붙이지 않습니다