mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:27:42 +00:00
LibGUI: Let the table view tell HeaderView about the min. section size
Previously HeaderView would just assume that each column or row could have a minimum size of 2. This makes it so that AbstractTableView subclasses can provide a new minimum value for a specific column.
This commit is contained in:
parent
854e16797e
commit
ab2719fd53
3 changed files with 23 additions and 6 deletions
|
@ -179,6 +179,16 @@ void AbstractTableView::set_column_width(int column, int width)
|
||||||
column_header().set_section_size(column, width);
|
column_header().set_section_size(column, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AbstractTableView::minimum_column_width(int)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AbstractTableView::minimum_row_height(int)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
Gfx::TextAlignment AbstractTableView::column_header_alignment(int column_index) const
|
Gfx::TextAlignment AbstractTableView::column_header_alignment(int column_index) const
|
||||||
{
|
{
|
||||||
if (!model())
|
if (!model())
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
int column_width(int column) const;
|
int column_width(int column) const;
|
||||||
void set_column_width(int column, int width);
|
void set_column_width(int column, int width);
|
||||||
void set_default_column_width(int column, int width);
|
void set_default_column_width(int column, int width);
|
||||||
|
virtual int minimum_column_width(int column);
|
||||||
|
virtual int minimum_row_height(int row);
|
||||||
|
|
||||||
Gfx::TextAlignment column_header_alignment(int column) const;
|
Gfx::TextAlignment column_header_alignment(int column) const;
|
||||||
void set_column_header_alignment(int column, Gfx::TextAlignment);
|
void set_column_header_alignment(int column, Gfx::TextAlignment);
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
static constexpr int minimum_column_size = 2;
|
|
||||||
|
|
||||||
HeaderView::HeaderView(AbstractTableView& table_view, Gfx::Orientation orientation)
|
HeaderView::HeaderView(AbstractTableView& table_view, Gfx::Orientation orientation)
|
||||||
: m_table_view(table_view)
|
: m_table_view(table_view)
|
||||||
, m_orientation(orientation)
|
, m_orientation(orientation)
|
||||||
|
@ -179,8 +177,13 @@ void HeaderView::mousemove_event(MouseEvent& event)
|
||||||
if (m_in_section_resize) {
|
if (m_in_section_resize) {
|
||||||
auto delta = event.position() - m_section_resize_origin;
|
auto delta = event.position() - m_section_resize_origin;
|
||||||
int new_size = m_section_resize_original_width + delta.primary_offset_for_orientation(m_orientation);
|
int new_size = m_section_resize_original_width + delta.primary_offset_for_orientation(m_orientation);
|
||||||
if (new_size <= minimum_column_size)
|
|
||||||
new_size = minimum_column_size;
|
auto minimum_size = orientation() == Orientation::Horizontal
|
||||||
|
? m_table_view.minimum_column_width(m_resizing_section)
|
||||||
|
: m_table_view.minimum_row_height(m_resizing_section);
|
||||||
|
|
||||||
|
if (new_size <= minimum_size)
|
||||||
|
new_size = minimum_size;
|
||||||
VERIFY(m_resizing_section >= 0 && m_resizing_section < model()->column_count());
|
VERIFY(m_resizing_section >= 0 && m_resizing_section < model()->column_count());
|
||||||
set_section_size(m_resizing_section, new_size);
|
set_section_size(m_resizing_section, new_size);
|
||||||
return;
|
return;
|
||||||
|
@ -393,8 +396,10 @@ void HeaderView::set_section_alignment(int section, Gfx::TextAlignment alignment
|
||||||
|
|
||||||
void HeaderView::set_default_section_size(int section, int size)
|
void HeaderView::set_default_section_size(int section, int size)
|
||||||
{
|
{
|
||||||
if (orientation() == Gfx::Orientation::Horizontal && size < minimum_column_size)
|
auto minimum_column_width = m_table_view.minimum_column_width(section);
|
||||||
size = minimum_column_size;
|
|
||||||
|
if (orientation() == Gfx::Orientation::Horizontal && size < minimum_column_width)
|
||||||
|
size = minimum_column_width;
|
||||||
|
|
||||||
auto& data = section_data(section);
|
auto& data = section_data(section);
|
||||||
if (data.default_size == size)
|
if (data.default_size == size)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue