summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-26 20:34:07 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-26 20:34:07 +0200
commitc4347a16cf4a8f800aac9b2fe3929774031fbb60 (patch)
tree0338d422152157b3bb389820dd78709c2d1ed2f8 /Libraries/LibGUI
parentd125c624c6ac5f7c5550cfbbf6ee96b647a06001 (diff)
downloadserenity-c4347a16cf4a8f800aac9b2fe3929774031fbb60.zip
LibGUI: Make AbstractTableView row height configurable
The row height is per-table, not per-row, but this is still nice.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/AbstractTableView.cpp19
-rw-r--r--Libraries/LibGUI/AbstractTableView.h4
-rw-r--r--Libraries/LibGUI/TableView.cpp10
-rw-r--r--Libraries/LibGUI/TreeView.cpp8
-rw-r--r--Libraries/LibGUI/TreeView.h2
5 files changed, 27 insertions, 16 deletions
diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp
index 6f429ba33d..08795deaef 100644
--- a/Libraries/LibGUI/AbstractTableView.cpp
+++ b/Libraries/LibGUI/AbstractTableView.cpp
@@ -86,7 +86,7 @@ void AbstractTableView::update_column_sizes()
auto cell_data = model.index(row, column).data();
int cell_width = 0;
if (cell_data.is_icon()) {
- cell_width = item_height();
+ cell_width = row_height();
} else if (cell_data.is_bitmap()) {
cell_width = cell_data.as_bitmap().width();
} else if (cell_data.is_valid()) {
@@ -109,7 +109,7 @@ void AbstractTableView::update_row_sizes()
for (int row = 0; row < row_count; ++row) {
if (!column_header().is_section_visible(row))
continue;
- row_header().set_section_size(row, item_height());
+ row_header().set_section_size(row, row_height());
}
}
@@ -125,7 +125,7 @@ void AbstractTableView::update_content_size()
if (column_header().is_section_visible(i))
content_width += column_width(i) + horizontal_padding() * 2;
}
- int content_height = item_count() * item_height();
+ int content_height = item_count() * row_height();
set_content_size({ content_width, content_height });
set_size_occupied_by_fixed_elements({ row_header().width(), column_header().height() });
@@ -291,7 +291,7 @@ Gfx::IntRect AbstractTableView::content_rect(int row, int column) const
for (int i = 0; i < column; ++i)
x += column_width(i) + horizontal_padding() * 2;
- return { row_rect.x() + x, row_rect.y(), column_width(column) + horizontal_padding() * 2, item_height() };
+ return { row_rect.x() + x, row_rect.y(), column_width(column) + horizontal_padding() * 2, row_height() };
}
Gfx::IntRect AbstractTableView::content_rect(const ModelIndex& index) const
@@ -301,7 +301,7 @@ Gfx::IntRect AbstractTableView::content_rect(const ModelIndex& index) const
Gfx::IntRect AbstractTableView::row_rect(int item_index) const
{
- return { row_header().is_visible() ? row_header().width() : 0, column_header().height() + (item_index * item_height()), max(content_size().width(), width()), item_height() };
+ return { row_header().is_visible() ? row_header().width() : 0, column_header().height() + (item_index * row_height()), max(content_size().width(), width()), row_height() };
}
Gfx::IntPoint AbstractTableView::adjusted_position(const Gfx::IntPoint& position) const
@@ -374,4 +374,13 @@ void AbstractTableView::layout_headers()
}
}
+void AbstractTableView::set_row_height(int height)
+{
+ if (m_row_height == height)
+ return;
+
+ m_row_height = height;
+ update_content_size();
+}
+
}
diff --git a/Libraries/LibGUI/AbstractTableView.h b/Libraries/LibGUI/AbstractTableView.h
index dcc44cc1a2..4341a5d139 100644
--- a/Libraries/LibGUI/AbstractTableView.h
+++ b/Libraries/LibGUI/AbstractTableView.h
@@ -39,7 +39,8 @@ public:
class AbstractTableView : public AbstractView {
public:
- int item_height() const { return 16; }
+ int row_height() const { return m_row_height; }
+ void set_row_height(int);
bool alternating_row_colors() const { return m_alternating_row_colors; }
void set_alternating_row_colors(bool b) { m_alternating_row_colors = b; }
@@ -119,6 +120,7 @@ private:
bool m_alternating_row_colors { true };
bool m_highlight_selected_rows { true };
int m_horizontal_padding { 5 };
+ int m_row_height { 16 };
};
}
diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp
index ea4b25aac5..dc773f1349 100644
--- a/Libraries/LibGUI/TableView.cpp
+++ b/Libraries/LibGUI/TableView.cpp
@@ -82,7 +82,7 @@ void TableView::paint_event(PaintEvent& event)
for (int row_index = first_visible_row; row_index <= last_visible_row; ++row_index) {
bool is_selected_row = selection().contains_row(row_index);
- int y = y_offset + painted_item_index * item_height();
+ int y = y_offset + painted_item_index * row_height();
Color background_color;
Color key_column_background_color;
@@ -106,7 +106,7 @@ void TableView::paint_event(PaintEvent& event)
continue;
int column_width = this->column_width(column_index);
bool is_key_column = m_key_column == column_index;
- Gfx::IntRect cell_rect(horizontal_padding() + x, y, column_width, item_height());
+ Gfx::IntRect cell_rect(horizontal_padding() + x, y, column_width, row_height());
auto cell_rect_for_fill = cell_rect.inflated(horizontal_padding() * 2, 0);
if (is_key_column)
painter.fill_rect(cell_rect_for_fill, key_column_background_color);
@@ -145,7 +145,7 @@ void TableView::paint_event(PaintEvent& event)
++painted_item_index;
};
- Gfx::IntRect unpainted_rect(0, column_header().height() + painted_item_index * item_height(), exposed_width, height());
+ Gfx::IntRect unpainted_rect(0, column_header().height() + painted_item_index * row_height(), exposed_width, height());
if (fill_with_background_color())
painter.fill_rect(unpainted_rect, widget_background_color);
}
@@ -176,7 +176,7 @@ void TableView::keydown_event(KeyEvent& event)
return;
}
if (event.key() == KeyCode::Key_PageUp) {
- int items_per_page = visible_content_rect().height() / item_height();
+ int items_per_page = visible_content_rect().height() / row_height();
auto old_index = selection().first();
auto new_index = model.index(max(0, old_index.row() - items_per_page), old_index.column());
if (model.is_valid(new_index)) {
@@ -187,7 +187,7 @@ void TableView::keydown_event(KeyEvent& event)
return;
}
if (event.key() == KeyCode::Key_PageDown) {
- int items_per_page = visible_content_rect().height() / item_height();
+ int items_per_page = visible_content_rect().height() / row_height();
auto old_index = selection().first();
auto new_index = model.index(min(model.row_count() - 1, old_index.row() + items_per_page), old_index.column());
if (model.is_valid(new_index)) {
diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp
index 76194c125c..9ba864cebc 100644
--- a/Libraries/LibGUI/TreeView.cpp
+++ b/Libraries/LibGUI/TreeView.cpp
@@ -175,7 +175,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const
auto node_text = index.data().to_string();
Gfx::IntRect rect = {
x_offset, y_offset,
- icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), item_height()
+ icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), row_height()
};
Gfx::IntRect toggle_rect;
if (row_count_at_index > 0) {
@@ -185,7 +185,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const
}
if (callback(index, rect, toggle_rect, indent_level) == IterationDecision::Break)
return IterationDecision::Break;
- y_offset += item_height();
+ y_offset += row_height();
// NOTE: Skip traversing children if this index is closed!
if (!metadata.open)
return IterationDecision::Continue;
@@ -288,7 +288,7 @@ void TreeView::paint_event(PaintEvent& event)
painter.draw_rect(toggle_rect, text_color);
if (column_index != tree_column) {
- Gfx::IntRect cell_rect(horizontal_padding() + x_offset, rect.y(), column_width, item_height());
+ Gfx::IntRect cell_rect(horizontal_padding() + x_offset, rect.y(), column_width, row_height());
auto cell_index = model.index(index.row(), column_index, index.parent());
if (auto* delegate = column_painting_delegate(column_index)) {
@@ -331,7 +331,7 @@ void TreeView::paint_event(PaintEvent& event)
auto parent_of_index_at_indent = index_at_indent.parent();
bool index_at_indent_is_last_in_parent = index_at_indent.row() == model.row_count(parent_of_index_at_indent) - 1;
Gfx::IntPoint a { tree_column_x_offset + horizontal_padding() + indent_width_in_pixels() * i - icon_size() / 2, rect.y() - 2 };
- Gfx::IntPoint b { a.x(), a.y() + item_height() - 1 };
+ Gfx::IntPoint b { a.x(), a.y() + row_height() - 1 };
if (index_at_indent_is_last_in_parent)
b.set_y(rect.center().y());
if (!(i != indent_level && index_at_indent_is_last_in_parent))
diff --git a/Libraries/LibGUI/TreeView.h b/Libraries/LibGUI/TreeView.h
index 32142429de..4ce99842a8 100644
--- a/Libraries/LibGUI/TreeView.h
+++ b/Libraries/LibGUI/TreeView.h
@@ -58,7 +58,7 @@ protected:
private:
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&, bool& is_toggle) const override;
- int item_height() const { return 16; }
+ int row_height() const { return 16; }
int max_item_width() const { return frame_inner_rect().width(); }
int indent_width_in_pixels() const { return 16; }
int icon_size() const { return 16; }