Skip to content

Output

1 source file(s), 25 public symbol(s), 25 of them carrying KDoc. Everything below is the documentation that lives beside the code — the same text the completion documentation panel shows in the editor. A blank summary means the declaration has no KDoc yet, not that this page dropped it.

MediaSlots.kt

A row of input slots for pictures and text, in a box's output: what a program that compares a few things (CLIP embeddings, a style transfer, a classifier) reads its inputs from.

val inputs = mediaSlots {
    image("public/docs/assets/madp_tetra/tabby_cat.jpg")
    image("public/docs/assets/madp_tetra/labrador.jpg")
    text("a photo of a cat")
    tray("public/docs/assets/madp_tetra")     // more pictures, to drag onto a slot
}
inputs.onChange { slots ->
    val vectors = slots.map { it.clip() }
    ...
}

Each slot has a number and a colour, and holds one picture or one piece of text:

  • click a picture slot to choose a file, or drop one on it; drop several and they fill that slot and the ones after it;
  • drop a folder (or use folder…) to put its pictures in the tray under the slots, then drag any of them onto a slot; MediaSlotsBuilder.tray fills the tray from the box's own code;
  • type into a text slot;
  • reset puts every slot back as the code says.

Pictures are scaled in the browser to at most 640 pixels on the long side, with the photo's EXIF orientation applied, before they are sent; the box sees a BufferedImage. What was dropped or typed outlives a re-run of the box, but not a restart of Field: the code's own files are what a document keeps.

onChange runs on a thread of its own, once now and again after every change, and only when every slot is filled. Changes that arrive while it is running are folded into one more run.

src/jvmMain/kotlin/afield/ui/output/MediaSlots.kt — read the source

Top-level functions

Declaration Summary
fun Box.mediaSlots(channel: String = "inputs", colors: List<String> = MEDIA_SLOT_COLORS, block: MediaSlotsBuilder.() -> Unit): MediaSlots Show a row of picture and text slots in this box's output and return them; see MediaSlots.

Top-level values

Declaration Summary
val MEDIA_SLOT_COLORS The madp tetra page's four slot colours, then two more from the same palette.

MediaSlots

class MediaSlots internal constructor(private val box: Box, private val channel: String, private val defaults: List<MediaSlot>)

The row of slots a box is holding: read slots or index it with get, ask whether it is complete, and hand onChange a block to run whenever one of them changes.

Declaration Summary
val slots: List<MediaSlot> The slots as they are now: the code's, with whatever was dropped or typed over them.
val tray: List<MediaSlot> The pictures waiting in the tray.
operator fun get(i: Int): MediaSlot Slot i, counting from 0.
val complete: Boolean Whether every slot holds something.
fun onChange(block: (List<MediaSlot>) -> Unit) Run block with the slots now, and again after every change, on a thread of its own. It is not called while a slot is empty. Calling onChange again replaces the block.

MediaSlot

class MediaSlot internal constructor(val index: Int, val kind: Kind, val color: String, val label: String, val image: BufferedImage?, val text: String, val file: File? = null)

One slot of a MediaSlots: a picture or a piece of text, with the slot's number and colour.

Declaration Summary
val index: Int The slot's position, from 0; the widget shows index + 1.
val kind: Kind Whether the slot takes a picture or a piece of text.
val color: String The slot's CSS colour, which a drawing of the result should reuse.
val label: String The picture's file name without its extension, or, for a text slot, the text itself.
val image: BufferedImage? The picture, for an image slot that is filled, and null for one that is not.
val text: String The text, for a text slot; empty for an image slot.
val file: File? Where the picture came from, when it came from a file on this machine rather than a drop.
enum class Kind A picture slot or a text slot.
val isEmpty: Boolean Whether there is nothing in the slot yet.
fun clip(): ClipVector The slot's CLIP embedding: clipEncodeImage for a picture, clipEncode for text. Both land in the same 512-dimensional space, so a picture and a sentence can be compared.
override fun toString(): String The slot's number as the widget shows it, its kind and its label, and whether it is empty.

MediaSlotsBuilder

class MediaSlotsBuilder internal constructor(private val colors: List<String>)

The receiver of Box.mediaSlots's block: one call per slot, in order, and any trays.

Declaration Summary
fun image(path: String) A picture slot holding the image at path (relative to Field's working directory, or absolute).
fun image() An empty picture slot, to be filled by a drop.
fun text(initial: String = "") A text slot, starting with initial.
fun tray(folder: String) Put every picture in folder (JPEG, PNG, GIF, BMP; not its subfolders) in the tray, by name.