From c952c57a99b78855d23dcbef035340e9a819d94e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 14 Sep 2021 21:17:50 -0600 Subject: [PATCH] canvas: actually follow CSS conventions for 1/2/3/4 arguments in padding --- libs/canvas/canvas/types.h | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/libs/canvas/canvas/types.h b/libs/canvas/canvas/types.h index 73149f8199..df40e1fbec 100644 --- a/libs/canvas/canvas/types.h +++ b/libs/canvas/canvas/types.h @@ -222,19 +222,37 @@ struct FourDimensions { FourDimensions (Distance u, Distance r = -1., Distance d = -1., Distance l = -1.) { - /* CSS style defaults: if only 1 value is givem, set all 4 to - * that value; if 2 values are supplied, up uses the first, - * other 3 use the second; if 3 values are supplied, up uses - * the first, right uses the second, other 2 use the - * third. etc. + /* CSS style defaults: see https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties */ - Distance last = u; + std::vector args; - up = u; - if (r >= 0) { last = r; } right = last; - if (d >= 0) { last = d; } down = last; - if (l >= 0) { last = l; } left = last; + args.push_back (u); + + if (r >= 0) { args.push_back (r); } + if (d >= 0) { args.push_back (d); } + if (l >= 0) { args.push_back (l); } + + switch (args.size()) { + case 1: + up = right = down = left = args[0]; + break; + case 2: + up = down = args[0]; + left = right = args[1]; + break; + case 3: + up = args[0]; + left = right = args[1]; + down = args[2]; + break; + case 4: + up = args[0]; + right = args[1]; + down = args[2]; + left = args[3]; + break; + } } };