diff --git a/README.md b/README.md index 5debb9a..350d7fc 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,10 @@ # MineMark Java Markdown Rendering library - \ No newline at end of file + + +# TODO +- [ ] Code blocks +- [ ] Blockquotes +- [ ] Tables +- [ ] \ tags \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 88d223a..5be7dd1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "dev.dediamondpro" -version = "1.0-SNAPSHOT49" +version = "1.0-SNAPSHOT59" repositories { mavenCentral() diff --git a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/LayoutConfigImpl.kt b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/LayoutConfigImpl.kt index 5c3533e..34916f7 100644 --- a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/LayoutConfigImpl.kt +++ b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/LayoutConfigImpl.kt @@ -11,11 +11,18 @@ import java.awt.Color class LayoutConfigImpl( var fontProvider: FontProvider = DefaultFonts.VANILLA_FONT_RENDERER, - alignment: Alignment = Alignment.LEFT, fontSize: Float = 1f, textColor: Color = Color.WHITE, - bold: Boolean = false, italic: Boolean = false, underlined: Boolean = false, strikethrough: Boolean = false, partOfLink: Boolean = false, - paddingConfig: PaddingConfig = PaddingConfig(4f, 4f), + alignment: Alignment = Alignment.LEFT, + fontSize: Float = 1f, + textColor: Color = Color.WHITE, + bold: Boolean = false, + italic: Boolean = false, + underlined: Boolean = false, + strikethrough: Boolean = false, + partOfLink: Boolean = false, + spacingConfig: SpacingConfig = SpacingConfig(4f, 4f, 4f, 16f), headingConfig: HeadingConfig = HeadingConfig(2f, 1.66f, 1.33f, 1f, 1.2f, 1f), - imageProvider: ImageProvider = DefaultImageProvider.INSTANCE, browserProvider: BrowserProvider = ElementaBrowserProvider + imageProvider: ImageProvider = DefaultImageProvider.INSTANCE, + browserProvider: BrowserProvider = ElementaBrowserProvider ) : LayoutConfig( alignment, fontSize, @@ -25,7 +32,7 @@ class LayoutConfigImpl( underlined, strikethrough, partOfLink, - paddingConfig, + spacingConfig, headingConfig, imageProvider, browserProvider @@ -41,7 +48,7 @@ class LayoutConfigImpl( isUnderlined, isStrikethrough, isPartOfLink, - paddingConfig, + spacingConfig, headingConfig, imageProvider, browserProvider diff --git a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/MineMarkComponent.kt b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/MineMarkComponent.kt index da5234b..9bb447b 100644 --- a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/MineMarkComponent.kt +++ b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/MineMarkComponent.kt @@ -79,6 +79,7 @@ class MineMarkComponent( .addElement(Elements.HEADING, ::MarkdownHeadingComponent) .addElement(Elements.IMAGE, ::MarkdownImageComponent) .addElement(Elements.HORIZONTAL_LINE, ::MarkdownHorizontalLineComponent) + .addElement(Elements.LIST_ELEMENT, ::MarkdownListElementComponent) } } } \ No newline at end of file diff --git a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownHorizontalLineComponent.kt b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownHorizontalLineComponent.kt index 3fdc1d6..bd3acf1 100644 --- a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownHorizontalLineComponent.kt +++ b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownHorizontalLineComponent.kt @@ -19,7 +19,7 @@ class MarkdownHorizontalLineComponent( renderData.matrixStack, Color.WHITE, x.toDouble(), - y.toDouble(), + (y + 2f).toDouble(), position!!.line.width.toDouble(), 2.0 ) @@ -30,6 +30,6 @@ class MarkdownHorizontalLineComponent( } override fun getHeight(layoutData: LayoutData): Float { - return 2f + return 6f } } \ No newline at end of file diff --git a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownListElementComponent.kt b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownListElementComponent.kt new file mode 100644 index 0000000..6e0e332 --- /dev/null +++ b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownListElementComponent.kt @@ -0,0 +1,51 @@ +package dev.dediamondpro.minemark.elementa.elements + +import dev.dediamondpro.minemark.LayoutData +import dev.dediamondpro.minemark.elementa.LayoutConfigImpl +import dev.dediamondpro.minemark.elementa.RenderData +import dev.dediamondpro.minemark.elements.BasicElement +import dev.dediamondpro.minemark.elements.Element +import dev.dediamondpro.minemark.elements.impl.list.ListElement +import dev.dediamondpro.minemark.elements.impl.list.ListHolderElement +import gg.essential.elementa.components.UIBlock +import org.xml.sax.Attributes +import java.awt.Color + +class MarkdownListElementComponent( + layoutConfig: LayoutConfigImpl, + parent: Element?, + qName: String, attributes: Attributes? +) : ListElement(layoutConfig, parent, qName, attributes) { + private val fontProvider = layoutConfig.fontProvider + private var marker: String = when (listType) { + ListHolderElement.ListType.ORDERED -> "${elementIndex + 1}. " + ListHolderElement.ListType.UNORDERED -> "● " + else -> "● " + } + + override fun drawMarker(x: Float, y: Float, renderData: RenderData) { + val scale = layoutConfig.fontSize + renderData.matrixStack.push() + renderData.matrixStack.scale(scale, scale, 1f) + fontProvider.drawString( + renderData.matrixStack, + marker, + layoutConfig.textColor, + x / scale, y / scale, + 1f, 1f + ) + renderData.matrixStack.pop() + } + + override fun getMarkerWidth(): Float { + return fontProvider.getStringWidth(marker, 1f) * layoutConfig.fontSize + } + + override fun getMarkerHeight(): Float { + return fontProvider.getStringHeight(marker, 1f) * layoutConfig.fontSize + } + + override fun generateLayout(layoutData: LayoutData?) { + super.generateLayout(layoutData) + } +} \ No newline at end of file diff --git a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownTextComponent.kt b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownTextComponent.kt index 2cee1a3..8e7b5ba 100644 --- a/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownTextComponent.kt +++ b/elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownTextComponent.kt @@ -1,10 +1,14 @@ package dev.dediamondpro.minemark.elementa.elements +import dev.dediamondpro.minemark.LayoutData import dev.dediamondpro.minemark.elementa.LayoutConfigImpl import dev.dediamondpro.minemark.elementa.RenderData import dev.dediamondpro.minemark.elements.Element import dev.dediamondpro.minemark.elements.impl.text.TextElement +import gg.essential.universal.UResolution import org.xml.sax.Attributes +import kotlin.math.floor +import kotlin.math.round class MarkdownTextComponent( layoutConfig: LayoutConfigImpl, @@ -12,7 +16,7 @@ class MarkdownTextComponent( qName: String, attributes: Attributes? ) : TextElement(layoutConfig, parent, qName, attributes) { private val font = layoutConfig.fontProvider - private val scale = layoutConfig.fontSize + private var scale = layoutConfig.fontSize private var prefix = buildString { if (layoutConfig.isBold) append("§l") if (layoutConfig.isItalic) append("§o") @@ -20,6 +24,12 @@ class MarkdownTextComponent( if (layoutConfig.isStrikethrough) append("§m") } + override fun generateLayout(layoutData: LayoutData?) { + val mcScale = UResolution.scaleFactor.toFloat() + scale = round(layoutConfig.fontSize * mcScale) / mcScale + super.generateLayout(layoutData) + } + override fun drawText(text: String, x: Float, bottomY: Float, hovered: Boolean, renderData: RenderData) { prefix = buildString { if (layoutConfig.isBold) append("§l") diff --git a/src/main/java/dev/dediamondpro/minemark/LayoutConfig.java b/src/main/java/dev/dediamondpro/minemark/LayoutConfig.java index 9c20894..0faf09c 100644 --- a/src/main/java/dev/dediamondpro/minemark/LayoutConfig.java +++ b/src/main/java/dev/dediamondpro/minemark/LayoutConfig.java @@ -20,12 +20,12 @@ public class LayoutConfig { private boolean underlined; private boolean strikethrough; private boolean partOfLink; - private final PaddingConfig paddingConfig; + private final SpacingConfig spacingConfig; private final HeadingConfig headingConfig; private final ImageProvider imageProvider; private final BrowserProvider browserProvider; - public LayoutConfig(Alignment alignment, float fontSize, Color textColor, boolean bold, boolean italic, boolean underlined, boolean strikethrough, boolean partOfLink, PaddingConfig paddingConfig, HeadingConfig headingConfig, ImageProvider imageProvider, BrowserProvider browserProvider) { + public LayoutConfig(Alignment alignment, float fontSize, Color textColor, boolean bold, boolean italic, boolean underlined, boolean strikethrough, boolean partOfLink, SpacingConfig spacingConfig, HeadingConfig headingConfig, ImageProvider imageProvider, BrowserProvider browserProvider) { this.alignment = alignment; this.fontSize = fontSize; this.textColor = textColor; @@ -33,22 +33,22 @@ public LayoutConfig(Alignment alignment, float fontSize, Color textColor, boolea this.italic = italic; this.underlined = underlined; this.strikethrough = strikethrough; - this.paddingConfig = paddingConfig; + this.spacingConfig = spacingConfig; this.headingConfig = headingConfig; this.imageProvider = imageProvider; this.browserProvider = browserProvider; } - public LayoutConfig(float defaultFontSize, PaddingConfig paddingConfig, HeadingConfig headingConfig, ImageProvider imageProvider, BrowserProvider browserProvider) { - this(Alignment.LEFT, defaultFontSize, Color.WHITE, false, false, false, false, false, paddingConfig, headingConfig, imageProvider, browserProvider); + public LayoutConfig(float defaultFontSize, SpacingConfig spacingConfig, HeadingConfig headingConfig, ImageProvider imageProvider, BrowserProvider browserProvider) { + this(Alignment.LEFT, defaultFontSize, Color.WHITE, false, false, false, false, false, spacingConfig, headingConfig, imageProvider, browserProvider); } - public LayoutConfig(float defaultFontSize, PaddingConfig paddingConfig, HeadingConfig headingConfig) { - this(defaultFontSize, paddingConfig, headingConfig, DefaultImageProvider.INSTANCE, DefaultBrowserProvider.INSTANCE); + public LayoutConfig(float defaultFontSize, SpacingConfig spacingConfig, HeadingConfig headingConfig) { + this(defaultFontSize, spacingConfig, headingConfig, DefaultImageProvider.INSTANCE, DefaultBrowserProvider.INSTANCE); } public LayoutConfig clone() { - return new LayoutConfig(alignment, fontSize, new Color(textColor.getRGB()), bold, italic, underlined, strikethrough, partOfLink, paddingConfig, headingConfig, imageProvider, browserProvider); + return new LayoutConfig(alignment, fontSize, new Color(textColor.getRGB()), bold, italic, underlined, strikethrough, partOfLink, spacingConfig, headingConfig, imageProvider, browserProvider); } public Alignment getAlignment() { @@ -115,8 +115,8 @@ public void setPartOfLink(boolean partOfLink) { this.partOfLink = partOfLink; } - public PaddingConfig getPaddingConfig() { - return paddingConfig; + public SpacingConfig getSpacingConfig() { + return spacingConfig; } public HeadingConfig getHeadingConfig() { @@ -135,13 +135,17 @@ public enum Alignment { CENTER, LEFT, RIGHT } - public static class PaddingConfig { + public static class SpacingConfig { private final float textSpacing; private final float paragraphPadding; + private final float listPadding; + private final float listIndentSpacing; - public PaddingConfig(float textSpacing, float paragraphPadding) { + public SpacingConfig(float textSpacing, float paragraphPadding, float listPadding, float listIndentSpacing) { this.textSpacing = textSpacing; this.paragraphPadding = paragraphPadding; + this.listPadding = listPadding; + this.listIndentSpacing = listIndentSpacing; } public float getTextSpacing() { @@ -151,6 +155,14 @@ public float getTextSpacing() { public float getParagraphPadding() { return paragraphPadding; } + + public float getListPadding() { + return listPadding; + } + + public float getListIndentSpacing() { + return listIndentSpacing; + } } public static class HeadingConfig { diff --git a/src/main/java/dev/dediamondpro/minemark/elements/ChildBasedElement.java b/src/main/java/dev/dediamondpro/minemark/elements/ChildBasedElement.java index b85352f..16942f3 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/ChildBasedElement.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/ChildBasedElement.java @@ -23,11 +23,24 @@ protected void generateLayout(LayoutData layoutData) { if (!(this instanceof Inline) && !layoutData.isLineEmpty()) { layoutData.nextLine(); } + float padding = getPadding(layoutData); + if (padding != 0 && !(parent instanceof NoPadding)) { + layoutData.setLineHeight(padding); + layoutData.nextLine(); + } for (Element child : children) { child.generateLayout(layoutData); } if (!(this instanceof Inline) && !layoutData.isLineEmpty()) { layoutData.nextLine(); } + if (padding != 0 && !(parent instanceof NoPadding)) { + layoutData.setLineHeight(padding); + layoutData.nextLine(); + } + } + + protected float getPadding(LayoutData layoutData) { + return 0f; } } diff --git a/src/main/java/dev/dediamondpro/minemark/elements/Element.java b/src/main/java/dev/dediamondpro/minemark/elements/Element.java index cd70969..9ed0a40 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/Element.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/Element.java @@ -10,7 +10,7 @@ import java.util.ArrayList; public abstract class Element { - private final @Nullable Element parent; + protected final @Nullable Element parent; protected final ArrayList> children = new ArrayList<>(); protected final String qName; protected final Attributes attributes; diff --git a/src/main/java/dev/dediamondpro/minemark/elements/NoPadding.java b/src/main/java/dev/dediamondpro/minemark/elements/NoPadding.java new file mode 100644 index 0000000..ebedc10 --- /dev/null +++ b/src/main/java/dev/dediamondpro/minemark/elements/NoPadding.java @@ -0,0 +1,9 @@ +package dev.dediamondpro.minemark.elements; + + +/** + * Interface to tell elements like {@link dev.dediamondpro.minemark.elements.impl.ParagraphElement} to not add any padding. + * Useful for elements like {@link dev.dediamondpro.minemark.elements.impl.list.ListElement} + */ +public interface NoPadding { +} diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/LinkElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/LinkElement.java index a412a2d..4be4e5c 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/LinkElement.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/impl/LinkElement.java @@ -16,8 +16,6 @@ public class LinkElement extends ChildBasedElement implements Inline { protected final ArrayList positions = new ArrayList<>(); protected final String link; - protected boolean wasUnderlined; - protected boolean hovered; public LinkElement(@NotNull L layoutConfig, @Nullable Element parent, @NotNull String qName, @Nullable Attributes attributes) { super(layoutConfig, parent, qName, attributes); diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/ParagraphElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/ParagraphElement.java index 6b6abfc..37b52a8 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/ParagraphElement.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/impl/ParagraphElement.java @@ -4,7 +4,7 @@ import dev.dediamondpro.minemark.LayoutData; import dev.dediamondpro.minemark.elements.ChildBasedElement; import dev.dediamondpro.minemark.elements.Element; -import dev.dediamondpro.minemark.elements.Inline; +import dev.dediamondpro.minemark.elements.NoPadding; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.xml.sax.Attributes; @@ -15,14 +15,7 @@ public ParagraphElement(@NotNull L layoutConfig, @Nullable Element parent, } @Override - protected void generateLayout(LayoutData layoutData) { - if (!layoutData.isLineEmpty()) { - layoutData.nextLine(); - } - layoutData.setLineHeight(layoutConfig.getPaddingConfig().getParagraphPadding()); - layoutData.nextLine(); - super.generateLayout(layoutData); - layoutData.setLineHeight(layoutConfig.getPaddingConfig().getParagraphPadding()); - layoutData.nextLine(); + protected float getPadding(LayoutData layoutData) { + return layoutConfig.getSpacingConfig().getParagraphPadding(); } } diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListElement.java index 62b60ce..c5ac6b5 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListElement.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListElement.java @@ -4,14 +4,19 @@ import dev.dediamondpro.minemark.LayoutData; import dev.dediamondpro.minemark.elements.ChildBasedElement; import dev.dediamondpro.minemark.elements.Element; +import dev.dediamondpro.minemark.elements.Inline; +import dev.dediamondpro.minemark.elements.NoPadding; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.xml.sax.Attributes; -// TODO: implement -public abstract class ListElement extends Element { +public abstract class ListElement extends ChildBasedElement implements Inline, NoPadding { protected final ListHolderElement.ListType listType; protected final int elementIndex; + protected LayoutData.MarkDownElementPosition markerPosition; + protected float markerWidth; + protected float markerHeight; + protected float indentX; public ListElement(@NotNull L layoutConfig, @Nullable Element parent, @NotNull String qName, @Nullable Attributes attributes) { super(layoutConfig, parent, qName, attributes); @@ -25,17 +30,39 @@ public ListElement(@NotNull L layoutConfig, @Nullable Element parent, @Not @Override protected void generateLayout(LayoutData layoutData) { - + // Marker is always aligned to the left + markerWidth = getMarkerWidth(); + markerHeight = getMarkerHeight(); + indentX = Math.max(markerWidth, layoutConfig.getSpacingConfig().getListIndentSpacing()); + markerPosition = layoutData.addElement(LayoutConfig.Alignment.LEFT, indentX, markerHeight); + LayoutData newLayoutData = new LayoutData(layoutData.getMaxWidth() - indentX); + newLayoutData.updateLineHeight(layoutData.getLineHeight()); + LayoutData.MarkDownLine firstLine = newLayoutData.getCurrentLine(); + super.generateLayout(newLayoutData); + layoutData.updateLineHeight(firstLine.getHeight()); + layoutData.addX(firstLine.getWidth()); + layoutData.nextLine(); + if (newLayoutData.getCurrentLine() != firstLine) { + layoutData.setLineHeight(newLayoutData.getY() + newLayoutData.getLineHeight() - firstLine.getHeight()); + layoutData.nextLine(); + } } @Override protected void draw(float xOffset, float yOffset, float mouseX, float mouseY, R renderData) { - + drawMarker( + markerPosition.getRightX() - markerWidth + xOffset, + markerPosition.getY() + yOffset, renderData + ); + super.draw( + xOffset + indentX, yOffset + markerPosition.getLine().getY(), + mouseX - indentX, mouseY - markerPosition.getLine().getY(), renderData + ); } protected abstract void drawMarker(float x, float y, R renderData); - protected abstract float getMarkerWidth(ListHolderElement.ListType listType, int elementIndex); + protected abstract float getMarkerWidth(); - protected abstract float getMarkerHeight(ListHolderElement.ListType listType, int elementIndex); + protected abstract float getMarkerHeight(); } diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListHolderElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListHolderElement.java index f54d9b7..c9d7f8a 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListHolderElement.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/impl/list/ListHolderElement.java @@ -1,8 +1,10 @@ package dev.dediamondpro.minemark.elements.impl.list; import dev.dediamondpro.minemark.LayoutConfig; +import dev.dediamondpro.minemark.LayoutData; import dev.dediamondpro.minemark.elements.ChildBasedElement; import dev.dediamondpro.minemark.elements.Element; +import dev.dediamondpro.minemark.elements.NoPadding; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.xml.sax.Attributes; @@ -22,6 +24,11 @@ public ListHolderElement(@NotNull L layoutConfig, @Nullable Element parent } } + @Override + protected float getPadding(LayoutData layoutData) { + return layoutConfig.getSpacingConfig().getListPadding(); + } + public int getElementPosition(Element element) { return children.indexOf(element); } diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/OrderedListElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/list/OrderedListElement.java deleted file mode 100644 index a8f9b52..0000000 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/OrderedListElement.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.dediamondpro.minemark.elements.impl.list; -/* -import dev.dediamondpro.minemark.LayoutConfig; -import dev.dediamondpro.minemark.elements.Element; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.xml.sax.Attributes; - -public class OrderedListElement extends Element { - public OrderedListElement(@NotNull L layoutConfig, @Nullable Element parent, @NotNull String qName, @Nullable Attributes attributes) { - super(layoutConfig, parent, qName, attributes); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/UnorderedListElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/list/UnorderedListElement.java deleted file mode 100644 index df6caab..0000000 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/list/UnorderedListElement.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.dediamondpro.minemark.elements.impl.list; -/* -import dev.dediamondpro.minemark.LayoutConfig; -import dev.dediamondpro.minemark.elements.Element; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.xml.sax.Attributes; - -public class UnorderedListElement extends Element { - public UnorderedListElement(@NotNull L layoutConfig, @Nullable Element parent, @NotNull String qName, @Nullable Attributes attributes) { - super(layoutConfig, parent, qName, attributes); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/dev/dediamondpro/minemark/elements/impl/text/TextElement.java b/src/main/java/dev/dediamondpro/minemark/elements/impl/text/TextElement.java index aa422e5..1575e1e 100644 --- a/src/main/java/dev/dediamondpro/minemark/elements/impl/text/TextElement.java +++ b/src/main/java/dev/dediamondpro/minemark/elements/impl/text/TextElement.java @@ -24,16 +24,16 @@ public TextElement(@NotNull L layoutConfig, @Nullable Element parent, @Not public void generateLayout(LayoutData layoutData) { lines.clear(); ArrayList allLines = new ArrayList<>(); - String[] predefinedLines = text.split("\n"); + String[] predefinedLines = text.split("(?=\n)"); for (int i = 0; i < predefinedLines.length; i++) { - String line = predefinedLines[i]; + String line = predefinedLines[i].replace("\n", ""); allLines.addAll(wrapText(line, i == 0 ? layoutData.getX() : 0f, layoutData.getMaxWidth())); } for (int i = 0; i < allLines.size(); i++) { String line = allLines.get(i); lines.put(layoutData.addElement( layoutConfig.getAlignment(), getTextWidth(line), - getTextHeight(line) + layoutConfig.getPaddingConfig().getTextSpacing() * layoutConfig.getFontSize()), + getTextHeight(line) + layoutConfig.getSpacingConfig().getTextSpacing() * layoutConfig.getFontSize()), line); if (i != allLines.size() - 1) { layoutData.nextLine(); diff --git a/src/test/java/BasicTest.java b/src/test/java/BasicTest.java index 05564b6..8b79bab 100644 --- a/src/test/java/BasicTest.java +++ b/src/test/java/BasicTest.java @@ -23,7 +23,7 @@ public class BasicTest { .addElement(Elements.HEADING, HeadingElement::new)*/ .build(); - private final LayoutConfig config = new LayoutConfig(5, new LayoutConfig.PaddingConfig(1f, 2f), new LayoutConfig.HeadingConfig(6, 5, 4, 3, 2, 1)); + private final LayoutConfig config = new LayoutConfig(5, new LayoutConfig.SpacingConfig(1f, 2f, 2f, 5f), new LayoutConfig.HeadingConfig(6, 5, 4, 3, 2, 1)); @Test public void test() { diff --git a/src/test/resources/test.md b/src/test/resources/test.md index a477d9c..f08e706 100644 --- a/src/test/resources/test.md +++ b/src/test/resources/test.md @@ -2,5 +2,15 @@ Oh, so **test**
test that's an issue? -1. oihdgiuqugydzq iudyuiq huqhd uqh fuh fuqzhfuiqhfqzufqiufhqui huqfh uiqz hufqh uiq -2. hdyqzuidqujdqoizdqzdjzqodjkqzpdpojqjdzq \ No newline at end of file +
+ +> hello +> +> How are you kind sir + +1. Test + 2. Yes + +- Hi + +
\ No newline at end of file