-
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.
completely redo how styles are handled
- Loading branch information
1 parent
3420d80
commit ce052d7
Showing
41 changed files
with
623 additions
and
542 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
60 changes: 0 additions & 60 deletions
60
elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/LayoutConfigImpl.kt
This file was deleted.
Oops, something went wrong.
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
10 changes: 6 additions & 4 deletions
10
...a/src/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownHeadingComponent.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
10 changes: 6 additions & 4 deletions
10
...ain/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownHorizontalLineComponent.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
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
20 changes: 11 additions & 9 deletions
20
...c/main/kotlin/dev/dediamondpro/minemark/elementa/elements/MarkdownListElementComponent.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 |
---|---|---|
@@ -1,44 +1,46 @@ | ||
package dev.dediamondpro.minemark.elementa.elements | ||
|
||
import dev.dediamondpro.minemark.LayoutData | ||
import dev.dediamondpro.minemark.elementa.LayoutConfigImpl | ||
import dev.dediamondpro.minemark.LayoutStyle | ||
import dev.dediamondpro.minemark.elementa.RenderData | ||
import dev.dediamondpro.minemark.elementa.style.MarkdownStyle | ||
import dev.dediamondpro.minemark.elements.Element | ||
import dev.dediamondpro.minemark.elements.impl.list.ListElement | ||
import dev.dediamondpro.minemark.elements.impl.list.ListHolderElement | ||
import org.xml.sax.Attributes | ||
|
||
class MarkdownListElementComponent( | ||
layoutConfig: LayoutConfigImpl, | ||
parent: Element<LayoutConfigImpl, RenderData>?, | ||
style: MarkdownStyle, | ||
layoutStyle: LayoutStyle, | ||
parent: Element<MarkdownStyle, RenderData>?, | ||
qName: String, attributes: Attributes? | ||
) : ListElement<LayoutConfigImpl, RenderData>(layoutConfig, parent, qName, attributes) { | ||
private val fontProvider = layoutConfig.fontProvider | ||
) : ListElement<MarkdownStyle, RenderData>(style, layoutStyle, parent, qName, attributes) { | ||
private val fontProvider = style.textStyle.font | ||
private var markerStr: 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 | ||
val scale = layoutStyle.fontSize | ||
renderData.matrixStack.push() | ||
renderData.matrixStack.scale(scale, scale, 1f) | ||
fontProvider.drawString( | ||
renderData.matrixStack, | ||
markerStr, | ||
layoutConfig.textColor, | ||
layoutStyle.textColor, | ||
x / scale, y / scale, | ||
1f, 1f | ||
) | ||
renderData.matrixStack.pop() | ||
} | ||
|
||
override fun getMarkerWidth(): Float { | ||
return fontProvider.getStringWidth(markerStr, 1f) * layoutConfig.fontSize | ||
return fontProvider.getStringWidth(markerStr, 1f) * layoutStyle.fontSize | ||
} | ||
|
||
override fun getMarkerHeight(layoutData: LayoutData?): Float { | ||
return fontProvider.getStringHeight(markerStr, 1f) * layoutConfig.fontSize | ||
return fontProvider.getStringHeight(markerStr, 1f) * layoutStyle.fontSize | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
elementa/src/main/kotlin/dev/dediamondpro/minemark/elementa/style/MarkdownStyle.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,40 @@ | ||
package dev.dediamondpro.minemark.elementa.style | ||
|
||
import dev.dediamondpro.minemark.elementa.util.ElementaBrowserProvider | ||
import dev.dediamondpro.minemark.providers.DefaultImageProvider | ||
import dev.dediamondpro.minemark.style.* | ||
import gg.essential.elementa.font.DefaultFonts | ||
import gg.essential.elementa.font.FontProvider | ||
import java.awt.Color | ||
|
||
data class MarkdownStyle @JvmOverloads constructor( | ||
private val textStyle: MarkdownTextStyle = MarkdownTextStyle( | ||
1f, Color.WHITE, 2f, DefaultFonts.VANILLA_FONT_RENDERER | ||
), | ||
private val paragraphStyle: ParagraphStyleConfig = ParagraphStyleConfig(6f), | ||
private val linkStyle: LinkStyleConfig = LinkStyleConfig(Color(65, 105, 225), true, ElementaBrowserProvider), | ||
private val headerStyle: HeaderStyleConfig = HeaderStyleConfig( | ||
HeaderLevelStyleConfig(2f, 12f, true, Color(80, 80, 80), 2f, 5f), | ||
HeaderLevelStyleConfig(1.66f, 10f, true, Color(80, 80, 80), 2f, 5f), | ||
HeaderLevelStyleConfig(1.33f, 8f), | ||
HeaderLevelStyleConfig(1f, 6f), | ||
HeaderLevelStyleConfig(0.7f, 4f), | ||
HeaderLevelStyleConfig(0.7f, 4f) | ||
), | ||
private val imageStyle: ImageStyleConfig = ImageStyleConfig(DefaultImageProvider.INSTANCE), | ||
private val listStyle: ListStyleConfig = ListStyleConfig(16f, 6f) | ||
) : Style { | ||
override fun getTextStyle(): MarkdownTextStyle = textStyle | ||
override fun getParagraphStyle(): ParagraphStyleConfig = paragraphStyle | ||
override fun getLinkStyle(): LinkStyleConfig = linkStyle | ||
override fun getHeaderStyle(): HeaderStyleConfig = headerStyle | ||
override fun getImageStyle(): ImageStyleConfig = imageStyle | ||
override fun getListStyle(): ListStyleConfig = listStyle | ||
} | ||
|
||
class MarkdownTextStyle( | ||
defaultFontSize: Float, | ||
defaultTextColor: Color?, | ||
padding: Float, | ||
val font: FontProvider | ||
) : TextStyleConfig(defaultFontSize, defaultTextColor, padding) |
Oops, something went wrong.