@tastic/hud 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -334,25 +334,25 @@ const styles = StyleSheet.create({
334
334
  sectionLabel: {
335
335
  letterSpacing: 2
336
336
  },
337
- // Negative margin cancels the padding so the icon still lines up with APPEARANCE/SOUND &
338
- // HAPTICS below, while the ripple/hover highlight itself gets room to breathe on both sides
339
- // instead of a flush edge-to-edge slab. overflow: 'hidden' makes sure that highlight actually
340
- // clips to borderRadius instead of drawing as a plain rectangle.
337
+ // Used to carry marginHorizontal: -12 + paddingHorizontal: 12 (netting to the same inset as
338
+ // APPEARANCE/SOUND & HAPTICS below, while giving the ripple/hover highlight room to breathe
339
+ // into the dialog's own gutter beyond that). Removed: this dialog scrolls (Dialog.ScrollArea +
340
+ // ScrollView above), and on web a ScrollView's own content wrapper clips to its own bounds
341
+ // regardless of a child's negative margin - confirmed live, the icon's own rounded-square badge
342
+ // was getting its left edge sliced off by exactly that overhang. No horizontal inset of its own
343
+ // now - it relies purely on the same dialog padding APPEARANCE/every other row already does,
344
+ // which can never overflow because it's never negative.
341
345
  toggleButton: {
342
346
  borderRadius: 12,
343
- marginHorizontal: -12,
344
347
  overflow: 'hidden',
345
- paddingHorizontal: 12,
346
348
  paddingVertical: 10
347
349
  },
348
- // Same shape as toggleButton but `flex: 1` instead of its own `marginHorizontal: -12` two of
349
- // these side by side in toggleRow would otherwise both pull inward and collide in the middle.
350
- // toggleRow carries that edge-alignment margin once, for the row as a whole, instead.
350
+ // Same shape as toggleButton, `flex: 1` instead of its own width - two of these side by side in
351
+ // toggleRow share the row's own edge alignment instead of each carrying their own.
351
352
  toggleButtonInRow: {
352
353
  borderRadius: 12,
353
354
  flex: 1,
354
355
  overflow: 'hidden',
355
- paddingHorizontal: 12,
356
356
  paddingVertical: 10
357
357
  },
358
358
  toggleContent: {
@@ -363,9 +363,9 @@ const styles = StyleSheet.create({
363
363
  toggleGroup: {
364
364
  gap: 4
365
365
  },
366
+ // No horizontal margin of its own now either - see toggleButton's identical note.
366
367
  toggleRow: {
367
368
  flexDirection: 'row',
368
- gap: 4,
369
- marginHorizontal: -12
369
+ gap: 4
370
370
  }
371
371
  })
@@ -0,0 +1,55 @@
1
+ import { computeContentBounds } from '@tastic/core'
2
+ import { ReactNode } from 'react'
3
+ import { StyleProp, StyleSheet, useWindowDimensions, View, ViewStyle } from 'react-native'
4
+
5
+ interface Props {
6
+ // Upper bound on the centered content region's width, in px. Omitted (the default) means no
7
+ // clamp at all - content fills the full window width and both gutters stay at 0 - the right
8
+ // default for a caller that wants this component's centered-content structure without ever
9
+ // actually capping width (e.g. a future full-bleed/"extend into safe area"-style mode: just
10
+ // don't pass this prop for that mode, rather than needing a separate disable flag).
11
+ maxContentWidth?: number
12
+ // Decoration for the left/right leftover space once maxContentWidth actually clamps something -
13
+ // e.g. a boundary wall. Each renders inside a View already sized to that side's own
14
+ // gutterWidth (0, and so with no room to show in, whenever nothing's clamped) - omit either/both
15
+ // for plain empty space, the default.
16
+ leftGutter?: ReactNode
17
+ rightGutter?: ReactNode
18
+ style?: StyleProp<ViewStyle>
19
+ children: ReactNode
20
+ }
21
+
22
+ // Caps a game's play area at maxContentWidth on a wide desktop/web window, splitting whatever's
23
+ // left over into two equal, empty-by-default gutters instead of letting content keep stretching
24
+ // (or drift off-center, left-anchored inside a now-much-wider parent) past the point where growing
25
+ // any further stops being useful. Below maxContentWidth - or with it omitted entirely - this is a
26
+ // no-op passthrough: children render at the full window width, no gutters.
27
+ //
28
+ // See @tastic/core's computeContentBounds for the actual clamp math this just wires up to a live
29
+ // useWindowDimensions() read - deliberately the only geometry source this component owns itself; a
30
+ // caller that also needs to fold in device safe-area insets or a split-screen zone boundary
31
+ // composes those together on its own side, the same way LightCycles' useZoneClampedAlign composes
32
+ // useAutoAlign with its own extra geometry (see that hook for the pattern this follows).
33
+ export function ContentGutter({ maxContentWidth, leftGutter, rightGutter, style, children }: Props) {
34
+ const { width: windowWidth } = useWindowDimensions()
35
+ const { contentWidth, gutterWidth } = computeContentBounds(windowWidth, maxContentWidth ?? Infinity)
36
+
37
+ return (
38
+ <View style={[styles.row, style]}>
39
+ <View style={[styles.gutter, { width: gutterWidth }]}>{leftGutter}</View>
40
+ <View style={{ width: contentWidth }}>{children}</View>
41
+ <View style={[styles.gutter, { width: gutterWidth }]}>{rightGutter}</View>
42
+ </View>
43
+ )
44
+ }
45
+
46
+ const styles = StyleSheet.create({
47
+ // overflow:'hidden' keeps an oversized leftGutter/rightGutter from bleeding into the content
48
+ // column instead of clipping cleanly at its own real width.
49
+ gutter: {
50
+ overflow: 'hidden'
51
+ },
52
+ row: {
53
+ flexDirection: 'row'
54
+ }
55
+ })
@@ -40,6 +40,13 @@ interface Props {
40
40
  host: PopoverHost
41
41
  value: string
42
42
  onChange: (hex: string) => void
43
+ // Transforms only what's *rendered* — trigger fill, swatch fill, and the contrast/caret/border
44
+ // colors derived from them — leaving `value`/`swatch.value` themselves untouched for `selected`/
45
+ // `taken` matching and for what onChange actually commits. For a host whose own theme mutes or
46
+ // tints a raw seed color before it's actually used elsewhere (e.g. blending it toward a base
47
+ // palette for a card-back tint), so the picker can preview that real result per-swatch instead of
48
+ // the too-vibrant seed hue, without changing what gets stored.
49
+ previewValue?: (hex: string) => string
43
50
  swatches?: SeedColor[]
44
51
  // The other player's current color, if any — stays visible in the grid (so the full palette
45
52
  // reads consistently for both players) but renders disabled with an X, rather than being
@@ -82,7 +89,7 @@ interface Props {
82
89
  // Renders inline rather than as a full-screen modal, scoped to its own panel — a modal color
83
90
  // picker would block the whole screen for one player while another can't touch their own panel at
84
91
  // the same time, which defeats the point of a split-screen lobby.
85
- export function InlineColorPicker({ id, host, value, onChange, swatches = defaultColors, takenValue, allowSwapTaken, dark, align: alignOverride, icon = 'palette', tag, labelFontFamily = MONO_FONT, autoDismiss = true, columns, size = DEFAULT_SIZE }: Props) {
92
+ export function InlineColorPicker({ id, host, value, onChange, previewValue, swatches = defaultColors, takenValue, allowSwapTaken, dark, align: alignOverride, icon = 'palette', tag, labelFontFamily = MONO_FONT, autoDismiss = true, columns, size = DEFAULT_SIZE }: Props) {
86
93
  const menuBg = dark ? '#000000' : '#FFFFFF'
87
94
  const { width: windowWidth } = useWindowDimensions()
88
95
  const autoColumns = clamp(Math.floor((windowWidth - 2 * SCREEN_MARGIN + SWATCHES_GAP) / (SWATCH_SIZE + SWATCHES_GAP)), MIN_COLUMNS, MAX_COLUMNS)
@@ -94,7 +101,9 @@ export function InlineColorPicker({ id, host, value, onChange, swatches = defaul
94
101
  const open = host.openId === id
95
102
  const { align: autoAlign, maxHeight, measured, triggerRef, verticalAlign } = useAutoAlign(open, swatchesWidth, swatchesHeight)
96
103
  const align = alignOverride ?? autoAlign
97
- const contrastColor = getContrastColor(value)
104
+ const displayFor = previewValue ?? ((hex: string) => hex)
105
+ const displayValue = displayFor(value)
106
+ const contrastColor = getContrastColor(displayValue)
98
107
  // An emoji glyph reads visually smaller than a bold letter at the same fontSize (the system emoji
99
108
  // font leaves more of its own em-box empty), so a plain-text ratio that looks right for an initial
100
109
  // still looks small for an emoji tag at the identical size — this bumps emoji up to the icon's own
@@ -103,7 +112,7 @@ export function InlineColorPicker({ id, host, value, onChange, swatches = defaul
103
112
 
104
113
  return (
105
114
  <View style={[styles.anchor, open && styles.anchorOpen]}>
106
- <TouchableRipple onPress={() => host.toggle(id)} borderless style={[styles.trigger, { backgroundColor: value, borderRadius: size / 2, height: size, width: size }]}>
115
+ <TouchableRipple onPress={() => host.toggle(id)} borderless style={[styles.trigger, { backgroundColor: displayValue, borderRadius: size / 2, height: size, width: size }]}>
107
116
  <View ref={triggerRef} collapsable={false} style={styles.triggerMeasure}>
108
117
  {/* Sized as a fraction of the trigger's own diameter rather than a fixed pixel size, so
109
118
  the glyph still reads as a deliberate part of the circle instead of shrinking toward its
@@ -121,18 +130,19 @@ export function InlineColorPicker({ id, host, value, onChange, swatches = defaul
121
130
  {/* Gated on `measured`, not just `open` — see useAutoAlign's own comment and
122
131
  SectionedDropdown's identical fix: without it, the popover mounts for one frame at a stale or
123
132
  guessed alignment and visibly jumps once this open's own measurement lands. */}
124
- <PopoverBody visible={open && measured} align={align} verticalAlign={verticalAlign} caretColor={menuBg} caretBorderColor={value} caretBorderWidth={SWATCHES_BORDER_WIDTH} triggerSize={size}>
133
+ <PopoverBody visible={open && measured} align={align} verticalAlign={verticalAlign} caretColor={menuBg} caretBorderColor={displayValue} caretBorderWidth={SWATCHES_BORDER_WIDTH} triggerSize={size}>
125
134
  {/* Border matches this trigger's own current color (not a neutral gray) — two triggers can
126
135
  sit close together, so the popover needs a clear visual tie back to which one opened it,
127
136
  not just its screen position. maxHeight (see useAutoAlign) only actually clamps on a screen
128
137
  short enough that the full grid can't fit above or below the trigger either way — a short
129
138
  landscape screen with the trigger row near the top, same case SectionedDropdown's own
130
139
  ScrollView exists for. */}
131
- <ScrollView style={[styles.swatches, { backgroundColor: menuBg, borderColor: value, width: swatchesWidth, maxHeight }]} contentContainerStyle={styles.swatchesContent} showsVerticalScrollIndicator={false}>
140
+ <ScrollView style={[styles.swatches, { backgroundColor: menuBg, borderColor: displayValue, width: swatchesWidth, maxHeight }]} contentContainerStyle={styles.swatchesContent} showsVerticalScrollIndicator={false}>
132
141
  {swatches.map((swatch) => {
133
142
  const selected = swatch.value.toLowerCase() === value.toLowerCase()
134
143
  const taken = !selected && !!takenValue && swatch.value.toLowerCase() === takenValue.toLowerCase()
135
144
  const swappable = taken && allowSwapTaken
145
+ const swatchDisplay = displayFor(swatch.value)
136
146
  return (
137
147
  <TouchableRipple
138
148
  key={swatch.value}
@@ -142,9 +152,9 @@ export function InlineColorPicker({ id, host, value, onChange, swatches = defaul
142
152
  if (autoDismiss) host.close()
143
153
  }}
144
154
  borderless
145
- style={[styles.swatch, { backgroundColor: swatch.value }, selected && styles.swatchSelected, taken && !swappable && styles.swatchTaken]}
155
+ style={[styles.swatch, { backgroundColor: swatchDisplay }, selected && styles.swatchSelected, taken && !swappable && styles.swatchTaken]}
146
156
  >
147
- {selected ? <Icon source='check' size={16} color={getContrastColor(swatch.value)} /> : swappable ? <Icon source='swap-horizontal' size={16} color={getContrastColor(swatch.value)} /> : taken ? <Icon source='close' size={16} color={getContrastColor(swatch.value)} /> : <View />}
157
+ {selected ? <Icon source='check' size={16} color={getContrastColor(swatchDisplay)} /> : swappable ? <Icon source='swap-horizontal' size={16} color={getContrastColor(swatchDisplay)} /> : taken ? <Icon source='close' size={16} color={getContrastColor(swatchDisplay)} /> : <View />}
148
158
  </TouchableRipple>
149
159
  )
150
160
  })}
@@ -200,6 +210,10 @@ const styles = StyleSheet.create({
200
210
  gap: SWATCHES_GAP,
201
211
  padding: SWATCHES_PADDING
202
212
  },
213
+ tagLabel: {
214
+ fontWeight: '700',
215
+ letterSpacing: 0.5
216
+ },
203
217
  // borderRadius/height/width come from the `size` prop instead (see render-site override) — no
204
218
  // fixed default here, since this style object is shared by every caller regardless of size.
205
219
  trigger: {
@@ -218,9 +232,5 @@ const styles = StyleSheet.create({
218
232
  justifyContent: 'center',
219
233
  paddingHorizontal: 4,
220
234
  width: '100%'
221
- },
222
- tagLabel: {
223
- fontWeight: '700',
224
- letterSpacing: 0.5
225
235
  }
226
236
  })
@@ -53,6 +53,12 @@ export interface SingleSelectSection<T extends string | number> {
53
53
  options: MenuOption<T>[]
54
54
  value: T
55
55
  onChange: (value: T) => void
56
+ // Another seat's currently-selected value in this section, if any — stays in `options` (so the
57
+ // trigger gauge below keeps indexing into the one list every seat shares, instead of each seat's
58
+ // gauge landing wherever its own filtered-down list happens to put the remaining values) but
59
+ // renders disabled and dimmed, unselectable. Same "shown, not removed" treatment as
60
+ // InlineColorPicker's own takenValue, for the same reason.
61
+ takenValue?: T
56
62
  }
57
63
 
58
64
  // Any number of these can be true at once — checkbox-style. Tapping a row toggles just that one and
@@ -250,12 +256,13 @@ function SingleSection({
250
256
  <>
251
257
  {section.options.map((option) => {
252
258
  const selected = option.value === section.value
259
+ const taken = !selected && option.value === section.takenValue
253
260
  const rowColor = selected ? onAccentColor : mutedColor
254
- const itemStyle = [styles.item, selected && { backgroundColor: accentColor }]
261
+ const itemStyle = [styles.item, selected && { backgroundColor: accentColor }, taken && styles.itemTaken]
255
262
  const labelStyle: TextStyle = { fontFamily: labelFontFamily, color: rowColor, fontWeight: selected ? 'bold' : 'normal' }
256
263
  const descriptionStyle: TextStyle = { fontFamily: labelFontFamily, color: rowColor }
257
264
  return (
258
- <TouchableRipple key={option.value} onPress={() => onSelect(option.value)} style={itemStyle}>
265
+ <TouchableRipple key={option.value} disabled={taken} onPress={() => onSelect(option.value)} style={itemStyle}>
259
266
  <View style={styles.itemRow}>
260
267
  {option.icon && <Icon source={option.icon} size={MENU_ITEM_ICON_SIZE} color={rowColor} />}
261
268
  <View style={styles.itemLabelColumn}>
@@ -367,6 +374,11 @@ const styles = StyleSheet.create({
367
374
  flexDirection: 'row',
368
375
  gap: 8
369
376
  },
377
+ // Same opacity as ProfilePicker's rowDisabled / InlineColorPicker's swatchTaken — the fleet's
378
+ // established "shown, not removed" treatment for another seat's own current pick.
379
+ itemTaken: {
380
+ opacity: 0.35
381
+ },
370
382
  menu: {
371
383
  borderRadius: 12,
372
384
  borderWidth: MENU_BORDER_WIDTH,
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { AchievementRow, LOCKED_BADGE_COLOR } from './AchievementRow'
2
2
  export { BaseSettingsDialog, type BaseSettingsDialogProps } from './BaseSettingsDialog'
3
3
  export { BaseStatsScreen } from './BaseStatsScreen'
4
+ export { ContentGutter } from './ContentGutter'
4
5
  export { CornerActionButtons } from './CornerActionButtons'
5
6
  export { MONO_FONT } from './fonts'
6
7
  export { InlineColorPicker } from './InlineColorPicker'