Browse Source
Move WX_GRID_AUTOSIZER into WX_GRID and use in more places.
Move WX_GRID_AUTOSIZER into WX_GRID and use in more places.
Also fixes some bugs around skipping of events. Also fixes some bugs around hidden columns.master
70 changed files with 368 additions and 944 deletions
-
1common/CMakeLists.txt
-
8common/dialogs/dialog_configure_paths.cpp
-
6common/dialogs/dialog_configure_paths_base.cpp
-
58common/dialogs/dialog_configure_paths_base.fbp
-
3common/dialogs/dialog_configure_paths_base.h
-
19common/dialogs/dialog_design_block_properties.cpp
-
4common/dialogs/dialog_design_block_properties.h
-
6common/dialogs/dialog_design_block_properties_base.cpp
-
3common/dialogs/dialog_design_block_properties_base.fbp
-
1common/dialogs/dialog_design_block_properties_base.h
-
7common/dialogs/panel_embedded_files.cpp
-
4common/dialogs/panel_embedded_files.h
-
4common/dialogs/panel_embedded_files_base.cpp
-
6common/dialogs/panel_embedded_files_base.fbp
-
10common/dialogs/panel_text_variables.cpp
-
4common/dialogs/panel_text_variables_base.cpp
-
2common/dialogs/panel_text_variables_base.fbp
-
2common/grid_tricks.cpp
-
86common/widgets/wx_grid.cpp
-
120common/widgets/wx_grid_autosizer.cpp
-
34eeschema/dialogs/dialog_label_properties.cpp
-
10eeschema/dialogs/dialog_label_properties.h
-
2eeschema/dialogs/dialog_label_properties_base.cpp
-
1eeschema/dialogs/dialog_label_properties_base.fbp
-
1eeschema/dialogs/dialog_label_properties_base.h
-
36eeschema/dialogs/dialog_lib_symbol_properties.cpp
-
3eeschema/dialogs/dialog_lib_symbol_properties.h
-
2eeschema/dialogs/dialog_lib_symbol_properties_base.cpp
-
1eeschema/dialogs/dialog_lib_symbol_properties_base.fbp
-
1eeschema/dialogs/dialog_lib_symbol_properties_base.h
-
36eeschema/dialogs/dialog_sheet_properties.cpp
-
4eeschema/dialogs/dialog_sheet_properties.h
-
8eeschema/dialogs/dialog_sheet_properties_base.cpp
-
183eeschema/dialogs/dialog_sheet_properties_base.fbp
-
4eeschema/dialogs/dialog_sheet_properties_base.h
-
44eeschema/dialogs/dialog_symbol_properties.cpp
-
4eeschema/dialogs/dialog_symbol_properties.h
-
2eeschema/dialogs/dialog_symbol_properties_base.cpp
-
1eeschema/dialogs/dialog_symbol_properties_base.fbp
-
1eeschema/dialogs/dialog_symbol_properties_base.h
-
25eeschema/dialogs/panel_template_fieldnames.cpp
-
4eeschema/dialogs/panel_template_fieldnames.h
-
8eeschema/dialogs/panel_template_fieldnames_base.cpp
-
3eeschema/dialogs/panel_template_fieldnames_base.fbp
-
1eeschema/dialogs/panel_template_fieldnames_base.h
-
2eeschema/fields_grid_table.cpp
-
3include/dialogs/dialog_configure_paths.h
-
3include/panel_text_variables.h
-
28include/widgets/wx_grid.h
-
70include/widgets/wx_grid_autosizer.h
-
88kicad/dialogs/dialog_edit_cfg.cpp
-
7kicad/dialogs/dialog_edit_cfg.h
-
62pcbnew/dialogs/dialog_footprint_properties.cpp
-
5pcbnew/dialogs/dialog_footprint_properties.h
-
24pcbnew/dialogs/dialog_footprint_properties_base.cpp
-
3pcbnew/dialogs/dialog_footprint_properties_base.fbp
-
1pcbnew/dialogs/dialog_footprint_properties_base.h
-
77pcbnew/dialogs/dialog_footprint_properties_fp_editor.cpp
-
5pcbnew/dialogs/dialog_footprint_properties_fp_editor.h
-
30pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.cpp
-
19pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.fbp
-
1pcbnew/dialogs/dialog_footprint_properties_fp_editor_base.h
-
29pcbnew/dialogs/dialog_layer_selection_base.cpp
-
2pcbnew/dialogs/dialog_layer_selection_base.fbp
-
31pcbnew/dialogs/panel_fp_properties_3d_model.cpp
-
22pcbnew/dialogs/panel_fp_properties_3d_model.h
-
6pcbnew/dialogs/panel_fp_properties_3d_model_base.cpp
-
3pcbnew/dialogs/panel_fp_properties_3d_model_base.fbp
-
1pcbnew/dialogs/panel_fp_properties_3d_model_base.h
-
17pcbnew/sel_layer.cpp
@ -1,120 +0,0 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright The KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include "widgets/wx_grid_autosizer.h"
|
|||
|
|||
#include <optional>
|
|||
|
|||
#include <wx/settings.h>
|
|||
|
|||
|
|||
WX_GRID_AUTOSIZER::WX_GRID_AUTOSIZER( wxGrid& aGrid, COL_MIN_WIDTHS aAutosizedCols, |
|||
unsigned aFlexibleCol ) : |
|||
m_grid( aGrid ), |
|||
m_autosizedCols( std::move( aAutosizedCols ) ), |
|||
m_flexibleCol( aFlexibleCol ) |
|||
{ |
|||
const int colCount = m_grid.GetNumberCols(); |
|||
|
|||
for( const auto& [colIndex, width] : m_autosizedCols ) |
|||
{ |
|||
wxASSERT_MSG( colIndex < colCount, "Autosized column does not exist in grid" ); |
|||
} |
|||
|
|||
wxASSERT_MSG( m_flexibleCol < colCount, "Flexible column index does not exist in grid" ); |
|||
|
|||
m_grid.Bind( wxEVT_UPDATE_UI, |
|||
[this]( wxUpdateUIEvent& aEvent ) |
|||
{ |
|||
recomputeGridWidths(); |
|||
aEvent.Skip(); |
|||
} ); |
|||
|
|||
m_grid.Bind( wxEVT_SIZE, |
|||
[this]( wxSizeEvent& aEvent ) |
|||
{ |
|||
onSizeEvent( aEvent ); |
|||
aEvent.Skip(); |
|||
} ); |
|||
|
|||
// Handles the case when the user changes the cell content to be longer than the
|
|||
// current column size
|
|||
m_grid.Bind( wxEVT_GRID_CELL_CHANGED, |
|||
[this]( wxGridEvent& aEvent ) |
|||
{ |
|||
m_gridWidthsDirty = true; |
|||
aEvent.Skip(); |
|||
} ); |
|||
} |
|||
|
|||
|
|||
void WX_GRID_AUTOSIZER::recomputeGridWidths() |
|||
{ |
|||
if( m_gridWidthsDirty ) |
|||
{ |
|||
const int width = m_grid.GetClientRect().GetWidth() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ); |
|||
|
|||
std::optional<int> flexibleMinWidth; |
|||
|
|||
for( const auto& [colIndex, minWidth] : m_autosizedCols ) |
|||
{ |
|||
m_grid.AutoSizeColumn( colIndex ); |
|||
const int colSize = m_grid.GetColSize( colIndex ); |
|||
|
|||
int minWidthScaled = m_grid.FromDIP( minWidth ); |
|||
m_grid.SetColSize( colIndex, std::max( minWidthScaled, colSize ) ); |
|||
|
|||
if( colIndex == m_flexibleCol ) |
|||
{ |
|||
flexibleMinWidth = minWidthScaled; |
|||
} |
|||
} |
|||
|
|||
// Gather all the widths except the flexi one
|
|||
int nonFlexibleWidth = 0; |
|||
|
|||
for( int i = 0; i < m_grid.GetNumberCols(); ++i ) |
|||
{ |
|||
if( i != m_flexibleCol ) |
|||
{ |
|||
nonFlexibleWidth += m_grid.GetColSize( i ); |
|||
} |
|||
} |
|||
|
|||
m_grid.SetColSize( m_flexibleCol, |
|||
std::max( flexibleMinWidth.value_or( 0 ), width - nonFlexibleWidth ) ); |
|||
|
|||
// Store the state for next time
|
|||
m_gridWidth = m_grid.GetSize().GetX(); |
|||
m_gridWidthsDirty = false; |
|||
} |
|||
} |
|||
|
|||
|
|||
void WX_GRID_AUTOSIZER::onSizeEvent( wxSizeEvent& aEvent ) |
|||
{ |
|||
const int width = aEvent.GetSize().GetX(); |
|||
|
|||
if( width != m_gridWidth ) |
|||
m_gridWidthsDirty = true; |
|||
} |
@ -1,70 +0,0 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright The KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef WX_GRID_AUTOSIZER_H |
|||
#define WX_GRID_AUTOSIZER_H |
|||
|
|||
#include <map> |
|||
|
|||
#include <wx/grid.h> |
|||
|
|||
/** |
|||
* Class that manages autosizing of columns in a wxGrid. |
|||
* |
|||
* The class will automatically resize the columns in the grid to fit the content, |
|||
* with one column being flexible and taking up the remaining space. |
|||
*/ |
|||
class WX_GRID_AUTOSIZER |
|||
{ |
|||
public: |
|||
/** |
|||
* Map of column indices to minimum widths. |
|||
* |
|||
* Use 0 to indicate that a column should be autosized to fit content, |
|||
* but without a minimum width. |
|||
*/ |
|||
using COL_MIN_WIDTHS = std::map<int, int>; |
|||
|
|||
/** |
|||
* @param aGrid The grid to manage. |
|||
* @param aAutosizedCols A map of columns to autosize: these will sized to fit, |
|||
* but not smaller than the width specified. |
|||
* @param aFlexibleCol The column that will take up the remaining space, |
|||
* with a minimum width if given in the aAutosizedCols map. |
|||
*/ |
|||
WX_GRID_AUTOSIZER( wxGrid& aGrid, COL_MIN_WIDTHS aAutosizedCols, unsigned aFlexibleCol ); |
|||
|
|||
private: |
|||
void recomputeGridWidths(); |
|||
|
|||
void onSizeEvent( wxSizeEvent& aEvent ); |
|||
|
|||
wxGrid& m_grid; |
|||
COL_MIN_WIDTHS m_autosizedCols; |
|||
int m_flexibleCol; |
|||
|
|||
bool m_gridWidthsDirty = true; |
|||
int m_gridWidth = 0; |
|||
}; |
|||
|
|||
#endif // WX_GRID_AUTOSIZER_H |
Write
Preview
Loading…
Cancel
Save
Reference in new issue