Skip to content

Instantly share code, notes, and snippets.

View halilozercan's full-sized avatar
🏛️
Learning

Halil Ozercan halilozercan

🏛️
Learning
View GitHub Profile
@halilozercan
halilozercan / Screenshot.kt
Created October 2, 2023 23:07
Drawing composables onto an ImageBitmap
import android.graphics.Bitmap
import android.graphics.Picture
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.graphics.Canvas
@halilozercan
halilozercan / DrawGlyphs.kt
Created October 1, 2023 20:30
A Set of helper functions and classes to draw each individual glyph separately
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ImageBitmap
@halilozercan
halilozercan / Varimoji.kt
Created September 22, 2023 19:15
Variable Font Emoji in Compose
// Download the varimoji font from https://crt-mate.github.io/varimoji/varimojiVF.woff2
// Convert it to TTF and put that under res/font/
@OptIn(ExperimentalTextApi::class)
@Composable
fun VariableFontEmoji() {
var actv by remember { mutableFloatStateOf(50f) }
var vlnc by remember { mutableFloatStateOf(50f) }
Column(
modifier = Modifier.padding(32.dp),
/**
* - Requires two frames
* - Need to hide BasicText from view
* - Unnecessary extra composition, way too hacky
* - Can do everything that a BasicText can do
* - Constraints must be applied to BasicText
*/
@Composable
fun UsingBasicText() {
Box(Modifier.fillMaxSize()) {
@Composable
fun Parent() {
Column {
var length by remember { mutableStateOf(1) }
val stringy by remember { derivedStateOf { { "a".repeat(length) } } }
ThingCounter(stringy)
Button(onClick = { length++ }) {
Text(text = "Change stringy")
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group.contains('org.jetbrains.compose')) {
def groupName = details.requested.group.replace("org.jetbrains.compose", "androidx.compose")
details.useTarget(
[group: groupName, name: details.requested.name, version: details.requested.version]
)
}
}
}
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.desktop.Window
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
@Composable
fun <T: Comparable<T>> SlideInOutLayout(
targetState: T,
modifier: Modifier = Modifier,
animationSpec: FiniteAnimationSpec<Float> = tween(),
content: @Composable (T) -> Unit
) {
val items = remember { mutableStateListOf<CrossSlideAnimationItem<T>>() }
val transitionState = remember { MutableTransitionState(targetState) }
val targetChanged = (targetState != transitionState.targetState)
@Composable
fun CalendarView(
modifier: Modifier = Modifier,
selectedDay: CalendarDay = CalendarDay.create(),
onSelectedDayChange: (CalendarDay) -> Unit = {},
visibleMonth: CalendarDay = CalendarDay.create(),
onVisibleMonthChange: (CalendarDay) -> Unit = {},
today: CalendarDay = CalendarDay.create(),
events: Set<CalendarDay> = emptySet()
) {
/**
* This interface marks the class for use of `Rizalt` library.
*/
interface Rizalt<P: Parcelable>
/**
* Creates a unique request key for given Fragment class. Key can be left empty
* to create a default instance.
*/
fun <T, P: Parcelable> KClass<T>.getRequestKeyNameFor(key: String): String where T: Fragment, T: Rizalt<P> {