mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 03:25:07 +00:00
LibGUI: Allow specifying per-column text alignment.
This commit is contained in:
parent
ce7019f38c
commit
b4c20789fb
6 changed files with 35 additions and 23 deletions
|
@ -87,9 +87,11 @@ void GTableView::paint_event(GPaintEvent&)
|
|||
|
||||
int x_offset = 0;
|
||||
for (int column_index = 0; column_index < m_model->column_count(); ++column_index) {
|
||||
Rect cell_rect(horizontal_padding + x_offset, y, m_model->column_width(column_index), item_height());
|
||||
painter.draw_text(cell_rect, m_model->data(row_index, column_index), TextAlignment::CenterLeft, text_color);
|
||||
x_offset += m_model->column_width(column_index) + horizontal_padding;
|
||||
auto column_metadata = m_model->column_metadata(column_index);
|
||||
int column_width = column_metadata.preferred_width;
|
||||
Rect cell_rect(horizontal_padding + x_offset, y, column_width, item_height());
|
||||
painter.draw_text(cell_rect, m_model->data(row_index, column_index), column_metadata.text_alignment, text_color);
|
||||
x_offset += column_width + horizontal_padding;
|
||||
}
|
||||
++painted_item_index;
|
||||
};
|
||||
|
@ -103,9 +105,11 @@ void GTableView::paint_event(GPaintEvent&)
|
|||
painter.fill_rect({ 0, 0, width(), header_height() }, Color::LightGray);
|
||||
int x_offset = 0;
|
||||
for (int column_index = 0; column_index < m_model->column_count(); ++column_index) {
|
||||
Rect cell_rect(x_offset, 0, m_model->column_width(column_index) + horizontal_padding, item_height());
|
||||
auto column_metadata = m_model->column_metadata(column_index);
|
||||
int column_width = column_metadata.preferred_width;
|
||||
Rect cell_rect(x_offset, 0, column_width + horizontal_padding, item_height());
|
||||
painter.draw_text(cell_rect.translated(horizontal_padding, 0), m_model->column_name(column_index), TextAlignment::CenterLeft, Color::Black);
|
||||
x_offset += m_model->column_width(column_index) + horizontal_padding;
|
||||
x_offset += column_width + horizontal_padding;
|
||||
painter.draw_line(cell_rect.top_left(), cell_rect.bottom_left(), Color::White);
|
||||
painter.draw_line(cell_rect.top_right(), cell_rect.bottom_right(), Color::DarkGray);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue