-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blockquote support and massivelly improve spacing/padding handling
- Loading branch information
1 parent
86d9e84
commit b1d2fc1
Showing
19 changed files
with
182 additions
and
57 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
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
29 changes: 29 additions & 0 deletions
29
...rc/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownBlockquoteComponent.kt
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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.BlockQuoteElement | ||
import gg.essential.elementa.components.UIBlock | ||
import org.xml.sax.Attributes | ||
import java.awt.Color | ||
|
||
class MarkdownBlockquoteComponent( | ||
layoutConfig: LayoutConfigImpl, | ||
parent: Element<LayoutConfigImpl, RenderData>?, | ||
qName: String, attributes: Attributes? | ||
) : BlockQuoteElement<LayoutConfigImpl, RenderData>(layoutConfig, parent, qName, attributes) { | ||
override fun drawBlock(x: Float, y: Float, height: Float, renderData: RenderData) { | ||
UIBlock.drawBlockSized( | ||
renderData.matrixStack, | ||
Color.WHITE, | ||
(x + 4f).toDouble(), y.toDouble(), | ||
2.0, height.toDouble() | ||
) | ||
} | ||
|
||
override fun getBlockWidth(layoutData: LayoutData?): Float { | ||
return 4f + 2f + 10f | ||
} | ||
} |
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
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
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
9 changes: 0 additions & 9 deletions
9
src/main/java/dev/dediamondpro/minemark/elements/NoPadding.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/main/java/dev/dediamondpro/minemark/elements/impl/BlockQuoteElement.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.dediamondpro.minemark.elements.impl; | ||
|
||
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.Inline; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.xml.sax.Attributes; | ||
|
||
public abstract class BlockQuoteElement<L extends LayoutConfig, R> extends ChildBasedElement<L, R> implements Inline { | ||
protected LayoutData.MarkDownElementPosition position; | ||
protected float blockWidth; | ||
|
||
public BlockQuoteElement(@NotNull L layoutConfig, @Nullable Element<L, R> parent, @NotNull String qName, @Nullable Attributes attributes) { | ||
super(layoutConfig, parent, qName, attributes); | ||
} | ||
|
||
@Override | ||
protected void draw(float xOffset, float yOffset, float mouseX, float mouseY, R renderData) { | ||
drawBlock(xOffset + position.getX(), yOffset + position.getY(), position.getHeight(), renderData); | ||
super.draw(xOffset + position.getX() + blockWidth, yOffset + position.getY(), mouseX, mouseY, renderData); | ||
} | ||
|
||
@Override | ||
protected void generateLayout(LayoutData layoutData) { | ||
blockWidth = getBlockWidth(layoutData); | ||
if (layoutData.isLineOccupied()) { | ||
layoutData.nextLine(); | ||
} | ||
layoutData.updatePadding(layoutConfig.getSpacingConfig().getBlockQuotePadding()); | ||
LayoutData newLayoutData = new LayoutData(layoutData.getMaxWidth() - blockWidth); | ||
super.generateLayout(newLayoutData); | ||
position = layoutData.addElement(LayoutConfig.Alignment.LEFT, layoutData.getMaxWidth(), newLayoutData.getY() + newLayoutData.getLineHeight()); | ||
layoutData.nextLine(); | ||
} | ||
|
||
public abstract void drawBlock(float x, float y, float height, R renderData); | ||
|
||
public abstract float getBlockWidth(LayoutData layoutData); | ||
} |
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
Oops, something went wrong.