Skip to content

Commit

Permalink
[426] Handle horizontal stack container
Browse files Browse the repository at this point in the history
Before this commit, this kind of container was not correctly handled.

Bug: #426
  • Loading branch information
lredor committed Sep 10, 2024
1 parent f65a8fa commit 01a8883
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,34 @@ public boolean isVerticalRegionContainerCompartment() {
return false;
}

/**
* Return if this GMF node is contained in an horizontal stack layout container.
*/
public boolean isHorizontalRegion() {
return view.eContainer() instanceof View container && new ViewQuery(container).isHorizontalRegionContainerCompartment();
}

/**
* Return if this GMF node have horizontal stack layout.
*/
public boolean isHorizontalRegionContainer() {
return this.view.getElement() instanceof DDiagramElement element //
&& element.getDiagramElementMapping() instanceof ContainerMapping mapping //
&& new ContainerMappingQuery(mapping).isHorizontalStackContainer();
}

/**
* Return if this GMF node is a compartment of a container having horizontal stack layout.
*/
public boolean isHorizontalRegionContainerCompartment() {
if (isFreeFormCompartment()) {
if (view.eContainer() instanceof Node container) {
return new ViewQuery(container).isHorizontalRegionContainer();
}
}
return false;
}

/**
* Return if this GMF node is a compartment of a container having an horizontal or a vertical stack layout.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) {
location.translate(previousChildBounds.preciseX(), previousChildBounds.preciseY() + previousChildBounds.preciseHeight());
}
}
} else if (viewQuery.isHorizontalRegion()) {
if (node.eContainer() instanceof Node container) {
if (container.getChildren().get(0) == node) {
Point parentNodeLocation = getAbsoluteLocation(container, insetsAware);
location.translate(parentNodeLocation);
if (insetsAware) {
translateWithInsets(location, node);
}
} else {
// Translate from the previous children
Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true);
location.translate(previousChildBounds.preciseX() + previousChildBounds.preciseWidth(), previousChildBounds.preciseY());
}
}
} else if (node.eContainer() instanceof Node container) {
Point parentNodeLocation = getAbsoluteLocation(container, insetsAware);
location.translate(parentNodeLocation);
Expand Down Expand Up @@ -363,6 +377,7 @@ private static Dimension getBottomRightInsets(Node container) {
result.setWidth(result.width() + borderSize.width());
result.setHeight(result.height() + borderSize.height());
} else if (new DDiagramElementContainerExperimentalQuery(ddec).isRegion()) {
// No margin, except the border size
Dimension borderSize = getBorderSize(ddec);
result.setWidth(result.width() + borderSize.width());
result.setHeight(result.height() + borderSize.height());
Expand Down Expand Up @@ -859,7 +874,7 @@ private static void replaceAutoSize(Node node, PrecisionRectangle bounds, boolea
if (nodeQuery.isFreeFormCompartment() || nodeQuery.isListCompartment()) {
defaultSize = new Dimension(ResizableCompartmentFigure.MIN_CLIENT_DP, ResizableCompartmentFigure.MIN_CLIENT_DP);
if (node.getChildren().isEmpty()) {
if (nodeQuery.isListCompartment() || nodeQuery.isVerticalRegionContainerCompartment()) {
if (nodeQuery.isListCompartment() || nodeQuery.isVerticalRegionContainerCompartment() || nodeQuery.isHorizontalRegionContainerCompartment()) {
// Add one margin border (even if empty)
defaultSize.expand(0, 1);
}
Expand Down

0 comments on commit 01a8883

Please sign in to comment.