1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Colors, 128, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 const struct { SkColor4f fColor; const char* fName; } kColors[] = {
7 {SkColors::kBlack, "SkColors::kBlack"},
8 {SkColors::kDkGray, "SkColors::kDkGray"},
9 {SkColors::kGray, "SkColors::kGray"},
10 {SkColors::kLtGray, "SkColors::kLtGray"},
11 {SkColors::kWhite, "SkColors::kWhite"},
12 {SkColors::kRed, "SkColors::kRed"},
13 {SkColors::kGreen, "SkColors::kGreen"},
14 {SkColors::kBlue, "SkColors::kBlue"},
15 {SkColors::kYellow, "SkColors::kYellow"},
16 {SkColors::kCyan, "SkColors::kCyan"},
17 {SkColors::kMagenta, "SkColors::kMagenta"},
18 };
19 float y = 0;
20 constexpr float kSize = 256.0f / (sizeof(kColors) / sizeof(kColors[0]));
21 const SkColor4f kBrown{0.5f, 0.25f, 0, 1};
22 for (const auto& c : kColors) {
23 canvas->drawRect(SkRect{0, y, 128, y + kSize}, SkPaint(c.fColor));
24 canvas->drawString(c.fName, 4, y + kSize * 0.7f, SkFont(), SkPaint(kBrown));
25 y += kSize;
26 }
27 }
28 } // END FIDDLE
29