|
8 | 8 | #include <winrt/Microsoft.UI.Xaml.Automation.Peers.h> |
9 | 9 | #include <winrt/Microsoft.UI.Xaml.Automation.h> |
10 | 10 | #include <winrt/Microsoft.UI.Xaml.Media.h> |
| 11 | +#include <winrt/Windows.ApplicationModel.DataTransfer.h> |
11 | 12 | #include <winrt/Windows.UI.Text.h> |
12 | 13 |
|
13 | 14 | #include "Log.h" |
@@ -181,6 +182,194 @@ FrameworkElement MakeEmptyStateCard(winrt::hstring const& glyph, winrt::hstring |
181 | 182 | return card; |
182 | 183 | } |
183 | 184 |
|
| 185 | +// ---- the Wave-2 component kit (spec §12) ----------------------------------- |
| 186 | + |
| 187 | +FrameworkElement MakePageHeader(winrt::hstring const& title, |
| 188 | + winrt::hstring const& description) { |
| 189 | + StackPanel column; |
| 190 | + column.Spacing(4); |
| 191 | + column.VerticalAlignment(VerticalAlignment::Top); |
| 192 | + |
| 193 | + TextBlock titleBlock; |
| 194 | + titleBlock.Text(title); |
| 195 | + if (auto style = StyleByKey(L"UrTitleTextStyle")) titleBlock.Style(style); |
| 196 | + column.Children().Append(titleBlock); |
| 197 | + |
| 198 | + if (!description.empty()) { |
| 199 | + TextBlock desc; |
| 200 | + desc.Text(description); |
| 201 | + if (auto style = StyleByKey(L"UrBodyTextStyle")) desc.Style(style); |
| 202 | + desc.Foreground(urnw::colors::MutedBrush()); |
| 203 | + desc.TextWrapping(TextWrapping::Wrap); |
| 204 | + // ~60ch reading measure, per the spec's page-description rule |
| 205 | + desc.MaxWidth(560); |
| 206 | + desc.HorizontalAlignment(HorizontalAlignment::Left); |
| 207 | + column.Children().Append(desc); |
| 208 | + } |
| 209 | + return column; |
| 210 | +} |
| 211 | + |
| 212 | +MetricCard MakeMetricCard(winrt::hstring const& label, winrt::hstring const& value) { |
| 213 | + MetricCard card; |
| 214 | + card.root = Controls::Border(); |
| 215 | + if (auto style = StyleByKey(L"UrStatTileStyle")) card.root.Style(style); |
| 216 | + |
| 217 | + StackPanel column; |
| 218 | + card.label = TextBlock(); |
| 219 | + card.label.Text(label); |
| 220 | + if (auto style = StyleByKey(L"UrStatLabelStyle")) card.label.Style(style); |
| 221 | + column.Children().Append(card.label); |
| 222 | + |
| 223 | + card.value = TextBlock(); |
| 224 | + card.value.Text(value); |
| 225 | + if (auto style = StyleByKey(L"UrStatValueStyle")) card.value.Style(style); |
| 226 | + column.Children().Append(card.value); |
| 227 | + |
| 228 | + card.root.Child(column); |
| 229 | + return card; |
| 230 | +} |
| 231 | + |
| 232 | +SettingsCard MakeSettingsCard(winrt::hstring const& glyph, winrt::hstring const& title, |
| 233 | + winrt::hstring const& description) { |
| 234 | + SettingsCard card; |
| 235 | + card.root = Controls::Border(); |
| 236 | + if (auto style = StyleByKey(L"UrCardStyle")) card.root.Style(style); |
| 237 | + |
| 238 | + Grid row; |
| 239 | + row.ColumnSpacing(12); |
| 240 | + { Controls::ColumnDefinition c; c.Width(GridLengthHelper::Auto()); row.ColumnDefinitions().Append(c); } |
| 241 | + { Controls::ColumnDefinition c; c.Width(GridLengthHelper::FromValueAndType(1, GridUnitType::Star)); row.ColumnDefinitions().Append(c); } |
| 242 | + { Controls::ColumnDefinition c; c.Width(GridLengthHelper::Auto()); row.ColumnDefinitions().Append(c); } |
| 243 | + |
| 244 | + FontIcon icon; |
| 245 | + icon.FontFamily(IconFont()); |
| 246 | + icon.Glyph(glyph); |
| 247 | + icon.FontSize(20); |
| 248 | + icon.Foreground(urnw::colors::MutedBrush()); |
| 249 | + icon.VerticalAlignment(VerticalAlignment::Center); |
| 250 | + Automation::AutomationProperties::SetAccessibilityView( |
| 251 | + icon, Automation::Peers::AccessibilityView::Raw); |
| 252 | + Grid::SetColumn(icon, 0); |
| 253 | + row.Children().Append(icon); |
| 254 | + |
| 255 | + StackPanel text; |
| 256 | + text.Spacing(2); |
| 257 | + text.VerticalAlignment(VerticalAlignment::Center); |
| 258 | + Grid::SetColumn(text, 1); |
| 259 | + card.title = TextBlock(); |
| 260 | + card.title.Text(title); |
| 261 | + if (auto style = StyleByKey(L"UrBodyTextStyle")) card.title.Style(style); |
| 262 | + card.title.TextWrapping(TextWrapping::Wrap); |
| 263 | + text.Children().Append(card.title); |
| 264 | + card.description = TextBlock(); |
| 265 | + card.description.Text(description); |
| 266 | + if (auto style = StyleByKey(L"UrCaptionTextStyle")) card.description.Style(style); |
| 267 | + card.description.TextWrapping(TextWrapping::Wrap); |
| 268 | + // an empty description must not spend the panel's spacing on nothing |
| 269 | + card.description.Visibility(description.empty() ? Visibility::Collapsed |
| 270 | + : Visibility::Visible); |
| 271 | + text.Children().Append(card.description); |
| 272 | + row.Children().Append(text); |
| 273 | + |
| 274 | + card.trailing = Grid(); |
| 275 | + card.trailing.HorizontalAlignment(HorizontalAlignment::Right); |
| 276 | + card.trailing.VerticalAlignment(VerticalAlignment::Center); |
| 277 | + Grid::SetColumn(card.trailing, 2); |
| 278 | + row.Children().Append(card.trailing); |
| 279 | + |
| 280 | + card.root.Child(row); |
| 281 | + return card; |
| 282 | +} |
| 283 | + |
| 284 | +CopyField MakeCopyField(winrt::hstring const& label, winrt::hstring const& value, |
| 285 | + bool masked) { |
| 286 | + CopyField field; |
| 287 | + StackPanel column; |
| 288 | + column.Spacing(2); |
| 289 | + |
| 290 | + TextBlock caption; |
| 291 | + caption.Text(label); |
| 292 | + if (auto style = StyleByKey(L"UrLabelStyle")) caption.Style(style); |
| 293 | + column.Children().Append(caption); |
| 294 | + |
| 295 | + Grid row; |
| 296 | + row.ColumnSpacing(8); |
| 297 | + { Controls::ColumnDefinition c; c.Width(GridLengthHelper::FromValueAndType(1, GridUnitType::Star)); row.ColumnDefinitions().Append(c); } |
| 298 | + { Controls::ColumnDefinition c; c.Width(GridLengthHelper::Auto()); row.ColumnDefinitions().Append(c); } |
| 299 | + |
| 300 | + field.value = TextBlock(); |
| 301 | + // masked DISPLAY only; the real value is captured by the copy button below |
| 302 | + field.value.Text(masked ? winrt::hstring{L"••••••••"} : value); |
| 303 | + if (auto style = StyleByKey(L"UrBodyTextStyle")) field.value.Style(style); |
| 304 | + field.value.TextTrimming(TextTrimming::CharacterEllipsis); |
| 305 | + field.value.VerticalAlignment(VerticalAlignment::Center); |
| 306 | + Grid::SetColumn(field.value, 0); |
| 307 | + row.Children().Append(field.value); |
| 308 | + |
| 309 | + field.copy = Button(); |
| 310 | + field.copy.Background(nullptr); |
| 311 | + field.copy.BorderThickness(ThicknessHelper::FromUniformLength(0)); |
| 312 | + field.copy.Padding(ThicknessHelper::FromLengths(8, 4, 8, 4)); |
| 313 | + field.copy.VerticalAlignment(VerticalAlignment::Center); |
| 314 | + FontIcon copyGlyph; |
| 315 | + copyGlyph.FontFamily(IconFont()); |
| 316 | + copyGlyph.Glyph(L""); // Copy |
| 317 | + copyGlyph.FontSize(16); |
| 318 | + copyGlyph.Foreground(urnw::colors::MutedBrush()); |
| 319 | + field.copy.Content(copyGlyph); |
| 320 | + // the button carries the action name a screen reader announces |
| 321 | + Automation::AutomationProperties::SetName(field.copy, winrt::hstring{L"Copy "} + label); |
| 322 | + // the full value is copied, never the mask |
| 323 | + field.copy.Click([value](auto const&, auto const&) { |
| 324 | + winrt::Windows::ApplicationModel::DataTransfer::DataPackage package; |
| 325 | + package.SetText(value); |
| 326 | + winrt::Windows::ApplicationModel::DataTransfer::Clipboard::SetContent(package); |
| 327 | + }); |
| 328 | + Grid::SetColumn(field.copy, 1); |
| 329 | + row.Children().Append(field.copy); |
| 330 | + |
| 331 | + column.Children().Append(row); |
| 332 | + field.value.VerticalAlignment(VerticalAlignment::Center); |
| 333 | + field.root = column; |
| 334 | + return field; |
| 335 | +} |
| 336 | + |
| 337 | +PlanUsageCard MakePlanUsageCard(winrt::hstring const& planLabel, |
| 338 | + winrt::hstring const& planValue) { |
| 339 | + PlanUsageCard card; |
| 340 | + card.root = Controls::Border(); |
| 341 | + if (auto style = StyleByKey(L"UrCardStyle")) card.root.Style(style); |
| 342 | + |
| 343 | + StackPanel column; |
| 344 | + column.Spacing(8); |
| 345 | + |
| 346 | + TextBlock caption; |
| 347 | + caption.Text(planLabel); |
| 348 | + if (auto style = StyleByKey(L"UrLabelStyle")) caption.Style(style); |
| 349 | + column.Children().Append(caption); |
| 350 | + |
| 351 | + card.planValue = TextBlock(); |
| 352 | + card.planValue.Text(planValue); |
| 353 | + if (auto style = StyleByKey(L"UrStatValueStyle")) card.planValue.Style(style); |
| 354 | + card.planValue.FontSize(22); |
| 355 | + column.Children().Append(card.planValue); |
| 356 | + |
| 357 | + // the caller constructs a urnw::UsageBar into this host (the bar is not a XAML |
| 358 | + // control), and its legend into the panel below - the same wiring the connect |
| 359 | + // drawer and Account already do around their own hosts. |
| 360 | + card.usageBarHost = Grid(); |
| 361 | + card.usageBarHost.Height(32); |
| 362 | + column.Children().Append(card.usageBarHost); |
| 363 | + |
| 364 | + card.legend = StackPanel(); |
| 365 | + card.legend.Orientation(Controls::Orientation::Horizontal); |
| 366 | + card.legend.Spacing(16); |
| 367 | + column.Children().Append(card.legend); |
| 368 | + |
| 369 | + card.root.Child(column); |
| 370 | + return card; |
| 371 | +} |
| 372 | + |
184 | 373 | void ApplySupportingText(TextBlock const& line, winrt::hstring const& text, |
185 | 374 | ValidationState state) { |
186 | 375 | if (!line) return; |
|
0 commit comments