|
5 | 5 | import com.github.webicitybrowser.thready.dimensions.Rectangle; |
6 | 6 | import com.github.webicitybrowser.thready.dimensions.RelativeDimension; |
7 | 7 | import com.github.webicitybrowser.thready.dimensions.util.AbsoluteDimensionsMath; |
| 8 | +import com.github.webicitybrowser.thready.gui.directive.core.pool.DirectivePool; |
8 | 9 | import com.github.webicitybrowser.thready.gui.graphical.layout.core.ChildLayoutResult; |
9 | 10 | import com.github.webicitybrowser.thready.gui.graphical.layout.core.LayoutRenderContext; |
10 | 11 | import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.box.Box; |
11 | 12 | import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.render.LocalRenderContext; |
12 | 13 | import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.render.unit.ContextSwitch; |
13 | 14 | import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.render.unit.RenderedUnit; |
| 15 | +import com.github.webicitybrowser.threadyweb.graphical.layout.adjusted.position.PositionOffsetCalculations; |
14 | 16 | import com.github.webicitybrowser.threadyweb.graphical.layout.adjusted.position.PositionOffsetUtil; |
15 | 17 | import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockChildRenderResult; |
16 | 18 | import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockPrerenderSizingInfo; |
17 | 19 | import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockUnitRenderer; |
18 | 20 | import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockUnitRenderingContext; |
19 | 21 | import com.github.webicitybrowser.threadyweb.graphical.layout.util.BoxOffsetDimensions; |
| 22 | +import com.github.webicitybrowser.threadyweb.graphical.layout.util.LayoutMarginCalculations; |
20 | 23 | import com.github.webicitybrowser.threadyweb.graphical.layout.util.LayoutSizeUtils; |
21 | 24 | import com.github.webicitybrowser.threadyweb.graphical.lookandfeel.weblaf.stage.render.unit.StyledUnitContext; |
22 | 25 | import com.github.webicitybrowser.threadyweb.graphical.lookandfeel.weblaf.stage.render.unit.StyledUnitGenerator; |
@@ -62,39 +65,62 @@ public static ChildLayoutResult renderAdjustedBox(Box box, LayoutRenderContext l |
62 | 65 | } |
63 | 66 |
|
64 | 67 | private static ChildLayoutResult renderFixedBox(Box childBox, LayoutRenderContext layoutRenderContext, StyledUnitGenerator styledUnitGenerator) { |
65 | | - BoxOffsetDimensions boxDimensions = BoxOffsetDimensions.create(layoutRenderContext, childBox.styleDirectives()); |
| 68 | + DirectivePool styleDirectives = childBox.styleDirectives(); |
| 69 | + SizeCalculationContext sizeCalculationContext = LayoutSizeUtils.createSizeCalculationContext(layoutRenderContext, styleDirectives); |
| 70 | + float[] positions = PositionOffsetCalculations.calculateOffset(sizeCalculationContext, styleDirectives); |
| 71 | + |
| 72 | + BoxOffsetDimensions boxDimensions = BoxOffsetDimensions.create(layoutRenderContext, styleDirectives); |
66 | 73 | AbsoluteSize viewportSize = layoutRenderContext.globalRenderContext().viewportSize(); |
67 | 74 | FlowBlockUnitRenderingContext context = new FlowBlockUnitRenderingContext( |
68 | 75 | childBox, boxDimensions, |
69 | 76 | childSize -> new LocalRenderContext(childSize, new ContextSwitch[0]), |
70 | | - childSize -> computeFallbackPreferredSize(viewportSize, childSize, boxDimensions.margins())); |
| 77 | + childSize -> computeFallbackPreferredSize(viewportSize, childSize, boxDimensions.margins(), positions)); |
71 | 78 |
|
72 | | - FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context); |
| 79 | + FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context, true); |
73 | 80 | FlowBlockChildRenderResult childRenderResult = FlowBlockUnitRenderer.generateChildUnit( |
74 | 81 | context, prerenderSizingInfo, layoutRenderContext.globalRenderContext()); |
75 | 82 |
|
76 | 83 | AbsoluteSize finalChildSize = LayoutSizeUtils.addPadding(childRenderResult.adjustedSize(), boxDimensions.totalPadding()); |
77 | 84 | AbsolutePosition fixedPosition = PositionOffsetUtil.getFixedPositionOffset( |
78 | 85 | prerenderSizingInfo.sizingContext().sizeCalculationContext(), |
79 | | - childBox.styleDirectives(), finalChildSize); |
| 86 | + styleDirectives, finalChildSize); |
80 | 87 | Rectangle fixedRect = new Rectangle(fixedPosition, finalChildSize); |
81 | 88 |
|
82 | 89 | RenderedUnit styledUnit = styledUnitGenerator.generateStyledUnit( |
83 | | - new StyledUnitContext(childBox.styleDirectives(), childRenderResult.unit(), finalChildSize, boxDimensions) |
| 90 | + new StyledUnitContext(styleDirectives, childRenderResult.unit(), finalChildSize, boxDimensions) |
84 | 91 | ); |
85 | 92 | AdjustedUnit adjustedUnit = new AdjustedUnit(styledUnit, fixedRect); |
86 | 93 |
|
87 | 94 | return new ChildLayoutResult(adjustedUnit, new Rectangle(new AbsolutePosition(0, 0), AbsoluteSize.ZERO_SIZE)); |
88 | 95 | } |
89 | 96 |
|
90 | | - private static AbsoluteSize computeFallbackPreferredSize(AbsoluteSize parentSize, AbsoluteSize preferredSize, float[] margins) { |
91 | | - float marginOffset = Math.max(0, margins[0]) + Math.max(0, margins[1]); |
| 97 | + private static AbsoluteSize computeFallbackPreferredSize(AbsoluteSize parentSize, AbsoluteSize preferredSize, float[] positions, float[] margins) { |
| 98 | + margins = LayoutMarginCalculations.zeroAutoMargins(margins); |
| 99 | + |
| 100 | + float marginOffsetX = Math.max(0, margins[0]) + Math.max(0, margins[1]); |
92 | 101 | float actualPreferredWidth = preferredSize.width() != RelativeDimension.UNBOUNDED ? |
93 | 102 | preferredSize.width() : |
94 | 103 | parentSize.width() == RelativeDimension.UNBOUNDED ? |
95 | 104 | RelativeDimension.UNBOUNDED : |
96 | | - Math.max(0, parentSize.width() - marginOffset); |
| 105 | + Math.max(0, parentSize.width() - marginOffsetX); |
| 106 | + if ( |
| 107 | + actualPreferredWidth == RelativeDimension.UNBOUNDED |
| 108 | + && positions[0] != RelativeDimension.UNBOUNDED |
| 109 | + && positions[1] != RelativeDimension.UNBOUNDED |
| 110 | + ) { |
| 111 | + actualPreferredWidth = Math.max(0, parentSize.width() - positions[0] - positions[1] - marginOffsetX); |
| 112 | + } |
| 113 | + |
97 | 114 | float actualPreferredHeight = preferredSize.height(); |
| 115 | + if ( |
| 116 | + actualPreferredHeight == RelativeDimension.UNBOUNDED |
| 117 | + && positions[2] != RelativeDimension.UNBOUNDED |
| 118 | + && positions[3] != RelativeDimension.UNBOUNDED |
| 119 | + ) { |
| 120 | + float marginOffsetY = Math.max(0, margins[2]) + Math.max(0, margins[3]); |
| 121 | + actualPreferredHeight = Math.max(0, parentSize.height() - positions[2] - positions[3] - marginOffsetY); |
| 122 | + } |
| 123 | + |
98 | 124 |
|
99 | 125 | return new AbsoluteSize(actualPreferredWidth, actualPreferredHeight); |
100 | 126 | } |
|
0 commit comments