Skip to content

Commit 003f400

Browse files
committed
Allow the use of an ImageCache with MarkdownComponent
1 parent 3ffa44f commit 003f400

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

api/Elementa.api

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,14 +3152,16 @@ public final class gg/essential/elementa/markdown/MarkdownComponent : gg/essenti
31523152
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;)V
31533153
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;F)V
31543154
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;)V
3155-
public synthetic fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
31563155
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;Z)V
31573156
public synthetic fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
3157+
public fun <init> (Ljava/lang/String;Lgg/essential/elementa/markdown/MarkdownConfig;FLgg/essential/elementa/font/FontProvider;ZLgg/essential/elementa/components/image/ImageCache;)V
3158+
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
31583159
public fun animationFrame ()V
31593160
public final fun bindText (Lgg/essential/elementa/state/State;)Lgg/essential/elementa/markdown/MarkdownComponent;
31603161
public fun draw (Lgg/essential/universal/UMatrixStack;)V
31613162
public final fun getConfig ()Lgg/essential/elementa/markdown/MarkdownConfig;
31623163
public final fun getDrawables ()Lgg/essential/elementa/markdown/drawables/DrawableList;
3164+
public final fun getImageCache ()Lgg/essential/elementa/components/image/ImageCache;
31633165
public final fun getMaxTextLineWidth ()F
31643166
public final fun getSectionOffsets ()Ljava/util/Map;
31653167
public final fun layout ()V

src/main/kotlin/gg/essential/elementa/markdown/MarkdownComponent.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import gg.essential.elementa.components.MarkdownNode
55
import gg.essential.elementa.components.TreeListComponent
66
import gg.essential.elementa.components.TreeNode
77
import gg.essential.elementa.components.Window
8+
import gg.essential.elementa.components.image.ImageCache
89
import gg.essential.elementa.constraints.HeightConstraint
910
import gg.essential.elementa.dsl.pixels
1011
import gg.essential.elementa.events.UIEvent
@@ -34,6 +35,7 @@ class MarkdownComponent(
3435
private val codeFontPointSize: Float = 10f,
3536
private val codeFontRenderer: FontProvider = ElementaFonts.JETBRAINS_MONO,
3637
private val disableSelection: Boolean = false,
38+
val imageCache: ImageCache? = null
3739
) : UIComponent() {
3840

3941
@JvmOverloads
@@ -42,7 +44,8 @@ class MarkdownComponent(
4244
config: MarkdownConfig = MarkdownConfig(),
4345
codeFontPointSize: Float = 10f,
4446
codeFontRenderer: FontProvider = ElementaFonts.JETBRAINS_MONO,
45-
) : this(text, config, codeFontPointSize, codeFontRenderer, false)
47+
disableSelection: Boolean = false
48+
) : this(text, config, codeFontPointSize, codeFontRenderer, disableSelection, null)
4649

4750
private val configState = BasicState(config)
4851
val config: MarkdownConfig

src/main/kotlin/gg/essential/elementa/markdown/drawables/ImageDrawable.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class ImageDrawable(md: MarkdownComponent, val url: URL, private val fallback: D
3030
private lateinit var imageX: ShiftableMDPixelConstraint
3131
private lateinit var imageY: ShiftableMDPixelConstraint
3232

33-
private val image = UIImage.ofURL(url) childOf md
33+
private val image =
34+
(if (md.imageCache == null) UIImage.ofURL(url) else UIImage.ofURL(url, md.imageCache)) childOf md
3435
private var hasLoaded = false
3536

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

0 commit comments

Comments
 (0)