Modern Apps git

← Modern-Apps.git

office: UI fixes

Commit
ebb097ceb8e73b5378742e679014d002b278ea05
Author
Vayun Mathur <[email protected]>
When
2026-06-21 04:34 UTC (5 months ago)
Parents
00cc27b

Diff

office/src/main/java/com/vayunmathur/office/MainActivity.kt
diff --git a/office/src/main/java/com/vayunmathur/office/MainActivity.kt b/office/src/main/java/com/vayunmathur/office/MainActivity.ktindex a9f0648c24..576f80708d 100644--- a/office/src/main/java/com/vayunmathur/office/MainActivity.kt+++ b/office/src/main/java/com/vayunmathur/office/MainActivity.kt@@ -221,9 +221,13 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity:     var showCellTextColor by remember { mutableStateOf(false) }     var showCellBgColor by remember { mutableStateOf(false) }     var showSlideTextColor by remember { mutableStateOf(false) }+    var showSlideFillColor by remember { mutableStateOf(false) }+    var showSlideStrokeColor by remember { mutableStateOf(false) }     var chartForSlide by remember { mutableStateOf(false) }     var chartForSheet by remember { mutableStateOf(false) }     var cropImageBlock by remember { mutableIntStateOf(-1) }+    var cropSlideTarget by remember { mutableStateOf<Pair<Int, Int>?>(null) }+    var cropSheetTarget by remember { mutableStateOf<Pair<Int, Int>?>(null) }      val isEditMode by viewModel.isEditMode.collectAsState()     val hasUnsavedChanges by viewModel.hasUnsavedChanges.collectAsState()@@ -463,6 +467,8 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity:                         onCellTextColor = { showCellTextColor = true },                         onCellBgColor = { showCellBgColor = true },                         onSlideTextColor = { showSlideTextColor = true },+                        onSlideFill = { showSlideFillColor = true },+                        onSlideStroke = { showSlideStrokeColor = true },                         onFontSize = { showFontSizePicker = true },                         onInsertImage = { imagePickerLauncher.launch("image/*") },                         onInsertShape = { kind ->@@ -500,7 +506,8 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity:                         onCellSelected = { s, r, c -> activeCell = Triple(s, r, c) },                         onFloatingBoundsChange = { s, e, x, y, w, h -> viewModel.setSheetElementBounds(s, e, x, y, w, h) },                         onFloatingTextChange = { s, e, t -> viewModel.updateSheetElementText(s, e, t) },-                        onFloatingDelete = { s, e -> viewModel.deleteSheetElement(s, e) })+                        onFloatingDelete = { s, e -> viewModel.deleteSheetElement(s, e) },+                        onFloatingCrop = { s, e -> cropSheetTarget = s to e })                     is OdfDocument.Presentation -> PresentationView(doc = document, isEditMode = isEditMode,                         onAddSlide = { viewModel.addSlide(it) }, onDeleteSlide = { viewModel.deleteSlide(it) },                         onDuplicateSlide = { viewModel.duplicateSlide(it) }, onMoveSlideUp = { viewModel.moveSlideUp(it) }, onMoveSlideDown = { viewModel.moveSlideDown(it) },@@ -509,7 +516,8 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity:                         onDeleteElement = { s, e -> viewModel.deleteSlideElement(s, e) },                         selectedElement = activeSlideEl,                         onSlideChange = { activeSlide = it },-                        onElementSelected = { s, e -> activeSlide = s; activeSlideEl = e })+                        onElementSelected = { s, e -> activeSlide = s; activeSlideEl = e },+                        onCropImage = { s, e -> cropSlideTarget = s to e })                     is OdfDocument.Drawing -> DrawingView(document)                 }             }@@ -553,11 +561,27 @@ fun DocumentScreen(document: OdfDocument, viewModel: OfficeViewModel, activity:     if (showSlideTextColor && activeSlideEl >= 0) {         ColorPickerDialog("Text Color", onColorSelected = { viewModel.setSlideElementColor(activeSlide, activeSlideEl, it) }, onDismiss = { showSlideTextColor = false })     }+    if (showSlideFillColor && activeSlideEl >= 0) {+        ColorPickerDialog("Fill Color", onColorSelected = { viewModel.setSlideElementFill(activeSlide, activeSlideEl, it) }, onDismiss = { showSlideFillColor = false })+    }+    if (showSlideStrokeColor && activeSlideEl >= 0) {+        ColorPickerDialog("Border Color", onColorSelected = { viewModel.setSlideElementStroke(activeSlide, activeSlideEl, it) }, onDismiss = { showSlideStrokeColor = false })+    }     if (cropImageBlock >= 0) {         val img = ((document as? OdfDocument.TextDocument)?.content?.getOrNull(cropImageBlock) as? OdfContentBlock.Image)?.image         if (img != null) ImageCropDialog(image = img, onApply = { l, t, r, b -> viewModel.setImageCrop(cropImageBlock, l, t, r, b) }, onDismiss = { cropImageBlock = -1 })         else cropImageBlock = -1     }+    cropSlideTarget?.let { (s, e) ->+        val img = ((document as? OdfDocument.Presentation)?.slides?.getOrNull(s)?.elements?.getOrNull(e) as? OdfSlideElement.Frame)?.frame?.image+        if (img != null) ImageCropDialog(image = img, onApply = { l, t, r, b -> viewModel.setSlideImageCrop(s, e, l, t, r, b) }, onDismiss = { cropSlideTarget = null })+        else cropSlideTarget = null+    }+    cropSheetTarget?.let { (s, e) ->+        val img = ((document as? OdfDocument.Spreadsheet)?.sheets?.getOrNull(s)?.floating?.getOrNull(e) as? OdfSlideElement.Frame)?.frame?.image+        if (img != null) ImageCropDialog(image = img, onApply = { l, t, r, b -> viewModel.setSheetImageCrop(s, e, l, t, r, b) }, onDismiss = { cropSheetTarget = null })+        else cropSheetTarget = null+    }     if (showChartEditor) {         val existing = if (!chartForSlide && editingChartBlock >= 0) ((document as? OdfDocument.TextDocument)?.content?.getOrNull(editingChartBlock) as? OdfContentBlock.Chart)?.chart else null         ChartEditorDialog(
office/src/main/java/com/vayunmathur/office/odf/OdfSerializer.kt
diff --git a/office/src/main/java/com/vayunmathur/office/odf/OdfSerializer.kt b/office/src/main/java/com/vayunmathur/office/odf/OdfSerializer.ktindex c396753efa..493d547c35 100644--- a/office/src/main/java/com/vayunmathur/office/odf/OdfSerializer.kt+++ b/office/src/main/java/com/vayunmathur/office/odf/OdfSerializer.kt@@ -99,7 +99,7 @@ object OdfSerializer {         }         if (listOpen) body.append("</text:list>") -        return buildDocument("office:text", styles, paraStyles, LinkedHashMap(), LinkedHashMap(), body.toString())+        return buildDocument("office:text", styles, paraStyles, LinkedHashMap(), LinkedHashMap(), LinkedHashMap(), body.toString())     }      private fun serializeSpreadsheet(doc: OdfDocument.Spreadsheet): String {@@ -107,6 +107,7 @@ object OdfSerializer {         val colStyles = LinkedHashMap<String, Float>()         val spanStyles = mutableMapOf<String, SpanStyleDef>()         val paraStyles = mutableMapOf<String, ParaStyleDef>()+        val graphicStyles = LinkedHashMap<String, GraphicStyleDef>()         val body = StringBuilder()         for (sheet in doc.sheets) {             body.append("""<table:table table:name="${esc(sheet.name)}">""")@@ -148,30 +149,31 @@ object OdfSerializer {             // Floating objects anchored to the sheet (Phase 4).             for (element in sheet.floating) {                 when (element) {-                    is OdfSlideElement.Frame -> serializeFrame(body, element.frame, spanStyles, paraStyles)-                    is OdfSlideElement.Shape -> serializeShape(body, element.shape, spanStyles, paraStyles)+                    is OdfSlideElement.Frame -> serializeFrame(body, element.frame, spanStyles, paraStyles, graphicStyles)+                    is OdfSlideElement.Shape -> serializeShape(body, element.shape, spanStyles, paraStyles, graphicStyles)                 }             }             body.append("</table:table>")         }-        return buildDocument("office:spreadsheet", spanStyles, paraStyles, cellStyles, colStyles, body.toString())+        return buildDocument("office:spreadsheet", spanStyles, paraStyles, cellStyles, colStyles, graphicStyles, body.toString())     }      private fun serializePresentation(doc: OdfDocument.Presentation): String {         val styles = mutableMapOf<String, SpanStyleDef>()         val paraStyles = mutableMapOf<String, ParaStyleDef>()+        val graphicStyles = LinkedHashMap<String, GraphicStyleDef>()         val body = StringBuilder()         for (slide in doc.slides) {             body.append("""<draw:page draw:name="${esc(slide.name)}">""")             for (element in slide.elements) {                 when (element) {-                    is OdfSlideElement.Frame -> serializeFrame(body, element.frame, styles, paraStyles)-                    is OdfSlideElement.Shape -> serializeShape(body, element.shape, styles, paraStyles)+                    is OdfSlideElement.Frame -> serializeFrame(body, element.frame, styles, paraStyles, graphicStyles)+                    is OdfSlideElement.Shape -> serializeShape(body, element.shape, styles, paraStyles, graphicStyles)                 }             }             body.append("</draw:page>")         }-        return buildDocument("office:presentation", styles, paraStyles, LinkedHashMap(), LinkedHashMap(), body.toString())+        return buildDocument("office:presentation", styles, paraStyles, LinkedHashMap(), LinkedHashMap(), graphicStyles, body.toString())     }      private fun serializeParagraph(@@ -266,10 +268,12 @@ object OdfSerializer {     private fun serializeFrame(         sb: StringBuilder, frame: OdfFrame,         styles: MutableMap<String, SpanStyleDef>,-        paraStyles: MutableMap<String, ParaStyleDef>+        paraStyles: MutableMap<String, ParaStyleDef>,+        graphicStyles: MutableMap<String, GraphicStyleDef>     ) {         sb.append("<draw:frame")-        sb.append(""" svg:x="${frame.x / 37.8f}cm" svg:y="${frame.y / 37.8f}cm"""")+        getOrCreateGraphicStyle(frame.fillColor, frame.strokeColor, frame.strokeWidth, graphicStyles)?.let { sb.append(""" draw:style-name="$it"""") }+        sb.append(""" svg:x="${frame.x / 37.8f}cm" svg:y="${frame.y / 37.8f}cm""")         sb.append(""" svg:width="${frame.width / 37.8f}cm" svg:height="${frame.height / 37.8f}cm"""")         if (frame.image != null) appendClip(sb, frame.image)         sb.append(">")@@ -293,7 +297,8 @@ object OdfSerializer {     private fun serializeShape(         sb: StringBuilder, shape: OdfShape,         styles: MutableMap<String, SpanStyleDef>,-        paraStyles: MutableMap<String, ParaStyleDef>+        paraStyles: MutableMap<String, ParaStyleDef>,+        graphicStyles: MutableMap<String, GraphicStyleDef>     ) {         val tag = when (shape) {             is OdfShape.Rect -> "draw:rect"@@ -302,7 +307,8 @@ object OdfSerializer {             is OdfShape.CustomShape -> "draw:custom-shape"         }         sb.append("<$tag")-        sb.append(""" svg:x="${shape.x / 37.8f}cm" svg:y="${shape.y / 37.8f}cm"""")+        getOrCreateGraphicStyle(shape.fillColor, shape.strokeColor, shape.strokeWidth, graphicStyles)?.let { sb.append(""" draw:style-name="$it"""") }+        sb.append(""" svg:x="${shape.x / 37.8f}cm" svg:y="${shape.y / 37.8f}cm""")         sb.append(""" svg:width="${shape.width / 37.8f}cm" svg:height="${shape.height / 37.8f}cm"""")         sb.append(">")         for (para in shape.text) serializeParagraph(sb, para, styles, paraStyles, "text:p")@@ -333,6 +339,19 @@ object OdfSerializer {         val alignment: TextAlign? = null, val borderColor: Long? = null     ) +    private data class GraphicStyleDef(+        val fillColor: Long? = null, val strokeColor: Long? = null, val strokeWidth: Float? = null+    )++    private fun getOrCreateGraphicStyle(fillColor: Long?, strokeColor: Long?, strokeWidth: Float?, styles: MutableMap<String, GraphicStyleDef>): String? {+        if (fillColor == null && strokeColor == null && strokeWidth == null) return null+        val def = GraphicStyleDef(fillColor, strokeColor, strokeWidth)+        for ((name, existing) in styles) if (existing == def) return name+        val name = "gr${styles.size + 1}"+        styles[name] = def+        return name+    }+     private fun getOrCreateCellStyle(cell: OdfCell, styles: MutableMap<String, CellStyleDef>): String? {         if (cell.backgroundColor == null && cell.textColor == null && !cell.bold && !cell.italic &&             cell.alignment == null && cell.borderColor == null) return null@@ -378,6 +397,7 @@ object OdfSerializer {         paraStyles: Map<String, ParaStyleDef>,         cellStyles: Map<String, CellStyleDef>,         colStyles: Map<String, Float>,+        graphicStyles: Map<String, GraphicStyleDef>,         bodyContent: String     ): String {         val sb = StringBuilder()@@ -444,6 +464,14 @@ object OdfSerializer {             if (def.textColor != null) sb.append(""" fo:color="${formatColor(def.textColor)}"""")             sb.append("/></style:style>")         }+        for ((name, def) in graphicStyles) {+            sb.append("""<style:style style:name="$name" style:family="graphic"><style:graphic-properties""")+            if (def.fillColor != null) sb.append(""" draw:fill="solid" draw:fill-color="${formatColor(def.fillColor)}"""")+            else sb.append(""" draw:fill="none"""")+            if (def.strokeColor != null) sb.append(""" draw:stroke="solid" svg:stroke-color="${formatColor(def.strokeColor)}"""")+            if (def.strokeWidth != null) sb.append(""" svg:stroke-width="${def.strokeWidth / 37.8f}cm"""")+            sb.append("/></style:style>")+        }         sb.append("</office:automatic-styles>")          sb.append("<office:body><$bodyType>")
office/src/main/java/com/vayunmathur/office/ui/DocumentViews.kt
diff --git a/office/src/main/java/com/vayunmathur/office/ui/DocumentViews.kt b/office/src/main/java/com/vayunmathur/office/ui/DocumentViews.ktindex 878a8641a9..46e345241e 100644--- a/office/src/main/java/com/vayunmathur/office/ui/DocumentViews.kt+++ b/office/src/main/java/com/vayunmathur/office/ui/DocumentViews.kt@@ -23,7 +23,6 @@ import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.defaultMinSize import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.IntrinsicSize@@ -1260,7 +1259,8 @@ fun SpreadsheetView(     onCellSelected: (Int, Int, Int) -> Unit = { _, _, _ -> },     onFloatingBoundsChange: (Int, Int, Float, Float, Float, Float) -> Unit = { _, _, _, _, _, _ -> },     onFloatingTextChange: (Int, Int, String) -> Unit = { _, _, _ -> },-    onFloatingDelete: (Int, Int) -> Unit = { _, _ -> }+    onFloatingDelete: (Int, Int) -> Unit = { _, _ -> },+    onFloatingCrop: (Int, Int) -> Unit = { _, _ -> } ) {     if (doc.sheets.isEmpty()) { Text("Empty spreadsheet", modifier = Modifier.padding(16.dp)); return } @@ -1272,7 +1272,7 @@ fun SpreadsheetView(     var renameText by remember { mutableStateOf("") }     var showSortDialog by remember { mutableStateOf(false) } -    Column(modifier = Modifier.fillMaxSize().imePadding()) {+    Column(modifier = Modifier.fillMaxSize()) {         if (doc.sheets.size > 1 || isEditMode) {             Row(verticalAlignment = Alignment.CenterVertically) {                 PrimaryScrollableTabRow(selectedTabIndex = selectedSheet, modifier = Modifier.weight(1f)) {@@ -1391,7 +1391,8 @@ fun SpreadsheetView(                 onSelect = { selectedFloating = it },                 onElementTextChange = { ei, t -> onFloatingTextChange(selectedSheet, ei, t) },                 onBoundsChange = { ei, x, y, w, h -> onFloatingBoundsChange(selectedSheet, ei, x, y, w, h) },-                onDelete = { ei -> onFloatingDelete(selectedSheet, ei); selectedFloating = -1 }+                onDelete = { ei -> onFloatingDelete(selectedSheet, ei); selectedFloating = -1 },+                onCropImage = { ei -> onFloatingCrop(selectedSheet, ei) }             )         }         }@@ -1432,7 +1433,8 @@ fun PresentationView(     onDeleteElement: (Int, Int) -> Unit = { _, _ -> },     selectedElement: Int = -1,     onSlideChange: (Int) -> Unit = {},-    onElementSelected: (Int, Int) -> Unit = { _, _ -> }+    onElementSelected: (Int, Int) -> Unit = { _, _ -> },+    onCropImage: (Int, Int) -> Unit = { _, _ -> } ) {     if (doc.slides.isEmpty()) { Text("Empty presentation", modifier = Modifier.padding(16.dp)); return } @@ -1443,7 +1445,7 @@ fun PresentationView(     currentSlide = currentSlide.coerceIn(0, doc.slides.size - 1)     LaunchedEffect(currentSlide) { onSlideChange(currentSlide); onElementSelected(currentSlide, -1) } -    Column(modifier = Modifier.fillMaxSize().imePadding()) {+    Column(modifier = Modifier.fillMaxSize()) {         // Main slide with swipe gesture         Box(             modifier = Modifier.weight(1f).pointerInput(doc.slides.size) {@@ -1466,7 +1468,8 @@ fun PresentationView(                         onSelect = { onElementSelected(currentSlide, it) },                         onElementTextChange = { ei, t -> onElementTextChange(currentSlide, ei, t) },                         onBoundsChange = { ei, x, y, w, h -> onElementBoundsChange(currentSlide, ei, x, y, w, h) },-                        onDelete = { ei -> onDeleteElement(currentSlide, ei); onElementSelected(currentSlide, -1) }+                        onDelete = { ei -> onDeleteElement(currentSlide, ei); onElementSelected(currentSlide, -1) },+                        onCropImage = { ei -> onCropImage(currentSlide, ei) }                     )                 }             }@@ -1594,13 +1597,14 @@ private fun SlideCard(     onSelect: (Int) -> Unit = {},     onElementTextChange: (Int, String) -> Unit = { _, _ -> },     onBoundsChange: (Int, Float, Float, Float, Float) -> Unit = { _, _, _, _, _ -> },-    onDelete: (Int) -> Unit = {}+    onDelete: (Int) -> Unit = {},+    onCropImage: (Int) -> Unit = {} ) {     Column(modifier = Modifier.padding(vertical = 8.dp)) {         Text(slide.name, style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp))         val (refW, refH) = slideBounds(slide)         Card(modifier = Modifier.fillMaxWidth().aspectRatio((refW / refH).coerceIn(0.5f, 3f)).padding(horizontal = 8.dp), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)) {-            SlideCanvas(slide, refW, refH, editMode, selectedIndex, onSelect, onElementTextChange, onBoundsChange, onDelete)+            SlideCanvas(slide, refW, refH, editMode, selectedIndex, onSelect, onElementTextChange, onBoundsChange, onDelete, onCropImage)         }         if (slide.notes.isNotEmpty()) {             var expanded by remember { mutableStateOf(false) }@@ -1635,14 +1639,15 @@ private fun SlideCanvas(     onSelect: (Int) -> Unit = {},     onElementTextChange: (Int, String) -> Unit = { _, _ -> },     onBoundsChange: (Int, Float, Float, Float, Float) -> Unit = { _, _, _, _, _ -> },-    onDelete: (Int) -> Unit = {}+    onDelete: (Int) -> Unit = {},+    onCropImage: (Int) -> Unit = {} ) {     FloatingElementLayer(         elements = slide.elements, refW = refW, refH = refH,         editMode = editMode, selectedIndex = selectedIndex, keyPrefix = slide.name,         backgroundColor = slide.backgroundColor,         onSelect = onSelect, onElementTextChange = onElementTextChange,-        onBoundsChange = onBoundsChange, onDelete = onDelete+        onBoundsChange = onBoundsChange, onDelete = onDelete, onCropImage = onCropImage     ) } @@ -1664,7 +1669,8 @@ fun FloatingElementLayer(     onSelect: (Int) -> Unit = {},     onElementTextChange: (Int, String) -> Unit = { _, _ -> },     onBoundsChange: (Int, Float, Float, Float, Float) -> Unit = { _, _, _, _, _ -> },-    onDelete: (Int) -> Unit = {}+    onDelete: (Int) -> Unit = {},+    onCropImage: (Int) -> Unit = {} ) {     BoxWithConstraints(         Modifier.fillMaxSize()@@ -1739,6 +1745,15 @@ fun FloatingElementLayer(                         .clickable { onDelete(ei) }, contentAlignment = Alignment.Center) {                         Icon(painterResource(com.vayunmathur.library.R.drawable.delete_24px), contentDescription = "Delete element", tint = MaterialTheme.colorScheme.error, modifier = Modifier.size(14.dp))                     }+                    // Crop (top start, above the box) — only for image frames.+                    if (element is OdfSlideElement.Frame && element.frame.image != null) {+                        Box(Modifier.align(Alignment.TopStart).offset(x = (-12).dp, y = (-24).dp).size(22.dp)+                            .background(MaterialTheme.colorScheme.secondaryContainer, CircleShape)+                            .border(1.dp, MaterialTheme.colorScheme.secondary, CircleShape)+                            .clickable { onCropImage(ei) }, contentAlignment = Alignment.Center) {+                            Icon(painterResource(com.vayunmathur.library.R.drawable.crop_24px), contentDescription = "Crop image", tint = MaterialTheme.colorScheme.secondary, modifier = Modifier.size(14.dp))+                        }+                    }                 }             }         }
office/src/main/java/com/vayunmathur/office/ui/OfficeBottomBar.kt
diff --git a/office/src/main/java/com/vayunmathur/office/ui/OfficeBottomBar.kt b/office/src/main/java/com/vayunmathur/office/ui/OfficeBottomBar.ktindex e73f4fe6bd..9265b191fb 100644--- a/office/src/main/java/com/vayunmathur/office/ui/OfficeBottomBar.kt+++ b/office/src/main/java/com/vayunmathur/office/ui/OfficeBottomBar.kt@@ -61,6 +61,8 @@ data class BottomBarActions(     val onCellTextColor: () -> Unit = {},     val onCellBgColor: () -> Unit = {},     val onSlideTextColor: () -> Unit = {},+    val onSlideFill: () -> Unit = {},+    val onSlideStroke: () -> Unit = {},     val onFontSize: () -> Unit = {},     val onInsertImage: () -> Unit = {},     val onInsertShape: (ShapeKind) -> Unit = {},@@ -277,6 +279,8 @@ private fun ElementFormatControls(target: FormatTarget.Element?, viewModel: Offi     FmtIcon(R.drawable.format_italic_24px, false, enabled, "Italic") { if (enabled) viewModel.toggleSlideElementItalic(s, e) }     FmtIcon(R.drawable.format_underlined_24px, false, enabled, "Underline") { if (enabled) viewModel.toggleSlideElementUnderline(s, e) }     FmtIcon(R.drawable.format_color_text_24px, false, enabled, "Text color") { actions.onSlideTextColor() }+    TextButton(onClick = { actions.onSlideFill() }, enabled = enabled) { Text("Fill") }+    TextButton(onClick = { actions.onSlideStroke() }, enabled = enabled) { Text("Border") }     Box {         FmtIcon(R.drawable.format_align_left_24px, false, enabled, "Alignment") { alignMenu = true }         DropdownMenu(expanded = alignMenu, onDismissRequest = { alignMenu = false }) {
office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt
diff --git a/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt b/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.ktindex 8331da59bd..857498e42f 100644--- a/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt+++ b/office/src/main/java/com/vayunmathur/office/util/OfficeViewModel.kt@@ -1444,6 +1444,65 @@ class OfficeViewModel(application: Application) : AndroidViewModel(application)         updateDocument(doc.copy(slides = slides))     } +    /** Sets crop insets on an image frame element of a slide. (Phase 5) */+    fun setSlideImageCrop(slideIndex: Int, elementIndex: Int, left: Float, top: Float, right: Float, bottom: Float) {+        val doc = (_state.value as? ViewState.Loaded)?.document as? OdfDocument.Presentation ?: return+        val slides = doc.slides.toMutableList()+        val slide = slides.getOrNull(slideIndex) ?: return+        val elements = slide.elements.toMutableList()+        elements[elementIndex] = cropElementImage(elements.getOrNull(elementIndex) ?: return, left, top, right, bottom)+        slides[slideIndex] = slide.copy(elements = elements)+        updateDocument(doc.copy(slides = slides))+    }++    /** Sets crop insets on an image frame element of a sheet's floating layer. (Phase 5) */+    fun setSheetImageCrop(sheetIndex: Int, elementIndex: Int, left: Float, top: Float, right: Float, bottom: Float) {+        mutateSheetFloating(sheetIndex) { list ->+            if (elementIndex !in list.indices) list+            else list.toMutableList().also { it[elementIndex] = cropElementImage(it[elementIndex], left, top, right, bottom) }+        }+    }++    private fun cropElementImage(el: OdfSlideElement, l: Float, t: Float, r: Float, b: Float): OdfSlideElement =+        if (el is OdfSlideElement.Frame && el.frame.image != null)+            OdfSlideElement.Frame(el.frame.copy(image = el.frame.image.copy(cropLeftPct = l, cropTopPct = t, cropRightPct = r, cropBottomPct = b)))+        else el++    /** Sets fill color on a slide shape/frame element. (extra) */+    fun setSlideElementFill(slideIndex: Int, elementIndex: Int, color: Long?) =+        setSlideElementColors(slideIndex, elementIndex, fill = color, setFill = true)++    /** Sets stroke (border) color on a slide shape/frame element. (extra) */+    fun setSlideElementStroke(slideIndex: Int, elementIndex: Int, color: Long?) =+        setSlideElementColors(slideIndex, elementIndex, stroke = color, setStroke = true)++    private fun setSlideElementColors(slideIndex: Int, elementIndex: Int, fill: Long? = null, stroke: Long? = null, setFill: Boolean = false, setStroke: Boolean = false) {+        val doc = (_state.value as? ViewState.Loaded)?.document as? OdfDocument.Presentation ?: return+        val slides = doc.slides.toMutableList()+        val slide = slides.getOrNull(slideIndex) ?: return+        val elements = slide.elements.toMutableList()+        val el = elements.getOrNull(elementIndex) ?: return+        elements[elementIndex] = when (el) {+            is OdfSlideElement.Frame -> OdfSlideElement.Frame(el.frame.copy(+                fillColor = if (setFill) fill else el.frame.fillColor,+                strokeColor = if (setStroke) stroke else el.frame.strokeColor+            ))+            is OdfSlideElement.Shape -> {+                val s = el.shape+                val nf = if (setFill) fill else s.fillColor+                val ns = if (setStroke) stroke else s.strokeColor+                OdfSlideElement.Shape(when (s) {+                    is OdfShape.Rect -> s.copy(fillColor = nf, strokeColor = ns)+                    is OdfShape.Ellipse -> s.copy(fillColor = nf, strokeColor = ns)+                    is OdfShape.Line -> s.copy(fillColor = nf, strokeColor = ns)+                    is OdfShape.CustomShape -> s.copy(fillColor = nf, strokeColor = ns)+                })+            }+        }+        slides[slideIndex] = slide.copy(elements = elements)+        updateDocument(doc.copy(slides = slides))+    }+     // --- CSV export ---      fun exportCsv(): String {