1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef UI_VIEWS_CONTROLS_TABLE_TABLE_UTILS_H_ 6 #define UI_VIEWS_CONTROLS_TABLE_TABLE_UTILS_H_ 7 8 #include <vector> 9 10 #include "ui/base/models/table_model.h" 11 #include "ui/views/views_export.h" 12 13 namespace gfx { 14 class Font; 15 } 16 17 namespace views { 18 19 class TableView; 20 21 VIEWS_EXPORT extern const int kUnspecifiedColumnWidth; 22 23 // Returns the width needed to display the contents of the specified column. 24 // This is used internally by CalculateTableColumnSizes() and generally not 25 // useful by itself. |header_padding| is padding added to the header. 26 VIEWS_EXPORT int WidthForContent(const gfx::Font& header_font, 27 const gfx::Font& content_font, 28 int padding, 29 int header_padding, 30 const ui::TableColumn& column, 31 ui::TableModel* model); 32 33 // Determines the width for each of the specified columns. |width| is the width 34 // to fit the columns into. |header_font| the font used to draw the header and 35 // |content_font| the header used to draw the content. |padding| is extra 36 // horizontal spaced added to each cell, and |header_padding| added to the 37 // width needed for the header. 38 VIEWS_EXPORT std::vector<int> CalculateTableColumnSizes( 39 int width, 40 int first_column_padding, 41 const gfx::Font& header_font, 42 const gfx::Font& content_font, 43 int padding, 44 int header_padding, 45 const std::vector<ui::TableColumn>& columns, 46 ui::TableModel* model); 47 48 // Converts a TableColumn::Alignment to the alignment for drawing the string. 49 int TableColumnAlignmentToCanvasAlignment(ui::TableColumn::Alignment alignment); 50 51 // Returns the index of the closest visible column index to |x|. Return value is 52 // in terms of table->visible_columns(). 53 int GetClosestVisibleColumnIndex(const TableView* table, int x); 54 55 } // namespace views 56 57 #endif // UI_VIEWS_CONTROLS_TABLE_TABLE_UTILS_H_ 58