This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new a5487151ef Toolbar does not expand to new line but widgets do, fixes  
#7468 (#7469)
a5487151ef is described below

commit a5487151ef6f96e12ffb425aa523f5291726781a
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Thu Jul 9 12:43:49 2026 +0200

    Toolbar does not expand to new line but widgets do, fixes  #7468 (#7469)
---
 .../hop/ui/hopgui/ToolBarToolbarContainer.java     | 35 ++++++++++++++++++++++
 .../apache/hop/ui/core/gui/IToolbarContainer.java  | 11 +++++++
 .../hopgui/file/pipeline/HopGuiPipelineGraph.java  |  8 +++--
 .../hopgui/file/workflow/HopGuiWorkflowGraph.java  |  4 +++
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git 
a/rcp/src/main/java/org/apache/hop/ui/hopgui/ToolBarToolbarContainer.java 
b/rcp/src/main/java/org/apache/hop/ui/hopgui/ToolBarToolbarContainer.java
index 4d536af919..0b8b5841a1 100644
--- a/rcp/src/main/java/org/apache/hop/ui/hopgui/ToolBarToolbarContainer.java
+++ b/rcp/src/main/java/org/apache/hop/ui/hopgui/ToolBarToolbarContainer.java
@@ -20,8 +20,13 @@ package org.apache.hop.ui.hopgui;
 import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarItem;
 import org.apache.hop.ui.core.gui.IToolbarContainer;
 import org.apache.hop.ui.core.gui.IToolbarWidgetRegistrar;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
 
 /** Desktop (RCP) toolbar container: wraps an SWT ToolBar. */
 public class ToolBarToolbarContainer implements IToolbarContainer {
@@ -41,4 +46,34 @@ public class ToolBarToolbarContainer implements 
IToolbarContainer {
   public void addItem(GuiToolbarItem item, IToolbarWidgetRegistrar registrar) {
     registrar.addItem(item, toolBar);
   }
+
+  @Override
+  public void enableWrapAutoHeight() {
+    // A SWT.WRAP toolbar wraps its items to extra rows when it is too narrow, 
but it does not
+    // grow its own allocated height to match. On every resize we measure the 
real extent of the
+    // (wrapped) items and feed it back into the FormData height so the layout 
gives the toolbar
+    // enough room and pushes the content below it down.
+    toolBar.addListener(SWT.Resize, event -> adjustWrappedHeight());
+  }
+
+  private void adjustWrappedHeight() {
+    if (toolBar.isDisposed() || !(toolBar.getLayoutData() instanceof FormData 
formData)) {
+      return;
+    }
+    int contentHeight = 0;
+    for (ToolItem item : toolBar.getItems()) {
+      Rectangle bounds = item.getBounds();
+      contentHeight = Math.max(contentHeight, bounds.y + bounds.height);
+    }
+    // Nothing to measure yet, or the height already matches: avoid a 
redundant re-layout (which
+    // would otherwise loop, since re-laying out fires another Resize event).
+    if (contentHeight <= 0 || formData.height == contentHeight) {
+      return;
+    }
+    formData.height = contentHeight;
+    Composite parent = toolBar.getParent();
+    if (parent != null && !parent.isDisposed()) {
+      parent.layout(true);
+    }
+  }
 }
diff --git a/ui/src/main/java/org/apache/hop/ui/core/gui/IToolbarContainer.java 
b/ui/src/main/java/org/apache/hop/ui/core/gui/IToolbarContainer.java
index ca74718179..b95e761d3d 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/gui/IToolbarContainer.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/gui/IToolbarContainer.java
@@ -35,4 +35,15 @@ public interface IToolbarContainer {
    * the appropriate widgets and registers them via the registrar.
    */
   void addItem(GuiToolbarItem item, IToolbarWidgetRegistrar registrar);
+
+  /**
+   * Desktop only: make the toolbar report its true (possibly wrapped, 
multi-row) height to its
+   * parent layout. When items wrap to a second line the toolbar then grows 
and the content below it
+   * is pushed down, instead of the extra rows overlapping the canvas or being 
hidden. This requires
+   * the toolbar control to use a {@link org.eclipse.swt.layout.FormData} 
layout. No-op for the web
+   * (RAP) container, whose RowLayout already self-sizes when it wraps.
+   */
+  default void enableWrapAutoHeight() {
+    // No-op by default; only the desktop SWT ToolBar needs explicit 
wrap-aware height handling.
+  }
 }
diff --git 
a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
 
b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
index 09f1ab2072..ca99166ca4 100644
--- 
a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
+++ 
b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
@@ -504,8 +504,9 @@ public class HopGuiPipelineGraph extends HopGuiAbstractGraph
     mainComposite.setLayout(new FormLayout());
     FormData fdMainComposite = new FormData();
     fdMainComposite.left = new FormAttachment(0, 0);
-    fdMainComposite.top =
-        new FormAttachment(0, toolBar.getBounds().height); // Position below 
toolbar
+    // Position below the toolbar, following its control so it moves down when 
the toolbar wraps to
+    // a second row rather than using a height captured once at construction 
time.
+    fdMainComposite.top = new FormAttachment(toolBar, 0);
     fdMainComposite.right = new FormAttachment(100, 0);
     fdMainComposite.bottom = new FormAttachment(100, 0);
     mainComposite.setLayoutData(fdMainComposite);
@@ -2425,6 +2426,9 @@ public class HopGuiPipelineGraph extends 
HopGuiAbstractGraph
       layoutData.right = new FormAttachment(100, 0);
       toolBar.setLayoutData(layoutData);
       toolBar.pack();
+      // Let the toolbar grow its height when its items wrap to a second row 
so they don't overlap
+      // the canvas below it.
+      toolBarContainer.enableWrapAutoHeight();
       PropsUi.setLook(toolBar, Props.WIDGET_STYLE_TOOLBAR);
 
       // enable / disable the icons in the toolbar too.
diff --git 
a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java
 
b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java
index 66dd39a54c..57afa40cc3 100644
--- 
a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java
+++ 
b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java
@@ -417,6 +417,7 @@ public class HopGuiWorkflowGraph extends HopGuiAbstractGraph
 
     FormData toolbarFd = new FormData();
     toolbarFd.left = new FormAttachment(0, 0);
+    toolbarFd.top = new FormAttachment(0, 0);
     toolbarFd.right = new FormAttachment(100, 0);
     toolBar.setLayoutData(toolbarFd);
 
@@ -1931,6 +1932,9 @@ public class HopGuiWorkflowGraph extends 
HopGuiAbstractGraph
       layoutData.right = new FormAttachment(100, 0);
       toolBar.setLayoutData(layoutData);
       toolBar.pack();
+      // Let the toolbar grow its height when its items wrap to a second row 
so they don't overlap
+      // the canvas below it.
+      toolBarContainer.enableWrapAutoHeight();
       PropsUi.setLook(toolBar, Props.WIDGET_STYLE_TOOLBAR);
 
       // enable / disable the icons in the toolbar too.

Reply via email to