diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java index 1bb697ff48..2725424a6d 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java @@ -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. */ diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java index 66ab86b390..3d52accd6e 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java @@ -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); @@ -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()); @@ -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); }