Skip to content

Commit

Permalink
let me spin
Browse files Browse the repository at this point in the history
  • Loading branch information
chyzman committed Oct 20, 2024
1 parent 0fc720f commit f605e4e
Showing 1 changed file with 9 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ protected CollapsibleContainer(Sizing horizontalSizing, Sizing verticalSizing, T
title = title.copy().formatted(Formatting.UNDERLINE);
this.titleLayout.child(Components.label(title).cursorStyle(CursorStyle.HAND));

this.spinnyBoi = new SpinnyBoiComponent(expanded);
this.spinnyBoi = new SpinnyBoiComponent();
this.titleLayout.child(spinnyBoi);

this.expanded = expanded;
this.spinnyBoi.targetRotation = expanded ? 90 : 0;
this.spinnyBoi.rotation = this.spinnyBoi.targetRotation;

super.child(this.titleLayout);

Expand Down Expand Up @@ -86,10 +88,10 @@ public EventSource<OnToggled> onToggled() {
public void toggleExpansion() {
if (expanded) {
this.contentLayout.clearChildren();
this.spinnyBoi.expanded(false);
this.spinnyBoi.targetRotation = 0;
} else {
this.contentLayout.children(this.collapsibleChildren);
this.spinnyBoi.expanded(true);
this.spinnyBoi.targetRotation = 90;
}

this.expanded = !this.expanded;
Expand Down Expand Up @@ -183,72 +185,19 @@ static EventStream<OnToggled> newStream() {

public static class SpinnyBoiComponent extends LabelComponent {

protected boolean expanded;
public float rotation = 90;
public float targetRotation = 90;

protected float baseRotation;
protected float expandedRotation;

protected float rotation;

public SpinnyBoiComponent(boolean expanded, float baseRotation, float expandedRotation) {
public SpinnyBoiComponent() {
super(Text.literal(">"));

this.expanded = expanded;
this.baseRotation = baseRotation;
this.expandedRotation = expandedRotation;
this.rotation = expanded ? expandedRotation : baseRotation;

this.margins(Insets.of(0, 0, 5, 10));
this.cursorStyle(CursorStyle.HAND);
}

public SpinnyBoiComponent(boolean expanded) {
this(expanded, 0, 90);
}

public SpinnyBoiComponent() {
this(false);
}

public void toggle() {
this.expanded = !this.expanded;
}

public boolean expanded() {
return this.expanded;
}

public SpinnyBoiComponent expanded(boolean expanded) {
this.expanded = expanded;
return this;
}

public float targetRotation() {
return this.expanded ? this.expandedRotation : this.baseRotation;
}

public float baseRotation() {
return this.baseRotation;
}

public SpinnyBoiComponent baseRotation(float baseRotation) {
this.baseRotation = baseRotation;
return this;
}

public float expandedRotation() {
return this.expandedRotation;
}

public SpinnyBoiComponent expandedRotation(float expandedRotation) {
this.expandedRotation = expandedRotation;
return this;
}

@Override
public void update(float delta, int mouseX, int mouseY) {
super.update(delta, mouseX, mouseY);
this.rotation += Delta.compute(this.rotation, this.targetRotation(), delta * .65f);
this.rotation += Delta.compute(this.rotation, this.targetRotation, delta * .65);
}

@Override
Expand Down

0 comments on commit f605e4e

Please sign in to comment.