Skip to content

Commit

Permalink
Allow the use of an ImageCache with MarkdownComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed May 2, 2023
1 parent 3ffa44f commit 003f400
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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
) : 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

0 comments on commit 003f400

Please sign in to comment.