Skip to content

Commit d6862e4

Browse files
committed
move layout style system completly to StyleEntries
1 parent 83fe852 commit d6862e4

File tree

16 files changed

+260
-173
lines changed

16 files changed

+260
-173
lines changed

elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownListElementComponent.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ class MarkdownListElementComponent(
4040
}
4141

4242
override fun drawMarker(x: Float, y: Float, matrixStack: UMatrixStack) {
43-
val scale = layoutStyle.fontSize
43+
val scale = layoutStyle.get(LayoutStyle.FONT_SIZE)
4444
matrixStack.push()
4545
matrixStack.scale(scale, scale, 1f)
4646
fontProvider.drawString(
4747
matrixStack,
4848
markerStr,
49-
layoutStyle.textColor,
49+
layoutStyle.get(LayoutStyle.TEXT_COLOR),
5050
x / scale, y / scale,
5151
1f, 1f
5252
)
5353
matrixStack.pop()
5454
}
5555

5656
override fun getListMarkerWidth(layoutData: LayoutData?, matrixStack: UMatrixStack): Float {
57-
return fontProvider.getStringWidth(markerStr, 1f) * layoutStyle.fontSize
57+
return fontProvider.getStringWidth(markerStr, 1f) * layoutStyle.get(LayoutStyle.FONT_SIZE)
5858
}
5959

6060
override fun getMarkerHeight(layoutData: LayoutData?, matrixStack: UMatrixStack): Float {
61-
return (fontProvider.getBaseLineHeight() + fontProvider.getShadowHeight()) * layoutStyle.fontSize
61+
return (fontProvider.getBaseLineHeight() + fontProvider.getShadowHeight()) * layoutStyle.get(LayoutStyle.FONT_SIZE)
6262
}
6363
}

elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownTextComponent.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ class MarkdownTextComponent(
3737
qName: String, attributes: Attributes?
3838
) : TextElement<MarkdownStyle, UMatrixStack>(text, style, layoutStyle, parent, qName, attributes) {
3939
private val font = style.textStyle.font
40-
private var scale = layoutStyle.fontSize
40+
private var scale = layoutStyle.get(LayoutStyle.FONT_SIZE)
4141
private var prefix = buildString {
42-
if (layoutStyle.isBold) append("§l")
43-
if (layoutStyle.isItalic) append("§o")
44-
if (layoutStyle.isUnderlined) append("§n")
45-
if (layoutStyle.isStrikethrough) append("§m")
42+
if (layoutStyle.get(LayoutStyle.BOLD)) append("§l")
43+
if (layoutStyle.get(LayoutStyle.ITALIC)) append("§o")
44+
if (layoutStyle.get(LayoutStyle.UNDERLINED)) append("§n")
45+
if (layoutStyle.get(LayoutStyle.STRIKETHROUGH)) append("§m")
4646
}
4747

4848
override fun generateLayout(layoutData: LayoutData?, matrixStack: UMatrixStack) {
4949
val mcScale = UResolution.scaleFactor.toFloat()
50-
scale = round(layoutStyle.fontSize * mcScale) / mcScale
50+
scale = round(layoutStyle.get(LayoutStyle.FONT_SIZE) * mcScale) / mcScale
5151
super.generateLayout(layoutData, matrixStack)
5252
}
5353

@@ -62,18 +62,18 @@ class MarkdownTextComponent(
6262
matrixStack: UMatrixStack
6363
) {
6464
prefix = buildString {
65-
if (layoutStyle.isBold) append("§l")
66-
if (layoutStyle.isItalic) append("§o")
67-
if (layoutStyle.isStrikethrough) append("§m")
68-
if (layoutStyle.isUnderlined || layoutStyle.isPartOfLink && hovered) append("§n")
65+
if (layoutStyle.get(LayoutStyle.BOLD)) append("§l")
66+
if (layoutStyle.get(LayoutStyle.ITALIC)) append("§o")
67+
if (layoutStyle.get(LayoutStyle.STRIKETHROUGH)) append("§m")
68+
if (layoutStyle.get(LayoutStyle.UNDERLINED) || layoutStyle.get(LayoutStyle.PART_OF_LINK) && hovered) append("§n")
6969
}
7070

7171
matrixStack.push()
7272
matrixStack.scale(scale, scale, 1f)
7373
font.drawString(
7474
matrixStack,
7575
prefix + text,
76-
layoutStyle.textColor,
76+
layoutStyle.get(LayoutStyle.TEXT_COLOR),
7777
x / scale, y / scale,
7878
1f, 1f
7979
)

minecraft/src/main/java/dev/dediamondpro/minemark/minecraft/elements/MarkdownListElement.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ public MarkdownListElement(@NotNull MarkdownStyle style, @NotNull LayoutStyle la
4545

4646
@Override
4747
protected void drawMarker(float x, float y, MarkdownRenderer renderer) {
48-
renderer.drawText(markerStr, (int) x, (int) y, layoutStyle.getFontSize(), layoutStyle.getTextColor().getRGB(), style.getTextStyle().hasShadow());
48+
renderer.drawText(markerStr, (int) x, (int) y, layoutStyle.get(LayoutStyle.FONT_SIZE), layoutStyle.get(LayoutStyle.TEXT_COLOR).getRGB(), style.getTextStyle().hasShadow());
4949
}
5050

5151
@Override
5252
protected float getListMarkerWidth(LayoutData layoutData, MarkdownRenderer renderer) {
53-
return renderer.getTextWidth(markerStr, layoutStyle.getFontSize());
53+
return renderer.getTextWidth(markerStr, layoutStyle.get(LayoutStyle.FONT_SIZE));
5454
}
5555

5656
@Override
5757
protected float getMarkerHeight(LayoutData layoutData, MarkdownRenderer renderData) {
58-
return 8f * layoutStyle.getFontSize();
58+
return 8f * layoutStyle.get(LayoutStyle.FONT_SIZE);
5959
}
6060
}

minecraft/src/main/java/dev/dediamondpro/minemark/minecraft/elements/MarkdownTextElement.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ protected float getTextWidth(@NotNull String text, float fontSize, MarkdownRende
5151

5252
private String getPrefix(boolean hovered) {
5353
StringBuilder prefixBuilder = new StringBuilder();
54-
if (layoutStyle.isBold()) prefixBuilder.append("§l");
55-
if (layoutStyle.isItalic()) prefixBuilder.append("§o");
56-
if (layoutStyle.isStrikethrough()) prefixBuilder.append("§m");
57-
if (layoutStyle.isUnderlined() || layoutStyle.isPartOfLink() && hovered) prefixBuilder.append("§n");
54+
if (layoutStyle.get(LayoutStyle.BOLD)) prefixBuilder.append("§l");
55+
if (layoutStyle.get(LayoutStyle.ITALIC)) prefixBuilder.append("§o");
56+
if (layoutStyle.get(LayoutStyle.STRIKETHROUGH)) prefixBuilder.append("§m");
57+
if (layoutStyle.get(LayoutStyle.UNDERLINED) || layoutStyle.get(LayoutStyle.PART_OF_LINK) && hovered) prefixBuilder.append("§n");
5858
return prefixBuilder.toString();
5959
}
6060

0 commit comments

Comments
 (0)