scoop:scoop.ui.component:0.1.0
src/calendar/header.scoop
Selected production source · src/calendar/header.scoop
1
package scoop.ui.component3
import scoop.datetime.LocalDate4
import scoop.graphics.*5
import scoop.ui.*6
import scoop.ui.style.*7
import scoop.ui.component.row as calendarHeaderRow9
internal fun calendarHeader(10
owner: CalendarControl,11
page: CalendarPage,12
index: Long,13
first: Boolean,14
last: Boolean,15
appearance: CalendarAppearance16
): View {17
val input = owner.props.value18
val before = calendarPageButton(owner, first, false, appearance)19
val after = calendarPageButton(owner, last, true, appearance)20
val caption =21
if (22
input.options.caption ==23
CalendarCaption.Dropdowns &&24
page.months.size >25
0L &&26
page.years.size >27
0L28
)29
calendarHeaderRow {30
this.add(calendarPageSelect(owner, index, page.months, appearance, "month"))31
this.add(calendarPageSelect(owner, index, page.years, appearance, "year"))32
this.spacing = 2.0 * appearance.density33
this.alignment = CrossAlignment.Center34
}35
else36
calendarLabel(page.caption, appearance.caption, input.fonts)37
val parts = CalendarHeaderParts(page, before, after, caption)38
when (input.header) {39
case Some(val build) -> return build(parts);40
case None -> {}41
}42
val layout =43
GridProps(44
[45
GridTrack.Fixed(appearance.cell),46
GridTrack.Fraction(1.0),47
GridTrack.Fixed(appearance.cell)48
],49
[GridTrack.Auto],50
[51
GridItem(before, 0L, 0L),52
GridItem(caption, 1L, 0L, vertical = CrossAlignment.Center),53
GridItem(after, 2L, 0L)54
],55
columnGap = 2.0 * appearance.density56
)57
return component(layout, { props, scope -> Grid(props, scope) })58
}60
private fun calendarPageButton(61
owner: CalendarControl,62
present: Boolean,63
forward: Boolean,64
appearance: CalendarAppearance65
): View {66
if (!present)67
return empty()68
val input = owner.props.value69
val first = owner.pages()[0L]70
val available =71
if (forward)72
first.next != None73
else74
first.previous != None75
val button =76
component(77
ButtonProps(78
ButtonContent.Resolved {79
style -> navigationIcon(80
if (forward)81
NavigationGlyph.End82
else83
NavigationGlyph.Start,84
style.iconSize,85
style.text.color86
)87
},88
{ owner.turn(forward) },89
input.enabled && available,90
appearance.normal,91
input.theme,92
FocusOptions(93
handle =94
Some(95
if (forward)96
owner.nextFocus97
else98
owner.previousFocus99
)100
),101
variant = ButtonVariant.Ghost,102
size = ButtonSize.Icon,103
semantics =104
ComponentSemantics(105
name =106
Some(107
if (forward)108
input.options.locale.nextMonth109
else110
input.options.locale.previousMonth111
)112
)113
),114
{ props, scope -> Button(props, scope) },115
ViewKey.Text(116
if (forward)117
"next"118
else119
"previous"120
)121
)122
return panelFrame(button, Insets.all(appearance.ring))123
}125
private fun calendarPageSelect(126
owner: CalendarControl,127
index: Long,128
entries: Array<CalendarPageChoice>,129
appearance: CalendarAppearance,130
key: String131
): View {132
val input = owner.props.value133
val selected =134
binding<LocalDate?>(135
{ owner.captionPage(index) },136
{137
next -> when (next) {138
case Some(val date) -> {139
owner.showCaption(date, index);140
};141
case None -> {}142
}143
}144
)145
val choices =146
Array<Choice<LocalDate>>(entries.size) {147
index -> Choice(148
ViewKey.Text(entries[index].anchor.toString()),149
entries[index].anchor,150
entries[index].label151
)152
}153
return select(selected, choices) {154
this.key = ViewKey.Text(key)155
this.size = SelectSize.Sm156
this.enabled = input.enabled157
this.fonts = input.fonts158
this.theme = input.theme159
this.position = SelectPosition.Popup160
this.style {161
this.surface {162
this.padding =163
Some(164
Insets(165
4.0 * appearance.density,166
2.0 * appearance.density,167
4.0 * appearance.density,168
2.0 * appearance.density169
)170
)171
}172
}173
}174
}