generated from QuiltMC/quilt-template-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix relative alignment not updating when the window's size changes
- Loading branch information
Showing
4 changed files
with
38 additions
and
29 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
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
14 changes: 10 additions & 4 deletions
14
...heart/src/main/java/net/pixaurora/kitten_cube/impl/ui/screen/align/RelativeAlignment.java
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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
package net.pixaurora.kitten_cube.impl.ui.screen.align; | ||
|
||
import java.util.function.Function; | ||
|
||
import net.pixaurora.kitten_cube.impl.math.Point; | ||
import net.pixaurora.kitten_cube.impl.math.Size; | ||
import net.pixaurora.kitten_cube.impl.ui.widget.Widget; | ||
|
||
public class RelativeAlignment implements AlignmentStrategy { | ||
private final AlignmentStrategy baseAlignment; | ||
private final Point offset; | ||
|
||
public RelativeAlignment(AlignmentStrategy baseAlignment, Point offset) { | ||
private final Function<Widget, Point> offset; | ||
private final Widget widget; | ||
|
||
public RelativeAlignment(AlignmentStrategy baseAlignment, Function<Widget, Point> offset, Widget widget) { | ||
this.baseAlignment = baseAlignment; | ||
this.offset = offset; | ||
this.widget = widget; | ||
} | ||
|
||
@Override | ||
public Point align(Point original, Size window) { | ||
return baseAlignment.align(original, window).offset(offset); | ||
return this.baseAlignment.align(original, window).offset(this.offset.apply(this.widget)); | ||
} | ||
|
||
@Override | ||
public Point inverseAlign(Point aligned, Size window) { | ||
return baseAlignment.inverseAlign(aligned, window).offset(offset.scaledBy(-1)); | ||
return this.baseAlignment.inverseAlign(aligned, window).offset(this.offset.apply(this.widget).scaledBy(-1)); | ||
} | ||
} |
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