summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-28 16:52:06 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-28 17:09:30 +0200
commit2222fc5e0845af594859ea8e49248505133c9737 (patch)
tree0f83b34b0a1c914ab11b5e4ee291f0da03049ebc /Libraries/LibGUI
parent6614ee703bd867f3f159019e72ac72a37e19ff61 (diff)
downloadserenity-2222fc5e0845af594859ea8e49248505133c9737.zip
LibGUI: Add optional grid and cursor styles to TableView
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/TableView.cpp25
-rw-r--r--Libraries/LibGUI/TableView.h22
2 files changed, 47 insertions, 0 deletions
diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp
index af3295f75c..a3581d9594 100644
--- a/Libraries/LibGUI/TableView.cpp
+++ b/Libraries/LibGUI/TableView.cpp
@@ -141,6 +141,15 @@ void TableView::paint_event(PaintEvent& event)
painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right);
}
}
+
+ if (m_grid_style == GridStyle::Horizontal || m_grid_style == GridStyle::Both)
+ painter.draw_line(cell_rect_for_fill.bottom_left(), cell_rect_for_fill.bottom_right(), palette().ruler());
+ if (m_grid_style == GridStyle::Vertical || m_grid_style == GridStyle::Both)
+ painter.draw_line(cell_rect_for_fill.top_right(), cell_rect_for_fill.bottom_right(), palette().ruler());
+
+ if (m_cursor_style == CursorStyle::Item && cell_index == cursor_index())
+ painter.draw_rect(cell_rect_for_fill, palette().text_cursor());
+
x += column_width + horizontal_padding() * 2;
}
++painted_item_index;
@@ -211,4 +220,20 @@ void TableView::move_cursor(CursorMovement movement, SelectionUpdate selection_u
}
}
+void TableView::set_grid_style(GridStyle style)
+{
+ if (m_grid_style == style)
+ return;
+ m_grid_style = style;
+ update();
+}
+
+void TableView::set_cursor_style(CursorStyle style)
+{
+ if (m_cursor_style == style)
+ return;
+ m_cursor_style = style;
+ update();
+}
+
}
diff --git a/Libraries/LibGUI/TableView.h b/Libraries/LibGUI/TableView.h
index f67b89935d..b876c337fa 100644
--- a/Libraries/LibGUI/TableView.h
+++ b/Libraries/LibGUI/TableView.h
@@ -35,6 +35,24 @@ class TableView : public AbstractTableView {
public:
virtual ~TableView() override;
+ enum class GridStyle {
+ None,
+ Horizontal,
+ Vertical,
+ Both,
+ };
+
+ enum class CursorStyle {
+ None,
+ Item,
+ };
+
+ GridStyle grid_style() const { return m_grid_style; }
+ void set_grid_style(GridStyle);
+
+ CursorStyle cursor_style() const { return m_cursor_style; }
+ void set_cursor_style(CursorStyle);
+
protected:
TableView();
@@ -42,6 +60,10 @@ protected:
virtual void keydown_event(KeyEvent&) override;
virtual void paint_event(PaintEvent&) override;
+
+private:
+ GridStyle m_grid_style { GridStyle::None };
+ CursorStyle m_cursor_style { CursorStyle::None };
};
}