Tweak viewer's shader panel

Base the box size on the shader length (within reason).

Change-Id: If847cb4de0cea3cb2267f284fd5bbb653f25e185
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/311455
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 2c1a338..eb517e0 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -2320,12 +2320,14 @@
                         doSave = true;
                     }
                     if (inTreeNode) {
-                        // Full width, and a reasonable amount of space for each shader.
-                        ImVec2 boxSize(-1.0f, ImGui::GetTextLineHeight() * 20.0f);
-                        ImGui::InputTextMultiline("##VP", &entry.fShader[kVertex_GrShaderType],
-                                                  boxSize);
-                        ImGui::InputTextMultiline("##FP", &entry.fShader[kFragment_GrShaderType],
-                                                  boxSize);
+                        auto stringBox = [](const char* label, std::string* str) {
+                            // Full width, and not too much space for each shader
+                            int lines = std::count(str->begin(), str->end(), '\n') + 2;
+                            ImVec2 boxSize(-1.0f, ImGui::GetTextLineHeight() * std::min(lines, 30));
+                            ImGui::InputTextMultiline(label, str, boxSize);
+                        };
+                        stringBox("##VP", &entry.fShader[kVertex_GrShaderType]);
+                        stringBox("##FP", &entry.fShader[kFragment_GrShaderType]);
                         ImGui::TreePop();
                     }
                 }