Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown: allow the use of an ImageCache with MarkdownComponent #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/Elementa.api
Original file line number Diff line number Diff line change
Expand Up @@ -3152,14 +3152,16 @@ public final class gg/essential/elementa/markdown/MarkdownComponent : gg/essenti
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;)V
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;F)V
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;)V
public synthetic fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;Z)V
public synthetic fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ZLgg/essential/elementa/components/image/ImageCache;)V
public synthetic fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ZLgg/essential/elementa/components/image/ImageCache;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun animationFrame ()V
public final fun bindText (Lgg/essential/elementa/state/State;)Lgg/essential/elementa/markdown/MarkdownComponent;
public fun draw (Lgg/essential/universal/UMatrixStack;)V
public final fun getConfig ()Lgg/essential/elementa/markdown/MarkdownConfig;
public final fun getDrawables ()Lgg/essential/elementa/markdown/drawables/DrawableList;
public final fun getImageCache ()Lgg/essential/elementa/components/image/ImageCache;
public final fun getMaxTextLineWidth ()F
public final fun getSectionOffsets ()Ljava/util/Map;
public final fun layout ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import gg.essential.elementa.components.MarkdownNode
import gg.essential.elementa.components.TreeListComponent
import gg.essential.elementa.components.TreeNode
import gg.essential.elementa.components.Window
import gg.essential.elementa.components.image.ImageCache
import gg.essential.elementa.constraints.HeightConstraint
import gg.essential.elementa.dsl.pixels
import gg.essential.elementa.events.UIEvent
Expand Down Expand Up @@ -34,6 +35,7 @@ class MarkdownComponent(
private val codeFontPointSize: Float = 10f,
private val codeFontRenderer: FontProvider = ElementaFonts.JETBRAINS_MONO,
private val disableSelection: Boolean = false,
val imageCache: ImageCache? = null
DeDiamondPro marked this conversation as resolved.
Show resolved Hide resolved
) : UIComponent() {

@JvmOverloads
Expand All @@ -42,7 +44,8 @@ class MarkdownComponent(
config: MarkdownConfig = MarkdownConfig(),
codeFontPointSize: Float = 10f,
codeFontRenderer: FontProvider = ElementaFonts.JETBRAINS_MONO,
) : this(text, config, codeFontPointSize, codeFontRenderer, false)
disableSelection: Boolean = false
) : this(text, config, codeFontPointSize, codeFontRenderer, disableSelection, null)

private val configState = BasicState(config)
val config: MarkdownConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ImageDrawable(md: MarkdownComponent, val url: URL, private val fallback: D
private lateinit var imageX: ShiftableMDPixelConstraint
private lateinit var imageY: ShiftableMDPixelConstraint

private val image = UIImage.ofURL(url) childOf md
private val image =
(if (md.imageCache == null) UIImage.ofURL(url) else UIImage.ofURL(url, md.imageCache)) childOf md
private var hasLoaded = false

override fun layoutImpl(x: Float, y: Float, width: Float): Layout {
Expand Down