All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.nacular.doodle.theme.material.MaterialButtonBehavior.kt Maven / Gradle / Ivy

The newest version!
package io.nacular.doodle.theme.material

import io.nacular.doodle.animation.Animation
import io.nacular.doodle.animation.Animator
import io.nacular.doodle.animation.Animator.Listener
import io.nacular.doodle.animation.invoke
import io.nacular.doodle.animation.transition.easeInOutCubic
import io.nacular.doodle.animation.transition.linear
import io.nacular.doodle.animation.tweenDouble
import io.nacular.doodle.animation.tweenFloat
import io.nacular.doodle.controls.buttons.Button
import io.nacular.doodle.controls.buttons.ButtonModel
import io.nacular.doodle.controls.theme.CommonTextButtonBehavior
import io.nacular.doodle.core.View
import io.nacular.doodle.drawing.Canvas
import io.nacular.doodle.drawing.Color
import io.nacular.doodle.drawing.Color.Companion.Black
import io.nacular.doodle.drawing.Color.Companion.White
import io.nacular.doodle.drawing.ColorPaint
import io.nacular.doodle.drawing.Font.Companion.Thick
import io.nacular.doodle.drawing.FontLoader
import io.nacular.doodle.drawing.TextMetrics
import io.nacular.doodle.drawing.opacity
import io.nacular.doodle.event.PointerEvent
import io.nacular.doodle.event.PointerListener
import io.nacular.doodle.focus.FocusManager
import io.nacular.doodle.geometry.Circle
import io.nacular.doodle.geometry.Point
import io.nacular.doodle.layout.Insets
import io.nacular.doodle.scheduler.Scheduler
import io.nacular.doodle.theme.material.MaterialTheme.Companion.FontConfig
import io.nacular.doodle.utils.Cancelable
import io.nacular.measured.units.Time.Companion.milliseconds
import io.nacular.measured.units.times
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.math.max
import kotlin.math.pow
import kotlin.math.sqrt

/**
 * Created by Nicholas Eddy on 12/10/19.
 */
internal fun drawRipple(on: Canvas, at: Point, opacity: Float, progress: Float) {
    val x = max(at.x, on.size.width  - at.x)
    val y = max(at.y, on.size.height - at.y)

    val maxRadius = sqrt(x.pow(2) + y.pow(2))

    on.circle(Circle(radius = maxRadius * progress, center = at), ColorPaint(White opacity opacity))
}

public class MaterialButtonBehavior(
                    textMetrics    : TextMetrics,
        private val animate        : Animator,
        private val scheduler      : Scheduler,
        private val fontConfig     : FontConfig?,
        private val fonts          : FontLoader,
        private val textColor      : Color,
        private val backgroundColor: Color,
        private val cornerRadius   : Double        = 0.0,
                    focusManager   : FocusManager? = null): CommonTextButtonBehavior




© 2015 - 2024 Weber Informatics LLC | Privacy Policy