mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
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:
parent
8961148cdf
commit
688675e89b
5 changed files with 18 additions and 24 deletions
|
@ -66,8 +66,6 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||||
m_table_view->row_header().set_visible(true);
|
m_table_view->row_header().set_visible(true);
|
||||||
m_table_view->set_model(SheetModel::create(*m_sheet));
|
m_table_view->set_model(SheetModel::create(*m_sheet));
|
||||||
|
|
||||||
m_table_view->set_row_height(18);
|
|
||||||
|
|
||||||
set_focus_proxy(m_table_view);
|
set_focus_proxy(m_table_view);
|
||||||
|
|
||||||
// FIXME: This is dumb.
|
// FIXME: This is dumb.
|
||||||
|
|
|
@ -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)
|
void AbstractTableView::keydown_event(KeyEvent& event)
|
||||||
{
|
{
|
||||||
if (is_tab_key_navigation_enabled()) {
|
if (is_tab_key_navigation_enabled()) {
|
||||||
|
@ -401,4 +392,14 @@ void AbstractTableView::keydown_event(KeyEvent& event)
|
||||||
AbstractView::keydown_event(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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,7 @@ public:
|
||||||
|
|
||||||
class AbstractTableView : public AbstractView {
|
class AbstractTableView : public AbstractView {
|
||||||
public:
|
public:
|
||||||
int row_height() const { return m_row_height; }
|
int row_height() const;
|
||||||
void set_row_height(int);
|
|
||||||
|
|
||||||
bool alternating_row_colors() const { return m_alternating_row_colors; }
|
bool alternating_row_colors() const { return m_alternating_row_colors; }
|
||||||
void set_alternating_row_colors(bool b) { m_alternating_row_colors = b; }
|
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>);
|
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;
|
Gfx::IntPoint adjusted_position(const Gfx::IntPoint&) const;
|
||||||
|
|
||||||
|
@ -123,8 +122,6 @@ private:
|
||||||
|
|
||||||
bool m_alternating_row_colors { true };
|
bool m_alternating_row_colors { true };
|
||||||
bool m_highlight_selected_rows { true };
|
bool m_highlight_selected_rows { true };
|
||||||
int m_horizontal_padding { 5 };
|
|
||||||
int m_row_height { 16 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,10 +93,10 @@ Gfx::IntRect HeaderView::section_rect(int section) const
|
||||||
continue;
|
continue;
|
||||||
offset += section_data(i).size;
|
offset += section_data(i).size;
|
||||||
if (orientation() == Gfx::Orientation::Horizontal)
|
if (orientation() == Gfx::Orientation::Horizontal)
|
||||||
offset += horizontal_padding() * 2;
|
offset += m_table_view.horizontal_padding() * 2;
|
||||||
}
|
}
|
||||||
if (orientation() == Gfx::Orientation::Horizontal)
|
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) };
|
return { 0, offset, width(), section_size(section) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ void HeaderView::paint_horizontal(Painter& painter)
|
||||||
continue;
|
continue;
|
||||||
int section_width = section_size(section);
|
int section_width = section_size(section);
|
||||||
bool is_key_column = m_table_view.key_column() == 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 pressed = section == m_pressed_section && m_pressed_section_is_pressed;
|
||||||
bool hovered = section == m_hovered_section && model()->is_column_sortable(section);
|
bool hovered = section == m_hovered_section && model()->is_column_sortable(section);
|
||||||
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
|
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
|
||||||
|
@ -248,11 +248,11 @@ void HeaderView::paint_horizontal(Painter& painter)
|
||||||
} else {
|
} else {
|
||||||
text = model()->column_name(section);
|
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)
|
if (pressed)
|
||||||
text_rect.move_by(1, 1);
|
text_rect.move_by(1, 1);
|
||||||
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
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()) {
|
if (x_offset < rect().right()) {
|
||||||
|
@ -276,7 +276,7 @@ void HeaderView::paint_vertical(Painter& painter)
|
||||||
bool hovered = false;
|
bool hovered = false;
|
||||||
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
|
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
|
||||||
String text = String::format("%d", section);
|
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)
|
if (pressed)
|
||||||
text_rect.move_by(1, 1);
|
text_rect.move_by(1, 1);
|
||||||
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
||||||
|
|
|
@ -64,8 +64,6 @@ private:
|
||||||
virtual void context_menu_event(ContextMenuEvent&) override;
|
virtual void context_menu_event(ContextMenuEvent&) override;
|
||||||
virtual void leave_event(Core::Event&) override;
|
virtual void leave_event(Core::Event&) override;
|
||||||
|
|
||||||
int horizontal_padding() const { return 5; }
|
|
||||||
|
|
||||||
Gfx::IntRect section_resize_grabbable_rect(int) const;
|
Gfx::IntRect section_resize_grabbable_rect(int) const;
|
||||||
|
|
||||||
void paint_horizontal(Painter&);
|
void paint_horizontal(Painter&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue