Skip to content

Commit

Permalink
make RenderRotatedText more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Jan 26, 2025
1 parent 2195c5d commit b4049c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ Tab[] createSlides(float w, float h) {
createSlide(DrawText::new, w, h),
createSlide(RenderText::new, w, h)
));
double[] angles = {
0, 45, 90, -45, -90
};

for (Graphics.HAnchor hAnchor : Graphics.HAnchor.values()) {
for (Graphics.VAnchor vAnchor : Graphics.VAnchor.values()) {
tabs.add(createBigSlide(() -> new RenderRotatedText(hAnchor, vAnchor), w, h));
tabs.add(createBigSlide(() -> new RenderRotatedText(hAnchor, vAnchor, angles), w, h));
}
}
return tabs.toArray(Tab[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import com.dua3.utility.text.VerticalAlignment;
import com.dua3.utility.ui.Graphics;

import java.util.stream.DoubleStream;

public class RenderRotatedText implements FxGraphicsSample.Slide {

public static final RichText TEXT = new RichTextBuilder()
Expand All @@ -37,10 +35,13 @@ public class RenderRotatedText implements FxGraphicsSample.Slide {
.toRichText();
private final Graphics.HAnchor hAnchor;
private final Graphics.VAnchor vAnchor;
private double[] angles;


public RenderRotatedText(Graphics.HAnchor hAnchor, Graphics.VAnchor vAnchor) {
public RenderRotatedText(Graphics.HAnchor hAnchor, Graphics.VAnchor vAnchor, double[] angles) {
this.hAnchor = hAnchor;
this.vAnchor = vAnchor;
this.angles = angles;
}

@Override
Expand All @@ -54,11 +55,6 @@ public void draw(Graphics g) {
}

public void drawText(Graphics g) {
double delta = 10.0;
double[] angles = DoubleStream.of(-delta, 90.0 - delta, 0, 45, 90, 135, 180, 225, 270, 315)
.map(v -> v + delta)
.toArray();

record Mode(Graphics.TextRotationMode mode, Graphics.AlignmentAxis axis) {
@Override
public String toString() {
Expand Down

0 comments on commit b4049c5

Please sign in to comment.