Skip to content

Commit aeae8c5

Browse files
committed
feat: support boxSizing
1 parent d49e697 commit aeae8c5

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Sources/Swift/FlexLayout.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,20 @@ public final class Flex {
13281328
yoga.display = value.yogaValue
13291329
return self
13301330
}
1331-
1331+
1332+
//
1333+
// MARK: Box Sizing
1334+
//
1335+
1336+
/**
1337+
Set the box sizing
1338+
*/
1339+
@discardableResult
1340+
public func boxSizing(_ value: BoxSizing) -> Flex {
1341+
yoga.boxSizing = value.yogaValue
1342+
return self
1343+
}
1344+
13321345
// MARK: Enums
13331346

13341347
/**
@@ -1471,7 +1484,17 @@ public final class Flex {
14711484
/// without influencing the layout of child nodes.
14721485
case contents
14731486
}
1474-
1487+
1488+
public enum BoxSizing {
1489+
/// Default value.
1490+
/// With `borderBox`, the specified dimensions (e.g., width, height) include the content, padding, and border.
1491+
/// This means the overall size of the element is as defined, with padding and border accounted for inside.
1492+
case borderBox
1493+
/// With `contentBox`, the specified dimensions refer only to the content area.
1494+
/// Padding and borders are added outside these dimensions, potentially increasing the total size of the element.
1495+
case contentBox
1496+
}
1497+
14751498
/*public enum Overflow {
14761499
/// Items that overflow
14771500
case visible

Sources/Swift/Impl/FlexLayout+Enum.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ extension Flex.Display {
119119
}
120120
}
121121

122+
extension Flex.BoxSizing {
123+
var yogaValue: YGBoxSizing {
124+
switch self {
125+
case .borderBox: return YGBoxSizing.borderBox
126+
case .contentBox: return YGBoxSizing.contentBox
127+
}
128+
}
129+
}
130+
122131
/*extension Flex.Overflow {
123132
var yogaValue: YGOverflow {
124133
switch self {

Sources/YogaKit/YGLayout.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ - (void)setPosition:(YGPositionType)position {
273273
YG_PROPERTY(YGWrap, flexWrap, FlexWrap)
274274
YG_PROPERTY(YGOverflow, overflow, Overflow)
275275
YG_PROPERTY(YGDisplay, display, Display)
276+
YG_PROPERTY(YGBoxSizing, boxSizing, BoxSizing)
276277

277278
YG_PROPERTY(CGFloat, flex, Flex)
278279
YG_PROPERTY(CGFloat, flexGrow, FlexGrow)

Sources/YogaKit/include/YogaKit/YGLayout.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
6464
@property(nonatomic, readwrite, assign) YGWrap flexWrap;
6565
@property(nonatomic, readwrite, assign) YGOverflow overflow;
6666
@property(nonatomic, readwrite, assign) YGDisplay display;
67+
@property(nonatomic, readwrite, assign) YGBoxSizing boxSizing;
6768

6869
@property(nonatomic, readwrite, assign) CGFloat flex;
6970
@property(nonatomic, readwrite, assign) CGFloat flexGrow;

0 commit comments

Comments
 (0)