Make WeatherDetailsCard vertically scrollable and add safeContentPadding

This commit is contained in:
Nebojsa Vuksic 2025-08-05 12:41:19 +02:00
parent 11dfe41249
commit f25ee25399

View File

@ -18,10 +18,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import org.jetbrains.jewel.foundation.theme.JewelTheme import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.ui.component.ActionButton import org.jetbrains.jewel.ui.component.*
import org.jetbrains.jewel.ui.component.HorizontallyScrollableContainer
import org.jetbrains.jewel.ui.component.Icon
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.jewel.ui.icons.AllIconsKeys import org.jetbrains.jewel.ui.icons.AllIconsKeys
import org.jetbrains.plugins.template.ComposeTemplateBundle import org.jetbrains.plugins.template.ComposeTemplateBundle
import org.jetbrains.plugins.template.weatherApp.WeatherAppColors import org.jetbrains.plugins.template.weatherApp.WeatherAppColors
@ -54,8 +51,9 @@ fun WeatherDetailsCard(
val cardColor = getCardColorByTemperature(currentWeatherForecast.temperature, isNightTime) val cardColor = getCardColorByTemperature(currentWeatherForecast.temperature, isNightTime)
val textColor = Color.White val textColor = Color.White
VerticallyScrollableContainer(modifier = modifier.safeContentPadding()) {
Box( Box(
modifier = modifier modifier = Modifier
.clip(RoundedCornerShape(16.dp)) .clip(RoundedCornerShape(16.dp))
.background(cardColor) .background(cardColor)
.padding(16.dp) .padding(16.dp)
@ -71,21 +69,42 @@ fun WeatherDetailsCard(
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
) { ) {
// Current Time // Current Time
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message("weather.app.time.text", timeToDisplay), text = ComposeTemplateBundle.message(
"weather.app.time.text",
formatDateTime(currentWeatherForecast.date)
),
color = textColor, color = textColor,
fontSize = JewelTheme.defaultTextStyle.fontSize, fontSize = JewelTheme.defaultTextStyle.fontSize,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
/**
* Jewel org.jetbrains.jewel.ui.component.ActionButton
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Button.kt
*/
ActionButton( ActionButton(
modifier = Modifier modifier = Modifier
.clip(RoundedCornerShape(8.dp)) .clip(RoundedCornerShape(8.dp))
.background(Color.Transparent) .background(Color.Transparent)
.padding(8.dp), .padding(8.dp),
tooltip = { Text("Refresh weather data") }, tooltip = {
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text("Refresh weather data")
},
onClick = { onReloadWeatherData(weatherForecastData.location) }, onClick = { onReloadWeatherData(weatherForecastData.location) },
) { ) {
/**
* Jewel org.jetbrains.jewel.ui.component.Icon
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt
*/
Icon( Icon(
key = AllIconsKeys.Actions.Refresh, key = AllIconsKeys.Actions.Refresh,
contentDescription = "Refresh", contentDescription = "Refresh",
@ -102,6 +121,10 @@ fun WeatherDetailsCard(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
/**
* Jewel org.jetbrains.jewel.ui.component.Icon
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt
*/
Icon( Icon(
key = when { key = when {
isNightTime -> currentWeatherForecast.weatherType.nightIconKey isNightTime -> currentWeatherForecast.weatherType.nightIconKey
@ -114,6 +137,10 @@ fun WeatherDetailsCard(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
// Temperature (emphasized) // Temperature (emphasized)
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message( text = ComposeTemplateBundle.message(
"weather.app.temperature.text", "weather.app.temperature.text",
@ -127,6 +154,10 @@ fun WeatherDetailsCard(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
// City name // City name
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = weatherForecastData.location.label, text = weatherForecastData.location.label,
color = textColor, color = textColor,
@ -143,6 +174,10 @@ fun WeatherDetailsCard(
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
) { ) {
// Wind info // Wind info
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message( text = ComposeTemplateBundle.message(
"weather.app.wind.direction.text", "weather.app.wind.direction.text",
@ -154,6 +189,10 @@ fun WeatherDetailsCard(
) )
// Humidity info // Humidity info
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message( text = ComposeTemplateBundle.message(
"weather.app.humidity.text", "weather.app.humidity.text",
@ -177,6 +216,7 @@ fun WeatherDetailsCard(
) )
} }
} }
}
} }
@Composable @Composable
@ -187,6 +227,10 @@ private fun SevenDaysForecastWidget(
) { ) {
if (weatherForecastData.dailyForecasts.isNotEmpty()) { if (weatherForecastData.dailyForecasts.isNotEmpty()) {
Column(modifier) { Column(modifier) {
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message("weather.app.7days.forecast.title.text"), text = ComposeTemplateBundle.message("weather.app.7days.forecast.title.text"),
color = textColor, color = textColor,
@ -198,8 +242,12 @@ private fun SevenDaysForecastWidget(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
val scrollState = rememberLazyListState() val scrollState = rememberLazyListState()
/**
* Jewel org.jetbrains.jewel.ui.component.HorizontallyScrollableContainer
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/ScrollableContainer.kt
*/
HorizontallyScrollableContainer( HorizontallyScrollableContainer(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().safeContentPadding(),
scrollState = scrollState, scrollState = scrollState,
) { ) {
LazyRow( LazyRow(
@ -244,6 +292,10 @@ private fun DayForecastItem(
.padding(8.dp) .padding(8.dp)
) { ) {
// Day name // Day name
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = dayName, text = dayName,
color = textColor, color = textColor,
@ -252,6 +304,10 @@ private fun DayForecastItem(
textAlign = TextAlign.Center textAlign = TextAlign.Center
) )
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = date, text = date,
color = textColor, color = textColor,
@ -263,6 +319,10 @@ private fun DayForecastItem(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
// Weather icon // Weather icon
/**
* Jewel org.jetbrains.jewel.ui.component.Icon
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Icon.kt
*/
Icon( Icon(
key = if (isNightTime(forecast.date)) forecast.weatherType.nightIconKey else forecast.weatherType.dayIconKey, key = if (isNightTime(forecast.date)) forecast.weatherType.nightIconKey else forecast.weatherType.dayIconKey,
contentDescription = forecast.weatherType.label, contentDescription = forecast.weatherType.label,
@ -273,6 +333,10 @@ private fun DayForecastItem(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
// Temperature // Temperature
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message( text = ComposeTemplateBundle.message(
"weather.app.temperature.text", "weather.app.temperature.text",
@ -286,6 +350,10 @@ private fun DayForecastItem(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
// Humidity // Humidity
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message( text = ComposeTemplateBundle.message(
"weather.app.humidity.text", "weather.app.humidity.text",
@ -298,6 +366,10 @@ private fun DayForecastItem(
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
// Wind direction // Wind direction
/**
* Jewel org.jetbrains.jewel.ui.component.Text
* @see https://github.com/JetBrains/intellij-community/blob/master/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Text.kt
*/
Text( Text(
text = ComposeTemplateBundle.message( text = ComposeTemplateBundle.message(
"weather.app.wind.direction.text", "weather.app.wind.direction.text",