Skip to content

Commit

Permalink
Make PixelImage global
Browse files Browse the repository at this point in the history
  • Loading branch information
reosfire committed Aug 11, 2024
1 parent ce57ac4 commit 0f8522c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
23 changes: 5 additions & 18 deletions src/main/kotlin/ru/reosfire/pixorio/filepicker/FilePicker.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package ru.reosfire.pixorio.filepicker

import androidx.compose.foundation.*
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
Expand All @@ -12,8 +15,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.res.useResource
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -25,6 +26,7 @@ import androidx.compose.ui.window.DialogWindow
import androidx.compose.ui.window.rememberDialogState
import ru.reosfire.pixorio.MainTheme
import ru.reosfire.pixorio.ui.components.basics.BasicButton
import ru.reosfire.pixorio.ui.components.basics.PixelImage
import java.io.File

data class FileNode(
Expand Down Expand Up @@ -191,18 +193,3 @@ private val RIGHT_ARROW_BITMAP = useResource("icons/filepicker/right_arrow.png")

private val FOLDER_BITMAP = useResource("icons/filepicker/folder.png") { loadImageBitmap(it) }
private val FILE_BITMAP = useResource("icons/filepicker/file.png") { loadImageBitmap(it) }

@Composable
fun PixelImage(
bitmap: ImageBitmap,
colorFilter: ColorFilter,
modifier: Modifier = Modifier,
) {
Image(
bitmap = bitmap,
contentDescription = null,
filterQuality = FilterQuality.None,
colorFilter = colorFilter,
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.reosfire.pixorio.ui.components.basics

import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.graphics.ImageBitmap

@Composable
fun PixelImage(
bitmap: ImageBitmap,
colorFilter: ColorFilter? = null,
modifier: Modifier = Modifier,
) {
Image(
bitmap = bitmap,
contentDescription = null,
filterQuality = FilterQuality.None,
colorFilter = colorFilter,
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ru.reosfire.pixorio.ui.components.brushes.palette

import androidx.compose.foundation.*
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.TooltipArea
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -12,11 +15,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.res.useResource
import androidx.compose.ui.unit.dp
import ru.reosfire.pixorio.brushes.AbstractBrush
import ru.reosfire.pixorio.ui.components.basics.PixelImage

data class BrushUiData(
val name: String,
Expand Down Expand Up @@ -63,14 +66,12 @@ private fun BrushItem(
Text(brush.name)
},
) {
Image(
PixelImage(
bitmap = useResource(brush.iconResource) { loadImageBitmap(it) },
contentDescription = brush.name.first().toString(),
filterQuality = FilterQuality.None,
modifier = modifier
.size(28.dp)
.then(if (isSelected) Modifier.border(1.dp, Color.White) else Modifier)
.clip(RoundedCornerShape(4.dp))
.then(if (isSelected) Modifier.border(1.dp, Color.White) else Modifier)
.clickable(onClick = onClick),
)
}
Expand Down

0 comments on commit 0f8522c

Please sign in to comment.