UseCase

class UseCase

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun addElement(element: Element, currentElements: List<Element>): List<Element>
Link copied to clipboard
fun bringToFront(elements: List<Element>, ids: Set<String>): List<Element>

Promote selected elements to the top of the z-order.

Link copied to clipboard
fun deleteElement(elementId: String, currentElements: List<Element>): List<Element>
Link copied to clipboard
fun deleteSelected(elements: List<Element>, ids: Set<String>): List<Element>

Delete every element whose id is in ids.

Link copied to clipboard
fun eraseAt(elements: List<Element>, point: Offset, radius: Float): List<Element>

Remove every element whose body is within radius of point. Reuses the same hitTest used by selection, with the eraser disk radius substituted for the pick tolerance — which means stroke width is already accounted for. Returns the original list instance when nothing was hit so callers can skip useless state churn.

Link copied to clipboard
fun finalizeArrowBindings(elements: List<Element>, arrowId: String): List<Element>

Attach connector bindings to an arrow: each endpoint binds to the topmost non-arrow/line shape it sits inside, or to null if it sits in empty space. When this call is what FIRST makes the arrow connect both endpoints, it also seeds a default perpendicular bend so the connector reads as a curve rather than overlapping with the straight center-to-center line.

Link copied to clipboard
fun hitTopmost(elements: List<Element>, point: Offset, tolerance: Float): Element?

Topmost element at point, or null if nothing was hit.

Link copied to clipboard
fun insertImage(bytes: ByteArray, position: Offset, intrinsicSize: Size): Element.Image
Link copied to clipboard
fun insertNewPath(offset: Offset, color: Color, width: Float, alpha: Float, strokeStyle: StrokeStyle = StrokeStyle.SOLID, pressure: Float = 1.0f): Element.Path
Link copied to clipboard
fun insertNewShape(shapeType: ShapeType, offset: Offset, color: Color, width: Float, cornerRadius: Float = 0.0f, strokeStyle: StrokeStyle = StrokeStyle.SOLID, fillColor: Color? = null, strokeEnabled: Boolean = true): Element.Shape
Link copied to clipboard
fun insertText(text: String, position: Offset, fontSize: Float, fontFamilyKey: String, alignment: TextAlignment, color: Color): Element.Text
Link copied to clipboard

Update every arrow's endpoints so they terminate on the bound shape's boundary along the line toward the other endpoint (or its bound center). Idempotent — safe to call after any element mutation. Detaches bindings whose target no longer exists.

Link copied to clipboard
fun resizeSingle(elements: List<Element>, id: String, handle: ResizeHandle, pointer: Offset): List<Element>

Recompute new bounds from a resize-handle drag and apply them. Single- element only; multi-selection callers should iterate or refuse.

Link copied to clipboard
fun selectInRect(elements: List<Element>, rect: Rect): Set<String>

Set of element IDs whose bounding box intersects rect.

Link copied to clipboard
fun sendToBack(elements: List<Element>, ids: Set<String>): List<Element>

Push selected elements to the bottom of the z-order.

Link copied to clipboard
fun setElementBounds(elements: List<Element>, id: String, bounds: Rect): List<Element>

Replace the bounds of a single element.

Link copied to clipboard
fun setElementPoints(elements: List<Element>, id: String, newPoints: List<Offset>): List<Element>

Overwrite the points list of a single element.

Link copied to clipboard
fun setElementRotation(elements: List<Element>, id: String, degrees: Float): List<Element>

Replace the rotation of a single element (degrees).

Link copied to clipboard
fun setLineBend(elements: List<Element>, id: String, bend: Offset): List<Element>

Update the curve deflection of a single LINE/ARROW shape.

Link copied to clipboard
fun setSelectedCornerRadius(elements: List<Element>, ids: Set<String>, radius: Float): List<Element>

Set the corner radius on selected RECTANGLE / TRIANGLE shapes. Other element types in the selection are left untouched.

Link copied to clipboard
fun setSelectedFillColor(elements: List<Element>, ids: Set<String>, color: Color?): List<Element>

Set the fill color of every selected shape. null clears the fill so the shape renders stroke-only. Paths and images have no fill concept and are left untouched — multi-selecting a mix still works.

Link copied to clipboard
fun setSelectedFontFamily(elements: List<Element>, ids: Set<String>, fontFamilyKey: String): List<Element>

Set font family key on every selected Element.Text.

Link copied to clipboard
fun setSelectedFontSize(elements: List<Element>, ids: Set<String>, size: Float): List<Element>

Set font size on every selected Element.Text.

Link copied to clipboard
fun setSelectedStrokeColor(elements: List<Element>, ids: Set<String>, color: Color): List<Element>

Recolor every selected element's stroke.

Link copied to clipboard
fun setSelectedStrokeEnabled(elements: List<Element>, ids: Set<String>, enabled: Boolean): List<Element>

Toggle the stroke pass on every selected shape. Paths are always stroked, so they're left untouched.

Link copied to clipboard

Set the stroke pattern on every selected element (shape OR freehand path).

Link copied to clipboard
fun setSelectedStrokeWidth(elements: List<Element>, ids: Set<String>, width: Float): List<Element>

Re-stroke every selected element.

Link copied to clipboard

Set text alignment on every selected Element.Text.

Link copied to clipboard
fun syncTextMeasuredHeight(elements: List<Element>, id: String, height: Float): List<Element>

Renderer-driven height sync — the canvas measures a text block, sees the rendered height differs from Element.Text.measuredHeight and dispatches io.ak1.drawbox.domain.model.Intent.SyncTextMeasuredHeight to bring the model in line. Bypasses history so this fixed-point convergence doesn't consume undo slots.

Link copied to clipboard
fun translateSelected(elements: List<Element>, ids: Set<String>, delta: Offset): List<Element>

Translate every element whose id is in ids by delta.

Link copied to clipboard
fun updateElement(element: Element, currentElements: List<Element>): List<Element>
Link copied to clipboard
fun updateLatestPath(newPoint: Offset, currentElements: List<Element>, pressure: Float = 1.0f): List<Element>
Link copied to clipboard
fun updateLatestShape(newPoint: Offset, currentElements: List<Element>): List<Element>
Link copied to clipboard
fun updateText(elements: List<Element>, id: String, text: String): List<Element>

Replace the text field of a single Element.Text. Snapshots history.