summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-26 16:34:10 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-26 17:00:40 +0200
commit9a0f40d4b5d8f5751432a88b1a479add8c814813 (patch)
tree065a705193f837c4e609f168028d7f48691b8cfa /Libraries
parent8cacac32b5adf8d23cc001c0c71509b0266f2abc (diff)
downloadserenity-9a0f40d4b5d8f5751432a88b1a479add8c814813.zip
LibGUI: Add a top-left-corner button to table views
If both the row and column headers are visible, we now also show a button in the top left corner. This avoids the headers overlapping each other when you scroll the contents. In the future, this could be hooked up to a "select all" action.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/AbstractTableView.cpp14
-rw-r--r--Libraries/LibGUI/AbstractTableView.h1
2 files changed, 14 insertions, 1 deletions
diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp
index 4994cca09d..6f429ba33d 100644
--- a/Libraries/LibGUI/AbstractTableView.cpp
+++ b/Libraries/LibGUI/AbstractTableView.cpp
@@ -28,6 +28,7 @@
#include <AK/Vector.h>
#include <LibGUI/AbstractTableView.h>
#include <LibGUI/Action.h>
+#include <LibGUI/Button.h>
#include <LibGUI/HeaderView.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Model.h>
@@ -40,6 +41,10 @@ namespace GUI {
AbstractTableView::AbstractTableView()
{
+ m_corner_button = add<Button>();
+ m_corner_button->move_to_back();
+ m_corner_button->set_background_role(Gfx::ColorRole::ThreedShadow1);
+ m_corner_button->set_fill_with_background_color(true);
m_column_header = add<HeaderView>(*this, Gfx::Orientation::Horizontal);
m_column_header->move_to_back();
m_row_header = add<HeaderView>(*this, Gfx::Orientation::Vertical);
@@ -296,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 * item_height()), max(content_size().width(), width()), item_height() };
}
Gfx::IntPoint AbstractTableView::adjusted_position(const Gfx::IntPoint& position) const
@@ -360,6 +365,13 @@ void AbstractTableView::layout_headers()
int y = (frame_thickness() + (column_header().is_visible() ? column_header().height() : 0)) + -vertical_scrollbar().value();
row_header().set_relative_rect(x, y, row_header().preferred_size().width(), content_height());
}
+
+ if (row_header().is_visible() && column_header().is_visible()) {
+ m_corner_button->set_relative_rect(frame_thickness(), frame_thickness(), row_header().width(), column_header().height());
+ m_corner_button->set_visible(true);
+ } else {
+ m_corner_button->set_visible(false);
+ }
}
}
diff --git a/Libraries/LibGUI/AbstractTableView.h b/Libraries/LibGUI/AbstractTableView.h
index 34ca3b4950..dcc44cc1a2 100644
--- a/Libraries/LibGUI/AbstractTableView.h
+++ b/Libraries/LibGUI/AbstractTableView.h
@@ -112,6 +112,7 @@ private:
RefPtr<HeaderView> m_column_header;
RefPtr<HeaderView> m_row_header;
+ RefPtr<Button> m_corner_button;
HashMap<int, OwnPtr<TableCellPaintingDelegate>> m_column_painting_delegate;