Skip to content

Commit

Permalink
Support for integrating application content into the window title pane
Browse files Browse the repository at this point in the history
For #23
  • Loading branch information
kirill-grouchnikov committed Nov 15, 2022
1 parent e2348d6 commit 0796041
Show file tree
Hide file tree
Showing 10 changed files with 838 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ internal fun AuroraTextField(
value = contentModel.value,
modifier = modifier
.defaultMinSize(
minWidth = TextFieldSizingConstants.MinWidth,
minHeight = TextFieldSizingConstants.MinHeight,
minWidth = presentationModel.defaultMinSize.width,
minHeight = presentationModel.defaultMinSize.height,
),
onValueChange = contentModel.onValueChange,
enabled = contentModel.enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp

data class TextFieldValueContentModel(
Expand All @@ -28,15 +29,15 @@ data class TextFieldValueContentModel(
val enabled: Boolean = true,
val readOnly: Boolean = false,
val onValueChange: (TextFieldValue) -> Unit
): ContentModel
) : ContentModel

data class TextFieldStringContentModel(
val value: String,
val placeholder: String = "",
val enabled: Boolean = true,
val readOnly: Boolean = false,
val onValueChange: (String) -> Unit
): ContentModel
) : ContentModel

object TextFieldSizingConstants {
val MinWidth = 200.dp
Expand All @@ -47,8 +48,9 @@ object TextFieldSizingConstants {
data class TextFieldPresentationModel(
val keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
val keyboardActions: KeyboardActions = KeyboardActions(),
val defaultMinSize: DpSize = DpSize(width = TextFieldSizingConstants.MinWidth, TextFieldSizingConstants.MinHeight),
val singleLine: Boolean = false,
val showBorder: Boolean = true,
val maxLines: Int = Int.MAX_VALUE,
val visualTransformation: VisualTransformation = VisualTransformation.None
): PresentationModel
) : PresentationModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package org.pushingpixels.aurora.demo.svg.material

import androidx.compose.ui.geometry.*
import androidx.compose.ui.graphics.*
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.graphics.drawscope.translate
import androidx.compose.ui.graphics.drawscope.withTransform
import androidx.compose.ui.graphics.painter.Painter
import java.lang.ref.WeakReference
import java.util.*
import kotlin.math.min

/**
* This class has been automatically generated using
* <a href="https://github.com/kirill-grouchnikov/aurora">Aurora SVG transcoder</a>.
*/
class ic_chat_black_24px : Painter() {
@Suppress("UNUSED_VARIABLE") private var shape: Outline? = null
@Suppress("UNUSED_VARIABLE") private var generalPath: Path? = null
@Suppress("UNUSED_VARIABLE") private var brush: Brush? = null
@Suppress("UNUSED_VARIABLE") private var stroke: Stroke? = null
@Suppress("UNUSED_VARIABLE") private var clip: Shape? = null
private var alpha = 1.0f
private var blendMode = DrawScope.DefaultBlendMode
private var alphaStack = mutableListOf(1.0f)
private var blendModeStack = mutableListOf(DrawScope.DefaultBlendMode)

@Suppress("UNUSED_VARIABLE", "UNUSED_VALUE", "VARIABLE_WITH_REDUNDANT_INITIALIZER", "UNNECESSARY_NOT_NULL_ASSERTION")
private fun _paint0(drawScope : DrawScope) {
var shapeText: Outline?
var generalPathText: Path? = null
var alphaText = 0.0f
var blendModeText = DrawScope.DefaultBlendMode
with(drawScope) {
//
alphaStack.add(0, alpha)
alpha *= 1.0f
blendModeStack.add(0, BlendMode.SrcOver)
blendMode = BlendMode.SrcOver
// _0
alphaStack.add(0, alpha)
alpha *= 1.0f
blendModeStack.add(0, BlendMode.SrcOver)
blendMode = BlendMode.SrcOver
// _0_0
if (generalPath == null) {
generalPath = Path()
} else {
generalPath!!.reset()
}
generalPath?.run {
moveTo(20.0f, 2.0f)
lineTo(4.0f, 2.0f)
cubicTo(2.9f, 2.0f, 2.01f, 2.9f, 2.01f, 4.0f)
lineTo(2.0f, 22.0f)
lineTo(6.0f, 18.0f)
lineTo(20.0f, 18.0f)
cubicTo(21.1f, 18.0f, 22.0f, 17.1f, 22.0f, 16.0f)
lineTo(22.0f, 4.0f)
cubicTo(22.0f, 2.9f, 21.1f, 2.0f, 20.0f, 2.0f)
close()
moveTo(6.0f, 9.0f)
lineTo(18.0f, 9.0f)
lineTo(18.0f, 11.0f)
lineTo(6.0f, 11.0f)
lineTo(6.0f, 9.0f)
close()
moveTo(14.0f, 14.0f)
lineTo(6.0f, 14.0f)
lineTo(6.0f, 12.0f)
lineTo(14.0f, 12.0f)
lineTo(14.0f, 14.0f)
close()
moveTo(18.0f, 8.0f)
lineTo(6.0f, 8.0f)
lineTo(6.0f, 6.0f)
lineTo(18.0f, 6.0f)
lineTo(18.0f, 8.0f)
close()
}
shape = Outline.Generic(generalPath!!)
brush = SolidColor(Color(0, 0, 0, 255))
drawOutline(outline = shape!!, style=Fill, brush=brush!!, alpha=alpha, blendMode = blendMode)
alpha = alphaStack.removeAt(0)
blendMode = blendModeStack.removeAt(0)
alphaStack.add(0, alpha)
alpha *= 1.0f
blendModeStack.add(0, BlendMode.SrcOver)
blendMode = BlendMode.SrcOver
// _0_1
alpha = alphaStack.removeAt(0)
blendMode = blendModeStack.removeAt(0)
alpha = alphaStack.removeAt(0)
blendMode = blendModeStack.removeAt(0)

}
}



private fun innerPaint(drawScope: DrawScope) {
_paint0(drawScope)


shape = null
generalPath = null
brush = null
stroke = null
clip = null
alpha = 1.0f
}

companion object {
/**
* Returns the X of the bounding box of the original SVG image.
*
* @return The X of the bounding box of the original SVG image.
*/
fun getOrigX(): Double {
return 2.0
}

/**
* Returns the Y of the bounding box of the original SVG image.
*
* @return The Y of the bounding box of the original SVG image.
*/
fun getOrigY(): Double {
return 2.0
}

/**
* Returns the width of the bounding box of the original SVG image.
*
* @return The width of the bounding box of the original SVG image.
*/
fun getOrigWidth(): Double {
return 20.0
}

/**
* Returns the height of the bounding box of the original SVG image.
*
* @return The height of the bounding box of the original SVG image.
*/
fun getOrigHeight(): Double {
return 20.0
}


}

override val intrinsicSize: Size
get() = Size.Unspecified

override fun DrawScope.onDraw() {
clipRect {
// Use the original icon bounding box and the current icon dimension to compute
// the scaling factor
val fullOrigWidth = getOrigX() + getOrigWidth()
val fullOrigHeight = getOrigY() + getOrigHeight()
val coef1 = size.width / fullOrigWidth
val coef2 = size.height / fullOrigHeight
val coef = min(coef1, coef2).toFloat()

// Use the original icon bounding box and the current icon dimension to compute
// the offset pivot for the scaling
var translateX = -getOrigX()
var translateY = -getOrigY()
if (coef1 != coef2) {
if (coef1 < coef2) {
val extraDy = ((fullOrigWidth - fullOrigHeight) / 2.0f).toFloat()
translateY += extraDy
} else {
val extraDx = ((fullOrigHeight - fullOrigWidth) / 2.0f).toFloat()
translateX += extraDx
}
}
val translateXDp = translateX.toFloat().toDp().value
val translateYDp = translateY.toFloat().toDp().value

// Create a combined scale + translate + clip transform before calling the transcoded painting instructions
withTransform({
scale(scaleX = coef, scaleY = coef, pivot = Offset.Zero)
translate(translateXDp, translateYDp)
clipRect(left = 0.0f, top = 0.0f, right = fullOrigWidth.toFloat(), bottom = fullOrigHeight.toFloat(), clipOp = ClipOp.Intersect)
}) {
innerPaint(this)
}
}
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0796041

Please sign in to comment.