@@ -0,0 +1,2677 @@
+/*%0A * Copyright 2021 The Terasology Foundation%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.destinationsol.ui.nui.widgets;%0A%0Aimport org.joml.Vector2i;%0Aimport org.terasology.nui.AbstractWidget;%0Aimport org.terasology.nui.Canvas;%0Aimport org.terasology.nui.LayoutConfig;%0Aimport org.terasology.nui.UIWidget;%0A%0Aimport java.util.Collections;%0Aimport java.util.Iterator;%0A%0A/**%0A * A container which returns a zero size if it, or its content, is invisible. Otherwise, this element should act%0A * completely transparently.%0A * This can be an alternative to adding and/or removing elements dynamically.%0A */%0Apublic class EmptyIfInvisibleContainer extends AbstractWidget %7B%0A    @LayoutConfig%0A    private UIWidget content;%0A%0A    public EmptyIfInvisibleContainer(String id) %7B%0A        setId(id);%0A    %7D%0A%0A    public EmptyIfInvisibleContainer(UIWidget content) %7B%0A        this.content = content;%0A    %7D%0A%0A    public EmptyIfInvisibleContainer(String id, UIWidget content) %7B%0A        setId(id);%0A        this.content = content;%0A    %7D%0A%0A    public void setContent(UIWidget content) %7B%0A        this.content = content;%0A    %7D%0A%0A    @Override%0A    public void onDraw(Canvas canvas) %7B%0A        if (content != null) %7B%0A            content.onDraw(canvas);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) %7B%0A        if (!this.isVisible() %7C%7C content == null %7C%7C !content.isVisible()) %7B%0A            return new Vector2i();%0A        %7D%0A%0A        return canvas.calculateRestrictedSize(content, sizeHint);%0A    %7D%0A%0A    @Override%0A    public Vector2i getMaxContentSize(Canvas canvas) %7B%0A        if (!this.isVisible() %7C%7C content == null %7C%7C !content.isVisible()) %7B%0A            return new Vector2i();%0A        %7D%0A%0A        return canvas.calculateMaximumSize(content);%0A    %7D%0A%0A    @Override%0A    public Iterator%3CUIWidget%3E iterator() %7B%0A        if (content != null) %7B%0A            return Collections.singletonList(content).iterator();%0A        %7D%0A%0A        return Collections.emptyIterator();%0A    %7D%0A%0A    @Override%0A    public boolean isSkinAppliedByCanvas() %7B%0A        return false;%0A    %7D%0A%0A    @Override%0A    public boolean canBeFocus() %7B%0A        return false;%0A    %7D%0A%7D%0A

add new EmptyIfInvisibleContainer widget