mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:08:11 +00:00
LibGUI: Make AbstractTableView and TableView more customisable
This patchset adds a few getters/setters to AbstractTableView to make its looks more customisable: - Header width & text alignment - Default column width - Ability to disable selected row highlighting
This commit is contained in:
parent
697faba147
commit
e1a819827c
3 changed files with 31 additions and 5 deletions
|
@ -165,7 +165,7 @@ void AbstractTableView::paint_headers(Painter& painter)
|
|||
auto text_rect = cell_rect.translated(horizontal_padding(), 0);
|
||||
if (pressed)
|
||||
text_rect.move_by(1, 1);
|
||||
painter.draw_text(text_rect, text, header_font(), Gfx::TextAlignment::CenterLeft, palette().button_text());
|
||||
painter.draw_text(text_rect, text, header_font(), column_header_alignment(column_index), palette().button_text());
|
||||
x_offset += column_width + horizontal_padding() * 2;
|
||||
}
|
||||
}
|
||||
|
@ -249,6 +249,23 @@ int AbstractTableView::column_width(int column_index) const
|
|||
return column_data(column_index).width;
|
||||
}
|
||||
|
||||
void AbstractTableView::set_column_width(int column, int width)
|
||||
{
|
||||
column_data(column).width = width;
|
||||
}
|
||||
|
||||
Gfx::TextAlignment AbstractTableView::column_header_alignment(int column_index) const
|
||||
{
|
||||
if (!model())
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
return column_data(column_index).header_alignment;
|
||||
}
|
||||
|
||||
void AbstractTableView::set_column_header_alignment(int column, Gfx::TextAlignment alignment)
|
||||
{
|
||||
column_data(column).header_alignment = alignment;
|
||||
}
|
||||
|
||||
void AbstractTableView::mousemove_event(MouseEvent& event)
|
||||
{
|
||||
if (!model())
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
|
||||
bool alternating_row_colors() const { return m_alternating_row_colors; }
|
||||
void set_alternating_row_colors(bool b) { m_alternating_row_colors = b; }
|
||||
bool highlight_selected_rows() const { return m_highlight_selected_rows; }
|
||||
void set_highlight_selected_rows(bool b) { m_highlight_selected_rows = b; }
|
||||
|
||||
int header_height() const { return m_headers_visible ? 16 : 0; }
|
||||
|
||||
|
@ -52,6 +54,12 @@ public:
|
|||
bool is_column_hidden(int) const;
|
||||
void set_column_hidden(int, bool);
|
||||
|
||||
int column_width(int column) const;
|
||||
void set_column_width(int column, int width);
|
||||
|
||||
Gfx::TextAlignment column_header_alignment(int column) const;
|
||||
void set_column_header_alignment(int column, Gfx::TextAlignment);
|
||||
|
||||
void set_cell_painting_delegate(int column, OwnPtr<TableCellPaintingDelegate>&&);
|
||||
|
||||
int horizontal_padding() const { return m_horizontal_padding; }
|
||||
|
@ -97,6 +105,7 @@ protected:
|
|||
bool has_initialized_width { false };
|
||||
bool visibility { true };
|
||||
RefPtr<Action> visibility_action;
|
||||
Gfx::TextAlignment header_alignment { Gfx::TextAlignment::CenterLeft };
|
||||
OwnPtr<TableCellPaintingDelegate> cell_painting_delegate;
|
||||
};
|
||||
ColumnData& column_data(int column) const;
|
||||
|
@ -107,7 +116,6 @@ protected:
|
|||
RefPtr<Menu> m_header_context_menu;
|
||||
|
||||
Gfx::IntRect column_resize_grabbable_rect(int) const;
|
||||
int column_width(int) const;
|
||||
void update_content_size();
|
||||
virtual void update_column_sizes();
|
||||
virtual int item_count() const;
|
||||
|
@ -116,6 +124,7 @@ private:
|
|||
bool m_headers_visible { true };
|
||||
bool m_in_column_resize { false };
|
||||
bool m_alternating_row_colors { true };
|
||||
bool m_highlight_selected_rows { true };
|
||||
int m_horizontal_padding { 5 };
|
||||
Gfx::IntPoint m_column_resize_origin;
|
||||
int m_column_resize_original_width { 0 };
|
||||
|
|
|
@ -84,7 +84,7 @@ void TableView::paint_event(PaintEvent& event)
|
|||
|
||||
Color background_color;
|
||||
Color key_column_background_color;
|
||||
if (is_selected_row) {
|
||||
if (is_selected_row && highlight_selected_rows()) {
|
||||
background_color = is_focused() ? palette().selection() : palette().inactive_selection();
|
||||
key_column_background_color = is_focused() ? palette().selection() : palette().inactive_selection();
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue