Finished new End-Settings for WorldEdit Screen
This commit is contained in:
parent
7546efe097
commit
cb1986a1fa
12 changed files with 106 additions and 67 deletions
|
@ -2,7 +2,6 @@ package org.betterx.ui.layout.components;
|
|||
|
||||
import org.betterx.ui.layout.components.input.RelativeContainerEventHandler;
|
||||
import org.betterx.ui.layout.components.render.ComponentRenderer;
|
||||
import org.betterx.ui.layout.components.render.NullRenderer;
|
||||
import org.betterx.ui.layout.values.Rectangle;
|
||||
import org.betterx.ui.layout.values.Size;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
|
@ -152,16 +151,16 @@ public abstract class AbstractStack<R extends ComponentRenderer, T extends Abstr
|
|||
return b;
|
||||
}
|
||||
|
||||
protected VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
|
||||
protected VerticalScroll<VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
|
||||
return addScrollable(Value.fill(), Value.fill(), content);
|
||||
}
|
||||
|
||||
protected VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
|
||||
protected VerticalScroll<VanillaScrollerRenderer> addScrollable(
|
||||
Value width,
|
||||
Value height,
|
||||
LayoutComponent<?, ?> content
|
||||
) {
|
||||
VerticalScroll<NullRenderer, VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content);
|
||||
VerticalScroll<VanillaScrollerRenderer> s = VerticalScroll.create(width, height, content);
|
||||
add(s);
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
|
|||
GuiEventListener focused = null;
|
||||
boolean visible = true;
|
||||
|
||||
int padding = 0;
|
||||
int paddingLeft, paddingTop, paddingRight, paddingBottom;
|
||||
|
||||
int backgroundColor = 0;
|
||||
int outlineColor = 0;
|
||||
|
@ -93,22 +93,29 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
|
|||
}
|
||||
|
||||
public Container setPadding(int padding) {
|
||||
this.padding = padding;
|
||||
return this;
|
||||
return setPadding(padding, padding, padding, padding);
|
||||
}
|
||||
|
||||
public int getPadding() {
|
||||
return padding;
|
||||
public Container setPadding(int left, int top, int right, int bottom) {
|
||||
this.paddingLeft = left;
|
||||
this.paddingTop = top;
|
||||
this.paddingRight = right;
|
||||
this.paddingBottom = bottom;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentWidth() {
|
||||
return children.stream().map(LayoutComponent::getContentWidth).reduce(0, Math::max) + 2 * padding;
|
||||
return children.stream()
|
||||
.map(LayoutComponent::getContentWidth)
|
||||
.reduce(0, Math::max) + paddingLeft + paddingRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentHeight() {
|
||||
return children.stream().map(LayoutComponent::getContentHeight).reduce(0, Math::max) + 2 * padding;
|
||||
return children.stream()
|
||||
.map(LayoutComponent::getContentHeight)
|
||||
.reduce(0, Math::max) + paddingTop + paddingBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,7 +153,7 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
|
|||
protected int updateContainerWidth(int containerWidth) {
|
||||
int myWidth = width.calculateOrFill(containerWidth);
|
||||
for (var child : children) {
|
||||
child.width.calculateOrFill(myWidth - 2 * padding);
|
||||
child.width.calculateOrFill(myWidth - (paddingLeft + paddingRight));
|
||||
child.updateContainerWidth(child.width.calculatedSize());
|
||||
}
|
||||
return myWidth;
|
||||
|
@ -156,7 +163,7 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
|
|||
protected int updateContainerHeight(int containerHeight) {
|
||||
int myHeight = height.calculateOrFill(containerHeight);
|
||||
for (var child : children) {
|
||||
child.height.calculateOrFill(myHeight - 2 * padding);
|
||||
child.height.calculateOrFill(myHeight - (paddingTop + paddingBottom));
|
||||
child.updateContainerHeight(child.height.calculatedSize());
|
||||
}
|
||||
return myHeight;
|
||||
|
@ -190,15 +197,15 @@ public class Container extends LayoutComponent<Container.ContainerRenderer, Cont
|
|||
super.setRelativeBounds(left, top);
|
||||
|
||||
for (var child : children) {
|
||||
int childLeft = (relativeBounds.width - 2 * padding) - child.width.calculatedSize();
|
||||
int childLeft = (relativeBounds.width - (paddingLeft + paddingRight)) - child.width.calculatedSize();
|
||||
if (child.hAlign == Alignment.MIN) childLeft = 0;
|
||||
else if (child.hAlign == Alignment.CENTER) childLeft /= 2;
|
||||
|
||||
int childTop = (relativeBounds.height - 2 * padding) - child.height.calculatedSize();
|
||||
int childTop = (relativeBounds.height - (paddingTop + paddingBottom)) - child.height.calculatedSize();
|
||||
if (child.vAlign == Alignment.MIN) childTop = 0;
|
||||
else if (child.vAlign == Alignment.CENTER) childTop /= 2;
|
||||
|
||||
child.setRelativeBounds(padding + childLeft, padding + childTop);
|
||||
child.setRelativeBounds(paddingLeft + childLeft, paddingTop + childTop);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
import org.betterx.ui.layout.components.render.NullRenderer;
|
||||
import org.betterx.ui.layout.values.Size;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
import org.betterx.ui.vanilla.VanillaScrollerRenderer;
|
||||
|
@ -170,7 +169,7 @@ public class HorizontalStack extends AbstractHorizontalStack<HorizontalStack> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
|
||||
public VerticalScroll<VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
|
||||
return super.addScrollable(content);
|
||||
}
|
||||
|
||||
|
@ -190,7 +189,7 @@ public class HorizontalStack extends AbstractHorizontalStack<HorizontalStack> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
|
||||
public VerticalScroll<VanillaScrollerRenderer> addScrollable(
|
||||
Value width,
|
||||
Value height,
|
||||
LayoutComponent<?, ?> content
|
||||
|
|
|
@ -68,6 +68,10 @@ public class Range<N extends Number> extends AbstractVanillaComponent<Slider<N>,
|
|||
);
|
||||
}
|
||||
|
||||
public N getValue() {
|
||||
return vanillaComponent.currentValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Component contentComponent() {
|
||||
|
|
|
@ -79,8 +79,9 @@ public class Tabs extends AbstractVerticalStack<Tabs> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public int getPadding() {
|
||||
return content.getPadding();
|
||||
public Tabs setPadding(int left, int top, int right, int bottom) {
|
||||
content.setPadding(left, top, right, bottom);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
import org.betterx.ui.layout.components.render.ComponentRenderer;
|
||||
import org.betterx.ui.layout.components.render.NullRenderer;
|
||||
import org.betterx.ui.layout.components.render.ScrollerRenderer;
|
||||
import org.betterx.ui.layout.values.Alignment;
|
||||
|
@ -19,10 +18,9 @@ import java.util.List;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRenderer> extends LayoutComponent<R, VerticalScroll<R, RS>> implements ContainerEventHandler {
|
||||
public class VerticalScroll<RS extends ScrollerRenderer> extends LayoutComponent<NullRenderer, VerticalScroll<RS>> implements ContainerEventHandler {
|
||||
protected LayoutComponent<?, ?> child;
|
||||
protected final RS scrollerRenderer;
|
||||
protected Rectangle viewBounds;
|
||||
|
||||
protected int dist;
|
||||
protected double scrollerY;
|
||||
|
@ -30,29 +28,26 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
|||
protected int travel;
|
||||
protected int topOffset;
|
||||
|
||||
public VerticalScroll(Value width, Value height, RS scrollerRenderer) {
|
||||
this(width, height, scrollerRenderer, null);
|
||||
}
|
||||
protected boolean keepSpaceForScrollbar = true;
|
||||
|
||||
public VerticalScroll(Value width, Value height, RS scrollerRenderer, R renderer) {
|
||||
super(width, height, renderer);
|
||||
public VerticalScroll(Value width, Value height, RS scrollerRenderer) {
|
||||
super(width, height, new NullRenderer());
|
||||
this.scrollerRenderer = scrollerRenderer;
|
||||
}
|
||||
|
||||
public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
|
||||
public static VerticalScroll<VanillaScrollerRenderer> create(LayoutComponent<?, ?> c) {
|
||||
return create(Value.relative(1), Value.relative(1), c);
|
||||
}
|
||||
|
||||
public static VerticalScroll<NullRenderer, VanillaScrollerRenderer> create(
|
||||
public static VerticalScroll<VanillaScrollerRenderer> create(
|
||||
Value width,
|
||||
Value height,
|
||||
LayoutComponent<?, ?> c
|
||||
) {
|
||||
VerticalScroll<NullRenderer, VanillaScrollerRenderer> res = new VerticalScroll<>(
|
||||
VerticalScroll<VanillaScrollerRenderer> res = new VerticalScroll<>(
|
||||
width,
|
||||
height,
|
||||
VanillaScrollerRenderer.DEFAULT,
|
||||
null
|
||||
VanillaScrollerRenderer.DEFAULT
|
||||
);
|
||||
res.setChild(c);
|
||||
return res;
|
||||
|
@ -60,9 +55,15 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
|||
|
||||
List<LayoutComponent<?, ?>> children = List.of();
|
||||
|
||||
public void setChild(LayoutComponent<?, ?> c) {
|
||||
public VerticalScroll<RS> setChild(LayoutComponent<?, ?> c) {
|
||||
this.child = c;
|
||||
children = List.of(child);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerticalScroll<RS> setKeepSpaceForScrollbar(boolean value) {
|
||||
keepSpaceForScrollbar = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +108,7 @@ public class VerticalScroll<R extends ComponentRenderer, RS extends ScrollerRend
|
|||
|
||||
if (child != null) {
|
||||
int width = relativeBounds.width;
|
||||
boolean willNeedScrollBar = child.height.calculatedSize() > relativeBounds.height;
|
||||
boolean willNeedScrollBar = keepSpaceForScrollbar || child.height.calculatedSize() > relativeBounds.height;
|
||||
if (willNeedScrollBar) width -= scrollerWidth();
|
||||
int childLeft = width - child.width.calculatedSize();
|
||||
if (child.hAlign == Alignment.MIN) childLeft = 0;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.betterx.ui.layout.components;
|
||||
|
||||
|
||||
import org.betterx.ui.layout.components.render.NullRenderer;
|
||||
import org.betterx.ui.layout.values.Size;
|
||||
import org.betterx.ui.layout.values.Value;
|
||||
import org.betterx.ui.vanilla.VanillaScrollerRenderer;
|
||||
|
@ -182,7 +181,7 @@ public class VerticalStack extends AbstractVerticalStack<VerticalStack> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
|
||||
public VerticalScroll<VanillaScrollerRenderer> addScrollable(LayoutComponent<?, ?> content) {
|
||||
return super.addScrollable(content);
|
||||
}
|
||||
|
||||
|
@ -202,7 +201,7 @@ public class VerticalStack extends AbstractVerticalStack<VerticalStack> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VerticalScroll<NullRenderer, VanillaScrollerRenderer> addScrollable(
|
||||
public VerticalScroll<VanillaScrollerRenderer> addScrollable(
|
||||
Value width,
|
||||
Value height,
|
||||
LayoutComponent<?, ?> content
|
||||
|
|
|
@ -56,7 +56,7 @@ public class Slider<N extends Number> extends AbstractSliderButton {
|
|||
this.updateMessage();
|
||||
}
|
||||
|
||||
protected N currentValue() {
|
||||
public N currentValue() {
|
||||
Double res = value * (maxValue.doubleValue() - minValue.doubleValue()) + minValue.doubleValue();
|
||||
if (minValue instanceof Integer) {
|
||||
return (N) (Integer) res.intValue();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue