1 // Copyright 2018 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef THIRD_PARTY_QUIC_TRACE_TOOLS_TABLE_H_ 16 #define THIRD_PARTY_QUIC_TRACE_TOOLS_TABLE_H_ 17 18 #include "tools/render/geometry_util.h" 19 #include "tools/render/rectangle_renderer.h" 20 #include "tools/render/text.h" 21 22 namespace quic_trace { 23 namespace render { 24 25 // Represents a simple key-value tables with optional section headers. 26 class Table { 27 public: 28 Table(const ProgramState* state, 29 TextRenderer* text_factory, 30 RectangleRenderer* rectangles); 31 32 void AddHeader(const std::string& text); 33 void AddRow(const std::string& label, const std::string& value); 34 // Compute the layout parameters and return the size of the table. Has to be 35 // caleld before Draw(). 36 vec2 Layout(); 37 // Draw the table at the specified position. Layout() MUST be called 38 // beforehand. 39 void Draw(vec2 position); 40 41 private: 42 struct Row { 43 std::shared_ptr<const Text> header; 44 std::shared_ptr<const Text> label; 45 std::shared_ptr<const Text> value; 46 47 int y_offset; 48 int height; 49 }; 50 51 const ProgramState* state_; 52 TextRenderer* text_renderer_; 53 RectangleRenderer* rectangles_; 54 55 std::vector<Row> rows_; 56 int width_; 57 int height_; 58 int spacing_; 59 }; 60 61 } // namespace render 62 } // namespace quic_trace 63 64 #endif // THIRD_PARTY_QUIC_TRACE_TOOLS_TABLE_H_ 65