LibGUI: Make table view row height+padding font-size-relative

This makes tables look a lot nicer with different-sized fonts. :^)
This commit is contained in:
Andreas Kling 2020-10-24 16:17:26 +02:00
parent 8961148cdf
commit 688675e89b
Notes: sideshowbarker 2024-07-19 01:45:57 +09:00
5 changed files with 18 additions and 24 deletions

View File

@ -66,8 +66,6 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
m_table_view->row_header().set_visible(true);
m_table_view->set_model(SheetModel::create(*m_sheet));
m_table_view->set_row_height(18);
set_focus_proxy(m_table_view);
// FIXME: This is dumb.

View File

@ -374,15 +374,6 @@ void AbstractTableView::layout_headers()
}
}
void AbstractTableView::set_row_height(int height)
{
if (m_row_height == height)
return;
m_row_height = height;
update_row_sizes();
}
void AbstractTableView::keydown_event(KeyEvent& event)
{
if (is_tab_key_navigation_enabled()) {
@ -401,4 +392,14 @@ void AbstractTableView::keydown_event(KeyEvent& event)
AbstractView::keydown_event(event);
}
int AbstractTableView::horizontal_padding() const
{
return font().glyph_height() / 2;
}
int AbstractTableView::row_height() const
{
return font().glyph_height() + 6;
}
}

View File

@ -39,8 +39,7 @@ public:
class AbstractTableView : public AbstractView {
public:
int row_height() const { return m_row_height; }
void set_row_height(int);
int row_height() const;
bool alternating_row_colors() const { return m_alternating_row_colors; }
void set_alternating_row_colors(bool b) { m_alternating_row_colors = b; }
@ -60,7 +59,7 @@ public:
void set_column_painting_delegate(int column, OwnPtr<TableCellPaintingDelegate>);
int horizontal_padding() const { return m_horizontal_padding; }
int horizontal_padding() const;
Gfx::IntPoint adjusted_position(const Gfx::IntPoint&) const;
@ -123,8 +122,6 @@ private:
bool m_alternating_row_colors { true };
bool m_highlight_selected_rows { true };
int m_horizontal_padding { 5 };
int m_row_height { 16 };
};
}

View File

@ -93,10 +93,10 @@ Gfx::IntRect HeaderView::section_rect(int section) const
continue;
offset += section_data(i).size;
if (orientation() == Gfx::Orientation::Horizontal)
offset += horizontal_padding() * 2;
offset += m_table_view.horizontal_padding() * 2;
}
if (orientation() == Gfx::Orientation::Horizontal)
return { offset, 0, section_size(section) + horizontal_padding() * 2, height() };
return { offset, 0, section_size(section) + m_table_view.horizontal_padding() * 2, height() };
return { 0, offset, width(), section_size(section) };
}
@ -232,7 +232,7 @@ void HeaderView::paint_horizontal(Painter& painter)
continue;
int section_width = section_size(section);
bool is_key_column = m_table_view.key_column() == section;
Gfx::IntRect cell_rect(x_offset, 0, section_width + horizontal_padding() * 2, height());
Gfx::IntRect cell_rect(x_offset, 0, section_width + m_table_view.horizontal_padding() * 2, height());
bool pressed = section == m_pressed_section && m_pressed_section_is_pressed;
bool hovered = section == m_hovered_section && model()->is_column_sortable(section);
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
@ -248,11 +248,11 @@ void HeaderView::paint_horizontal(Painter& painter)
} else {
text = model()->column_name(section);
}
auto text_rect = cell_rect.shrunken(horizontal_padding() * 2, 0);
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
if (pressed)
text_rect.move_by(1, 1);
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
x_offset += section_width + horizontal_padding() * 2;
x_offset += section_width + m_table_view.horizontal_padding() * 2;
}
if (x_offset < rect().right()) {
@ -276,7 +276,7 @@ void HeaderView::paint_vertical(Painter& painter)
bool hovered = false;
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
String text = String::format("%d", section);
auto text_rect = cell_rect.shrunken(horizontal_padding() * 2, 0);
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
if (pressed)
text_rect.move_by(1, 1);
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());

View File

@ -64,8 +64,6 @@ private:
virtual void context_menu_event(ContextMenuEvent&) override;
virtual void leave_event(Core::Event&) override;
int horizontal_padding() const { return 5; }
Gfx::IntRect section_resize_grabbable_rect(int) const;
void paint_horizontal(Painter&);