Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit c0a251a

Browse files
Fixing test compile
1 parent 44b46af commit c0a251a

18 files changed

Lines changed: 238 additions & 271 deletions

File tree

tyrian-next/src/main/scala/tyrian/ui/elements/stateful/input/Input.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ final case class Input(
5353

5454
def themeLens: Lens[Theme.Default, InputTheme] =
5555
Lens(
56-
_.input,
57-
(t, i) => t.copy(input = i)
56+
_.elements.input,
57+
(t, i) => t.withInputTheme(i)
5858
)
5959

6060
def withThemeOverride(value: ThemeOverride[InputTheme]): Input =
@@ -105,8 +105,8 @@ object Input:
105105
Style.empty
106106

107107
case tt: Theme.Default =>
108-
if i.isDisabled then tt.input.toDisabledStyles(theme)
109-
else tt.input.toStyles(theme)
108+
if i.isDisabled then tt.elements.input.toDisabledStyles(theme)
109+
else tt.elements.input.toStyles(theme)
110110

111111
val classAttribute =
112112
if i.classNames.isEmpty then EmptyAttribute

tyrian-next/src/main/scala/tyrian/ui/elements/stateful/input/InputTheme.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import tyrian.ui.datatypes.RGBA
1212
import tyrian.ui.datatypes.Spacing
1313
import tyrian.ui.theme.Theme
1414

15+
// TODO: Which fields should be optional? Inherit from main styles.
1516
final case class InputTheme(
1617
fontSize: FontSize,
1718
fontWeight: FontWeight,
@@ -93,7 +94,7 @@ final case class InputTheme(
9394
val borderStyle = border.map(_.toStyle).getOrElse(Style.empty)
9495

9596
Style(
96-
"font-family" -> t.fonts.body.toCSSValue,
97+
"font-family" -> t.config.fonts.body.toCSSValue,
9798
"font-size" -> fontSize.toCSSValue,
9899
"font-weight" -> fontWeight.toCSSValue,
99100
"color" -> textColor.toCSSValue,

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/canvas/Canvas.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ final case class Canvas(
3737

3838
def themeLens: Lens[Theme.Default, ContainerTheme] =
3939
Lens(
40-
_.image,
41-
(t, c) => t.copy(canvas = c)
40+
_.elements.canvas,
41+
(t, c) => t.withCanvasTheme(c)
4242
)
4343

4444
def withThemeOverride(value: ThemeOverride[ContainerTheme]): Canvas =
@@ -82,7 +82,7 @@ object Canvas:
8282
Style.empty
8383

8484
case tt: Theme.Default =>
85-
tt.canvas.toStyle
85+
tt.elements.canvas.toStyle
8686

8787
val styles =
8888
if canvasStyles.isEmpty then Nil else List(style(canvasStyles))

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/image/Image.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ final case class Image(
5454

5555
def themeLens: Lens[Theme.Default, ContainerTheme] =
5656
Lens(
57-
_.image,
58-
(t, i) => t.copy(image = i)
57+
_.elements.image,
58+
(t, i) => t.withImageTheme(i)
5959
)
6060

6161
def withThemeOverride(value: ThemeOverride[ContainerTheme]): Image =
@@ -122,7 +122,7 @@ object Image:
122122
Style.empty
123123

124124
case tt: Theme.Default =>
125-
tt.image.toStyle
125+
tt.elements.image.toStyle
126126

127127
val styles =
128128
image.fit.toStyle |+| imageStyles

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/link/Link.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ final case class Link(
4343

4444
def themeLens: Lens[Theme.Default, LinkTheme] =
4545
Lens(
46-
_.link,
47-
(t, link) => t.copy(link = link)
46+
_.elements.link,
47+
(t, link) => t.withLinkTheme(link)
4848
)
4949

5050
def withThemeOverride(value: ThemeOverride[LinkTheme]): Link =
@@ -98,7 +98,7 @@ object Link:
9898
EmptyAttribute
9999

100100
case t: Theme.Default =>
101-
style(t.link.toStyles(theme))
101+
t.elements.link.toStyles.fold(EmptyAttribute)(style(_))
102102

103103
val attributes =
104104
List(
Lines changed: 8 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,24 @@
11
package tyrian.ui.elements.stateless.link
22

33
import tyrian.Style
4-
import tyrian.ui.datatypes.FontSize
5-
import tyrian.ui.datatypes.FontWeight
6-
import tyrian.ui.datatypes.LineHeight
74
import tyrian.ui.datatypes.RGBA
8-
import tyrian.ui.datatypes.TextAlignment
9-
import tyrian.ui.datatypes.TextDecoration
10-
import tyrian.ui.datatypes.TextStyle
11-
import tyrian.ui.datatypes.Wrapping
12-
import tyrian.ui.elements.stateless.text.TextTheme
13-
import tyrian.ui.theme.Theme
145

156
final case class LinkTheme(
16-
base: TextTheme, // TODO: Should this by optional and inherit from the main text theme? How about the default blue for a link?
17-
hoverColor: Option[RGBA],
18-
visitedColor: Option[RGBA],
19-
focusColor: Option[RGBA]
7+
unvisited: Option[RGBA]
208
):
219

22-
// Delegate basic text styling to the base TextTheme
23-
def withFontSize(value: FontSize): LinkTheme =
24-
this.copy(base = base.withFontSize(value))
10+
def withUnvisitedColor(color: RGBA): LinkTheme =
11+
this.copy(unvisited = Some(color))
2512

26-
def withFontWeight(value: FontWeight): LinkTheme =
27-
this.copy(base = base.withFontWeight(value))
13+
def defaultUnvisitedColor: LinkTheme =
14+
this.copy(unvisited = None)
2815

29-
def withTextColor(value: RGBA): LinkTheme =
30-
this.copy(base = base.withTextColor(value))
31-
32-
def withAlignment(value: TextAlignment): LinkTheme =
33-
this.copy(base = base.withAlignment(value))
34-
35-
def withLineHeight(value: LineHeight): LinkTheme =
36-
this.copy(base = base.withLineHeight(value))
37-
38-
def withWrapping(value: Wrapping): LinkTheme =
39-
this.copy(base = base.withWrapping(value))
40-
def noWrap: LinkTheme =
41-
withWrapping(Wrapping.NoWrap)
42-
def wrap: LinkTheme =
43-
withWrapping(Wrapping.Wrap)
44-
45-
def withStyle(value: TextStyle): LinkTheme =
46-
this.copy(base = base.withStyle(value))
47-
48-
def withDecoration(value: TextDecoration): LinkTheme =
49-
this.copy(base = base.withDecoration(value))
50-
51-
// Link-specific styling
52-
def withHoverColor(color: RGBA): LinkTheme =
53-
this.copy(hoverColor = Some(color))
54-
55-
def withVisitedColor(color: RGBA): LinkTheme =
56-
this.copy(visitedColor = Some(color))
57-
58-
def withFocusColor(color: RGBA): LinkTheme =
59-
this.copy(focusColor = Some(color))
60-
61-
def noHoverColor: LinkTheme =
62-
this.copy(hoverColor = None)
63-
64-
def noVisitedColor: LinkTheme =
65-
this.copy(visitedColor = None)
66-
67-
def noFocusColor: LinkTheme =
68-
this.copy(focusColor = None)
69-
70-
// Convenience methods that delegate to base
71-
def bold: LinkTheme = this.copy(base = base.bold)
72-
def italic: LinkTheme = this.copy(base = base.italic)
73-
def underlined: LinkTheme = this.copy(base = base.underlined)
74-
def strikethrough: LinkTheme = this.copy(base = base.strikethrough)
75-
76-
def clearWeight: LinkTheme = this.copy(base = base.clearWeight)
77-
def clearStyle: LinkTheme = this.copy(base = base.clearStyle)
78-
def clearDecoration: LinkTheme = this.copy(base = base.clearDecoration)
79-
80-
def alignLeft: LinkTheme = this.copy(base = base.alignLeft)
81-
def alignCenter: LinkTheme = this.copy(base = base.alignCenter)
82-
def alignRight: LinkTheme = this.copy(base = base.alignRight)
83-
def alignJustify: LinkTheme = this.copy(base = base.alignJustify)
84-
85-
def toStyles(theme: Theme): Style =
86-
base.toStyles(theme)
87-
88-
def toHoverStyles: Style =
89-
hoverColor.map(color => Style("color" -> color.toCSSValue)).getOrElse(Style.empty)
90-
91-
def toVisitedStyles: Style =
92-
visitedColor.map(color => Style("color" -> color.toCSSValue)).getOrElse(Style.empty)
93-
94-
def toFocusStyles: Style =
95-
focusColor.map(color => Style("color" -> color.toCSSValue)).getOrElse(Style.empty)
16+
def toStyles: Option[Style] =
17+
unvisited.map(color => Style("color" -> color.toCSSValue))
9618

9719
object LinkTheme:
9820

9921
val default: LinkTheme =
10022
LinkTheme(
101-
base = TextTheme(
102-
fontSize = FontSize.Medium,
103-
fontWeight = FontWeight.Normal,
104-
textColor = RGBA.fromHex("#0066cc"), // Classic link blue..
105-
alignment = TextAlignment.Left,
106-
lineHeight = LineHeight.Normal,
107-
wrapping = Wrapping.Wrap,
108-
style = TextStyle.Normal,
109-
decoration = TextDecoration.Underline // Links are underlined
110-
),
111-
hoverColor = Some(RGBA.fromHex("#004499")), // Darker blue on hover
112-
visitedColor = Some(RGBA.fromHex("#551a8b")), // Purple for visited links
113-
focusColor = Some(RGBA.fromHex("#0066cc")) // Same as base for focus
23+
unvisited = None
11424
)

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/table/CellTheme.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ final case class CellTheme(
4242
def toStyle: Option[Style] =
4343
val baseStyles =
4444
for {
45-
fw <- fontWeight
46-
fs <- fontSize
45+
fw <- fontWeight // TODO: Inherit from main styles!
46+
fs <- fontSize // TODO: Inherit from main styles!
4747
} yield Style(
4848
"font-weight" -> fw.toCSSValue,
4949
"font-size" -> fs.toCSSValue
5050
)
5151

5252
for {
5353
backgroundStyle <- background.map("background-color" -> _.toCSSValue)
54-
textColorStyle <- textColor.map("color" -> _.toCSSValue)
54+
textColorStyle <- textColor.map("color" -> _.toCSSValue) // TODO: Inherit from main styles!
5555
base <- baseStyles
5656
p <- padding.map(_.toStyle)
5757
} yield base |+| p |+| Style(backgroundStyle, textColorStyle)

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/table/Table.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ final case class Table(
2525

2626
def themeLens: Lens[Theme.Default, TableTheme] =
2727
Lens(
28-
_.table,
29-
(t, table) => t.copy(table = table)
28+
_.elements.table,
29+
(t, table) => t.withTableTheme(table)
3030
)
3131

3232
def withThemeOverride(value: ThemeOverride[TableTheme]): Table =
@@ -68,15 +68,15 @@ object Table:
6868
EmptyAttribute
6969

7070
case t: Theme.Default =>
71-
style(t.table.toTableStyles)
71+
style(t.elements.table.toTableStyles)
7272

7373
val headerStyleAttribute =
7474
theme match
7575
case Theme.None =>
7676
EmptyAttribute
7777

7878
case t: Theme.Default =>
79-
t.table.toHeaderStyles match
79+
t.elements.table.toHeaderStyles match
8080
case Some(s) => style(s)
8181
case None => EmptyAttribute
8282

@@ -86,7 +86,7 @@ object Table:
8686
EmptyAttribute
8787

8888
case t: Theme.Default =>
89-
t.table.toCellStyles match
89+
t.elements.table.toCellStyles match
9090
case Some(s) => style(s)
9191
case None => EmptyAttribute
9292

@@ -106,7 +106,7 @@ object Table:
106106
EmptyAttribute
107107

108108
case t: Theme.Default =>
109-
style(t.table.toRowStyles(index % 2 == 1))
109+
style(t.elements.table.toRowStyles(index % 2 == 1))
110110

111111
tr(rowStyles)(
112112
row.map { cellData =>

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/text/TextBlock.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ final case class TextBlock(
3636

3737
def themeLens: Lens[Theme.Default, TextTheme] =
3838
Lens(
39-
_.text.getFromVariant(variant),
40-
(t, txt) => t.copy(text = t.text.setFromVariant(variant, txt))
39+
_.elements.text.getFromVariant(variant),
40+
(t, txt) => t.withTextThemes(t.elements.text.setFromVariant(variant, txt))
4141
)
4242

4343
def withThemeOverride(value: ThemeOverride[TextTheme]): TextBlock =

tyrian-next/src/main/scala/tyrian/ui/elements/stateless/text/TextTheme.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ final case class TextTheme(
7171

7272
case t: Theme.Default =>
7373
val baseStyle = Style(
74-
"font-family" -> t.fonts.body.toCSSValue,
74+
"font-family" -> t.config.fonts.body.toCSSValue,
7575
"font-size" -> fontSize.toCSSValue,
7676
"font-weight" -> fontWeight.toCSSValue,
7777
"color" -> textColor.toCSSValue,
@@ -80,8 +80,6 @@ final case class TextTheme(
8080
"white-space" -> wrapping.toTextCSSValue
8181
)
8282

83-
// TODO: Maybe all style options in the theme should be Optional? Some are, some aren't currently.
84-
// It would clean up this logic and remove the need for the foldLeft.
8583
val styleModifiers = List(
8684
if style != TextStyle.Normal then Some("font-style" -> style.toCSSValue) else None,
8785
if decoration != TextDecoration.None then Some("text-decoration" -> decoration.toCSSValue) else None

0 commit comments

Comments
 (0)