Igor Demin
4 years ago
20 changed files with 88 additions and 180 deletions
@ -1,31 +1,14 @@ |
|||||||
package org.jetbrains.codeviewer.platform |
package org.jetbrains.codeviewer.platform |
||||||
|
|
||||||
import android.graphics.BitmapFactory |
|
||||||
import androidx.compose.runtime.Composable |
import androidx.compose.runtime.Composable |
||||||
import androidx.compose.ui.graphics.ImageBitmap |
import androidx.compose.ui.platform.LocalContext |
||||||
import androidx.compose.ui.graphics.asImageBitmap |
|
||||||
import androidx.compose.ui.platform.AmbientContext |
|
||||||
import androidx.compose.ui.text.font.Font |
import androidx.compose.ui.text.font.Font |
||||||
import androidx.compose.ui.text.font.FontStyle |
import androidx.compose.ui.text.font.FontStyle |
||||||
import androidx.compose.ui.text.font.FontWeight |
import androidx.compose.ui.text.font.FontWeight |
||||||
import java.io.InputStream |
|
||||||
import java.net.URL |
|
||||||
|
|
||||||
@Composable |
|
||||||
actual fun imageResource(res: String): ImageBitmap { |
|
||||||
val context = AmbientContext.current |
|
||||||
val id = context.resources.getIdentifier(res, "drawable", context.packageName) |
|
||||||
return androidx.compose.ui.res.imageResource(id) |
|
||||||
} |
|
||||||
|
|
||||||
actual suspend fun imageFromUrl(url: String): ImageBitmap { |
|
||||||
val bytes = URL(url).openStream().buffered().use(InputStream::readBytes) |
|
||||||
return BitmapFactory.decodeByteArray(bytes, 0, bytes.size).asImageBitmap() |
|
||||||
} |
|
||||||
|
|
||||||
@Composable |
@Composable |
||||||
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { |
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { |
||||||
val context = AmbientContext.current |
val context = LocalContext.current |
||||||
val id = context.resources.getIdentifier(res, "font", context.packageName) |
val id = context.resources.getIdentifier(res, "font", context.packageName) |
||||||
return androidx.compose.ui.text.font.Font(id, weight, style) |
return Font(id, weight, style) |
||||||
} |
} |
@ -1,19 +0,0 @@ |
|||||||
package org.jetbrains.codeviewer.platform |
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable |
|
||||||
import androidx.compose.runtime.mutableStateOf |
|
||||||
import androidx.compose.runtime.remember |
|
||||||
import androidx.compose.ui.selection.Selection |
|
||||||
import androidx.compose.ui.selection.SelectionContainer |
|
||||||
import androidx.compose.ui.text.InternalTextApi |
|
||||||
|
|
||||||
@OptIn(InternalTextApi::class) |
|
||||||
@Composable |
|
||||||
actual fun SelectionContainer(children: @Composable () -> Unit) { |
|
||||||
val selection = remember { mutableStateOf<Selection?>(null) } |
|
||||||
SelectionContainer( |
|
||||||
selection = selection.value, |
|
||||||
onSelectionChange = { selection.value = it }, |
|
||||||
children = children |
|
||||||
) |
|
||||||
} |
|
@ -1,15 +1,9 @@ |
|||||||
package org.jetbrains.codeviewer.platform |
package org.jetbrains.codeviewer.platform |
||||||
|
|
||||||
import androidx.compose.runtime.Composable |
import androidx.compose.runtime.Composable |
||||||
import androidx.compose.ui.graphics.ImageBitmap |
|
||||||
import androidx.compose.ui.text.font.Font |
import androidx.compose.ui.text.font.Font |
||||||
import androidx.compose.ui.text.font.FontStyle |
import androidx.compose.ui.text.font.FontStyle |
||||||
import androidx.compose.ui.text.font.FontWeight |
import androidx.compose.ui.text.font.FontWeight |
||||||
|
|
||||||
@Composable |
|
||||||
expect fun imageResource(res: String): ImageBitmap |
|
||||||
|
|
||||||
expect suspend fun imageFromUrl(url: String): ImageBitmap |
|
||||||
|
|
||||||
@Composable |
@Composable |
||||||
expect fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font |
expect fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font |
@ -1,6 +0,0 @@ |
|||||||
package org.jetbrains.codeviewer.platform |
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable |
|
||||||
|
|
||||||
@Composable |
|
||||||
expect fun SelectionContainer(children: @Composable () -> Unit) |
|
@ -1,33 +0,0 @@ |
|||||||
package org.jetbrains.codeviewer.util |
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues |
|
||||||
import androidx.compose.foundation.lazy.LazyColumnForIndexed |
|
||||||
import androidx.compose.foundation.lazy.LazyItemScope |
|
||||||
import androidx.compose.foundation.lazy.LazyListState |
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState |
|
||||||
import androidx.compose.runtime.Composable |
|
||||||
import androidx.compose.ui.Alignment |
|
||||||
import androidx.compose.ui.Modifier |
|
||||||
import androidx.compose.ui.unit.dp |
|
||||||
|
|
||||||
@Composable |
|
||||||
fun LazyColumnFor( |
|
||||||
size: Int, |
|
||||||
modifier: Modifier = Modifier, |
|
||||||
state: LazyListState = rememberLazyListState(), |
|
||||||
contentPadding: PaddingValues = PaddingValues(0.dp), |
|
||||||
horizontalAlignment: Alignment.Horizontal = Alignment.Start, |
|
||||||
itemContent: @Composable LazyItemScope.(index: Int) -> Unit |
|
||||||
) = LazyColumnForIndexed( |
|
||||||
items = UnitList(size), |
|
||||||
modifier = modifier, |
|
||||||
state = state, |
|
||||||
contentPadding = contentPadding, |
|
||||||
horizontalAlignment = horizontalAlignment, |
|
||||||
) { index, _ -> |
|
||||||
itemContent(index) |
|
||||||
} |
|
||||||
|
|
||||||
private class UnitList(override val size: Int) : AbstractList<Unit>() { |
|
||||||
override fun get(index: Int) = Unit |
|
||||||
} |
|
@ -1,24 +1,9 @@ |
|||||||
package org.jetbrains.codeviewer.platform |
package org.jetbrains.codeviewer.platform |
||||||
|
|
||||||
import androidx.compose.runtime.Composable |
import androidx.compose.runtime.Composable |
||||||
import androidx.compose.ui.graphics.ImageBitmap |
|
||||||
import androidx.compose.ui.graphics.asImageBitmap |
|
||||||
import androidx.compose.ui.text.font.Font |
import androidx.compose.ui.text.font.Font |
||||||
import androidx.compose.ui.text.font.FontStyle |
import androidx.compose.ui.text.font.FontStyle |
||||||
import androidx.compose.ui.text.font.FontWeight |
import androidx.compose.ui.text.font.FontWeight |
||||||
import kotlinx.coroutines.Dispatchers |
|
||||||
import kotlinx.coroutines.withContext |
|
||||||
import org.jetbrains.skija.Image |
|
||||||
import java.io.InputStream |
|
||||||
import java.net.URL |
|
||||||
|
|
||||||
@Composable |
|
||||||
actual fun imageResource(res: String) = androidx.compose.ui.res.imageResource("drawable/$res.png") |
|
||||||
|
|
||||||
actual suspend fun imageFromUrl(url: String): ImageBitmap = withContext(Dispatchers.IO) { |
|
||||||
val bytes = URL(url).openStream().buffered().use(InputStream::readBytes) |
|
||||||
Image.makeFromEncoded(bytes).asImageBitmap() |
|
||||||
} |
|
||||||
|
|
||||||
@Composable |
@Composable |
||||||
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font = |
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font = |
||||||
|
@ -1,9 +0,0 @@ |
|||||||
package org.jetbrains.codeviewer.platform |
|
||||||
|
|
||||||
import androidx.compose.foundation.text.selection.DesktopSelectionContainer |
|
||||||
import androidx.compose.runtime.Composable |
|
||||||
|
|
||||||
@Composable |
|
||||||
actual fun SelectionContainer(children: @Composable () -> Unit) { |
|
||||||
DesktopSelectionContainer(content = children) |
|
||||||
} |
|
Loading…
Reference in new issue