1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

LibGUI: Add optional grid and cursor styles to TableView

This commit is contained in:
Andreas Kling 2020-08-28 16:52:06 +02:00
parent 6614ee703b
commit 2222fc5e08
2 changed files with 47 additions and 0 deletions

View file

@ -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();
}
}

View file

@ -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 };
};
}