-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from InkApplications/weather
Add weather widget
- Loading branch information
Showing
13 changed files
with
241 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 39 additions & 16 deletions
55
render-compose/src/commonMain/kotlin/ink/ui/render/compose/renderer/ListRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,65 @@ | ||
package ink.ui.render.compose.renderer | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import ink.ui.render.compose.theme.ComposeRenderTheme | ||
import ink.ui.structures.Positioning | ||
import ink.ui.structures.GroupingStyle | ||
import ink.ui.structures.elements.ElementList | ||
import ink.ui.structures.elements.Orientation | ||
import ink.ui.structures.elements.UiElement | ||
import ink.ui.structures.render.RenderResult | ||
|
||
internal object ListRenderer: ElementRenderer { | ||
@Composable | ||
override fun render(element: UiElement, theme: ComposeRenderTheme, parent: ElementRenderer): RenderResult { | ||
when (element) { | ||
is ElementList -> Column( | ||
if (element !is ElementList) return RenderResult.Skipped | ||
|
||
when (element.orientation) { | ||
Orientation.Vertical -> Column( | ||
horizontalAlignment = when (element.positioning) { | ||
Positioning.Start -> Alignment.Start | ||
Positioning.Center -> Alignment.CenterHorizontally | ||
}, | ||
) { | ||
element.items.forEachIndexed { index, item -> | ||
parent.render(item, theme, parent) | ||
if (element.groupingStyle != GroupingStyle.Unified && index != 0 && index != element.items.size - 1) { | ||
val spacing = when (element.groupingStyle) { | ||
GroupingStyle.Items -> theme.spacing.item | ||
GroupingStyle.Sections -> theme.spacing.sectionSpacing | ||
GroupingStyle.Unified -> throw IllegalStateException() | ||
} | ||
Spacer(modifier = Modifier.height(spacing)) | ||
} | ||
renderElements(element, theme, parent) | ||
} | ||
Orientation.Horizontal -> Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = when (element.positioning) { | ||
Positioning.Start -> Arrangement.Start | ||
Positioning.Center -> Arrangement.Center | ||
}, | ||
modifier = Modifier.let { | ||
if (element.positioning == Positioning.Center) { | ||
it.fillMaxWidth() | ||
} else it | ||
} | ||
) { | ||
renderElements(element, theme, parent) | ||
} | ||
else -> return RenderResult.Skipped | ||
} | ||
return RenderResult.Rendered | ||
} | ||
|
||
@Composable | ||
private fun renderElements( | ||
element: ElementList, | ||
theme: ComposeRenderTheme, | ||
parent: ElementRenderer | ||
) { | ||
element.items.forEachIndexed { index, item -> | ||
parent.render(item, theme, parent) | ||
if (element.groupingStyle != GroupingStyle.Unified && index != 0 && index != element.items.size - 1) { | ||
val spacing = when (element.groupingStyle) { | ||
GroupingStyle.Items -> theme.spacing.item | ||
GroupingStyle.Sections -> theme.spacing.sectionSpacing | ||
GroupingStyle.Unified -> throw IllegalStateException() | ||
} | ||
Spacer(modifier = Modifier.height(spacing)) | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
render-compose/src/commonMain/kotlin/ink/ui/render/compose/renderer/WeatherRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ink.ui.render.compose.renderer | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.text.BasicText | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import ink.ui.structures.Sentiment | ||
import ink.ui.structures.Symbol | ||
import ink.ui.structures.elements.WeatherElement | ||
import org.jetbrains.compose.resources.painterResource | ||
|
||
val WeatherRenderer = renderer<WeatherElement> { theme, element -> | ||
Box( | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Column( | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
val title = element.title | ||
if (title != null) { | ||
BasicText( | ||
text = title, | ||
style = theme.typography.caption.copy(color = theme.colors.foreground), | ||
) | ||
} | ||
|
||
when (element.condition) { | ||
WeatherElement.Condition.Clear -> Image( | ||
painterResource(Symbol.Sunshine.resource), | ||
colorFilter = ColorFilter.tint(theme.colors.forSentiment(Sentiment.Nominal)), | ||
contentDescription = element.condition.description, | ||
modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) | ||
) | ||
|
||
WeatherElement.Condition.Cloudy -> Image( | ||
painterResource(Symbol.Cloud.resource), | ||
colorFilter = ColorFilter.tint(theme.colors.forSentiment(Sentiment.Nominal)), | ||
contentDescription = element.condition.description, | ||
modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) | ||
) | ||
|
||
WeatherElement.Condition.Rainy -> Image( | ||
painterResource(Symbol.Rain.resource), | ||
colorFilter = ColorFilter.tint(theme.colors.forSentiment(Sentiment.Nominal)), | ||
contentDescription = element.condition.description, | ||
modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) | ||
) | ||
} | ||
|
||
BasicText(element.temperature, style = theme.typography.body.copy(color = theme.colors.foreground)) | ||
|
||
val secondaryTemperature = element.secondaryTemperature | ||
if (secondaryTemperature != null) { | ||
BasicText(secondaryTemperature, style = theme.typography.caption.copy(color = theme.colors.foreground)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val WeatherElement.Condition.description get() = when (this) { | ||
WeatherElement.Condition.Clear -> "Clear" | ||
WeatherElement.Condition.Cloudy -> "Cloudy" | ||
WeatherElement.Condition.Rainy -> "Rainy" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.