]> git.cworth.org Git - lmno.games/commitdiff
Don't waste space for glyphs that are not full height.
authorCarl Worth <cworth@cworth.org>
Sat, 20 Jun 2020 17:48:26 +0000 (10:48 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 20 Jun 2020 17:48:26 +0000 (10:48 -0700)
For "Single" through" Squat-T" only two rows of dots are needed to
display the full glyph, so it's wasteful to have a full-size glyph. We
fix this by dynamically computing a correct viewBox for the glyph's
SVG given the dots that are present, and then letting the "glyph"
class styling automatically determine a height based on its children,
rather than explicitly setting it to the full height, assuming a
square.

scribe/scribe.css
scribe/scribe.jsx

index c3852b1c2790e2436bbe89d01a2beae19de4272e..a3b5d2ce676aef8a3ac874157a8de68b2ec26ccd 100644 (file)
@@ -93,5 +93,4 @@
 
 .glyph {
     width: 8vw;
-    height: 8vw;
 }
index 7b68ff05afe8ac16d78b74d6b74d49b7f4fe73cf..3caf03c87d313ab3e582bfc68bb0da020143c6dd 100644 (file)
@@ -169,6 +169,16 @@ function Glyph(props) {
 
   const glyph_dots = [];
 
+  let last_square = 0;
+  for (let i = 0; i < 9; i++) {
+    if (props.squares[i])
+      last_square = i;
+  }
+
+  const height = Math.floor(20 * (Math.floor(last_square / 3) + 1));
+
+  const viewbox=`0 0 60 ${height}`;
+
   for (let row = 0; row < 3; row++) {
     for (let col = 0; col < 3; col++) {
       if (props.squares[3 * row + col]) {
@@ -176,6 +186,7 @@ function Glyph(props) {
         let cx = 10 + 20 * col;
         glyph_dots.push(
           <circle
+            key={3 * row + col}
             cx={cx}
             cy={cy}
             r="8"
@@ -188,7 +199,7 @@ function Glyph(props) {
   return (<div className="glyph-and-name">
             {props.name}
             <div className="glyph">
-              <svg viewBox="0 0 60 60">
+              <svg viewBox={viewbox}>
                 <g fill="#287789">
                   {glyph_dots}
                 </g>