-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new Figure Container to serve as light weight drawing container
Using pure Figure just as layout container for other figures is very heavy weight as the graphics state is saved and restored very often. For pure layout containers this would not be necessary. This new figure can help to reduce memory footprint and drawing performance for these cases.
- Loading branch information
Showing
4 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Johannes Kepler University Linz | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Alois Zoitl - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.draw2d; | ||
|
||
/** | ||
* Lightweight Container which just draws the children according to the given | ||
* layout. | ||
* | ||
* This Container does not maintain any graphics state and delegates that to its | ||
* children. This can save memory and increase drawing performance for larger | ||
* graphs with deep nested figures. | ||
* | ||
* A Container can not have any border and does not draw any background. | ||
* | ||
* This class is currently in development its API may | ||
* change: @noreference, @noextend and @noinstantiate | ||
* | ||
* @since 3.16 | ||
*/ | ||
public class Container extends Figure { | ||
|
||
public Container(LayoutManager manager) { | ||
setLayoutManager(manager); | ||
} | ||
|
||
@Override | ||
public final void paint(Graphics graphics) { | ||
getChildren().stream().filter(IFigure::isVisible).forEach(child -> child.paint(graphics)); | ||
} | ||
|
||
@Override | ||
public final void setLayoutManager(LayoutManager manager) { | ||
super.setLayoutManager(manager); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5c1bcd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azoitl
Something I noticed while playing around with this figure:
Because Container overwrites the paint() method, any border that is set to this figure isn't drawn. However, the insets of the border are still taken into consideration when doing the layout. This leads to "ghost" borders where they shouldn't be any.
When using Container (with border):
When using Figure (without border):
Because the Container doesn't support borders, my expectation would've been for both figures to look the same.
5c1bcd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A similar issue shows up for the
setOpaque()
method. Because the background is never painted, those figures are inherently transparent.5c1bcd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ptziegler that are two good points where I agree with you that the
Container
should definitly ignore. Should we create a dedicated issue to collect these items? I guess it makes sense that I review a second time Figure and check what elements should be ignored or forbidden.5c1bcd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azoitl I've created #441