diff options
author | Sven Gothel <[email protected]> | 2023-12-18 03:53:39 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-12-18 03:53:39 +0100 |
commit | a4fc84cba410e7e7082e8fd097cb0185d0aac1a2 (patch) | |
tree | 1abcf7a5f397214eab76a01d298d1e531a9785cb /src/graphui/classes/com/jogamp | |
parent | cf924e3ff144408ea175c8aeac0819bd1a05467d (diff) |
Bug 805: GraphUI Group: Add 'widget-mode' used to utilize a group as one visible UI widget element (activation, visibility)
Enabled widget behavior for a group causes
- the whole group to be shown on top on (mouse over) activation of one of its elements via getAdjustedZ()
- this group's onActivation(Listener) to handle all it's elements activation events
- isActive() of this group and its sub-groups to return true if one of its elements is active
Diffstat (limited to 'src/graphui/classes/com/jogamp')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Group.java | 57 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 11 |
2 files changed, 66 insertions, 2 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java index 77854b74a..1a05f75b5 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -262,9 +262,64 @@ public class Group extends Shape implements Container { public void setRelayoutOnDirtyShapes(final boolean v) { relayoutOnDirtyShapes = v; } public boolean getRelayoutOnDirtyShapes() { return relayoutOnDirtyShapes; } + private boolean widgetMode = false; + /** + * Toggles widget behavior for this group and all its elements, default is disabled. + * <p> + * Enabled widget behavior for a group causes + * <ul> + * <li>the whole group to be shown on top on (mouse over) activation of one of its elements</li> + * <li>this group's {@link #onActivation(Listener)} to handle all it's elements activation events</li> + * <li>{@link #isActive()} of this group and its sub-groups to return true if one of its elements is active</li> + * </ul> + * </p> + * <p> + * This method modifies all elements of this group for enabled or disabled widget behavior. + * </p> + * @param v enable or disable + * @return this group for chaining + */ + public final Group setWidgetMode(final boolean v) { + widgetMode = v; + if( v ) { + enableUniActivationImpl(true, forwardActivation); + } else { + enableUniActivationImpl(false, null); + } + return this; + } + protected final void enableUniActivationImpl(final boolean v, final Listener activationListener) { + for(final Shape s : shapes ) { + if( s.isGroup() ) { + final Group sg = (Group)s; + sg.setWidgetMode(v); + } + s.onActivation(activationListener); + } + } + + /** Returns whether {@link #setWidgetMode(boolean)} is enabled or disabled. */ + public final boolean getWidgetMode() { return widgetMode; } + @Override public boolean isActive() { - return super.isActive() || forAll((final Shape gs) -> { return gs.isActive(); }); + return super.isActive() || ( widgetMode && forAll((final Shape gs) -> { return gs.isActive(); } ) ); + } + + @Override + public float getAdjustedZ() { + final float[] v = { getAdjustedZImpl() }; + if( widgetMode && !super.isActive() ) { + forAll((final Shape gs) -> { + if( gs.isActive() ) { + v[0] = gs.getAdjustedZImpl(); + return true; + } else { + return false; + } + } ); + } + return v[0]; } @Override diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index d3b4bcbef..bfea0773f 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -1239,7 +1239,7 @@ public abstract class Shape { this.zOffset = zOffset; setIO(IO_ACTIVE, v); if( DEBUG ) { - System.err.println("XXX Activation "+this); + System.err.println("XXX "+(v?" Active":"DeActive")+" "+this); } if( null != onActivationListener ) { onActivationListener.run(this); @@ -1252,6 +1252,15 @@ public abstract class Shape { /** Returns true of this shape is active */ public boolean isActive() { return isIO(IO_ACTIVE); } + protected final Listener forwardActivation = new Listener() { + @Override + public void run(final Shape shape) { + if( null != onActivationListener ) { + onActivationListener.run(shape); + } + } + }; + public float getAdjustedZ() { return getAdjustedZImpl(); } |