Better column width handling for sim params grid.

This commit is contained in:
Jeff Young 2022-12-08 14:40:01 +00:00
parent 6535f407a6
commit 107025322c
5 changed files with 79 additions and 23 deletions

View File

@ -56,6 +56,7 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
m_wasCodePreviewUpdated( true ),
m_firstCategory( nullptr ),
m_prevParamGridSelection( nullptr ),
m_lastParamGridWidth( 0 ),
m_inKillFocus( false )
{
m_modelNameCombobox->SetValidator( m_modelNameValidator );
@ -83,33 +84,22 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
| wxPG_VFB_BEEP
| wxPG_VFB_MARK_CELL );
m_paramGrid->SetColumnProportion( PARAM_COLUMN::DESCRIPTION, 50 );
m_paramGrid->SetColumnProportion( PARAM_COLUMN::VALUE, 18 );
m_paramGrid->SetColumnProportion( PARAM_COLUMN::UNIT, 10 );
m_paramGrid->SetColumnProportion( PARAM_COLUMN::DEFAULT, 12 );
m_paramGrid->SetColumnProportion( PARAM_COLUMN::TYPE, 10 );
wxPropertyGrid* grid = m_paramGrid->GetGrid();
if( wxPropertyGrid* grid = m_paramGrid->GetGrid() )
{
//grid->SetCellBackgroundColour( grid->GetPropertyDefaultCell().GetBgCol() );
//grid->SetCellTextColour( grid->GetPropertyDefaultCell().GetFgCol();
//grid->SetCellBackgroundColour( grid->GetPropertyDefaultCell().GetBgCol() );
//grid->SetCellTextColour( grid->GetPropertyDefaultCell().GetFgCol();
// In wx 3.0 the color will be wrong sometimes.
grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
// In wx 3.0 the color will be wrong sometimes.
grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this );
grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this );
grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
grid->DedicateKey( WXK_RETURN );
grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
grid->DedicateKey( WXK_RETURN );
grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
grid->DedicateKey( WXK_UP );
grid->DedicateKey( WXK_DOWN );
}
else
{
wxFAIL;
}
grid->DedicateKey( WXK_UP );
grid->DedicateKey( WXK_DOWN );
m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) );
@ -469,6 +459,8 @@ void DIALOG_SIM_MODEL<T>::updateModelParamsTab()
m_paramGrid->Expand( "Waveform" );
}
adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(), true );
// Set all properties to default colors.
// Update properties in models that have autofill.
for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
@ -1344,5 +1336,59 @@ void DIALOG_SIM_MODEL<T>::onParamGridSelectionChange( wxPropertyGridEvent& aEven
m_prevParamGridSelection = grid->GetSelection();
}
template <typename T>
void DIALOG_SIM_MODEL<T>::adjustParamGridColumns( int aWidth, bool aForce )
{
wxPropertyGrid* grid = m_paramGridMgr->GetGrid();
int margin = 15;
int indent = 20;
if( aWidth != m_lastParamGridWidth || aForce )
{
m_lastParamGridWidth = aWidth;
grid->FitColumns();
std::vector<int> colWidths;
for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
{
if( ii == 0 )
colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin + indent );
else if( ii == 1 )
colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin );
else
colWidths.push_back( 50 );
aWidth -= colWidths[ ii ];
}
// Account for scroll bars
aWidth -= ( grid->GetSize().x - grid->GetClientSize().x );
if( aWidth > 0 )
colWidths[ PARAM_COLUMN::VALUE ] += aWidth;
for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
grid->SetColumnProportion( ii, colWidths[ ii ] );
grid->ResetColumnSizes();
grid->RefreshEditor();
}
}
template <typename T>
void DIALOG_SIM_MODEL<T>::onSizeParamGrid( wxSizeEvent& event )
{
adjustParamGridColumns( event.GetSize().GetX(), false );
event.Skip();
}
template class DIALOG_SIM_MODEL<SCH_FIELD>;
template class DIALOG_SIM_MODEL<LIB_FIELD>;

View File

@ -135,10 +135,13 @@ private:
void onSaveInValueCheckbox( wxCommandEvent& aEvent ) override;
void onExcludeCheckbox( wxCommandEvent& aEvent ) override;
void onDifferentialCheckbox( wxCommandEvent& event ) override;
void onSizeParamGrid( wxSizeEvent& event ) override;
void onParamGridSetFocus( wxFocusEvent& aEvent );
void onParamGridSelectionChange( wxPropertyGridEvent& aEvent );
void adjustParamGridColumns( int aWidth, bool aForce );
bool isIbisLoaded() { return dynamic_cast<const SIM_LIBRARY_KIBIS*>( library() ); }
private:
@ -160,6 +163,7 @@ private:
wxPGProperty* m_firstCategory; // Used to add principal parameters to root.
wxPGProperty* m_prevParamGridSelection;
int m_lastParamGridWidth;
bool m_inKillFocus;
};

View File

@ -134,6 +134,8 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
m_paramGridMgr = new wxPropertyGridManager(m_parametersPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPGMAN_DEFAULT_STYLE|wxPG_SPLITTER_AUTO_CENTER);
m_paramGridMgr->SetExtraStyle( wxPG_EX_MODE_BUTTONS|wxPG_EX_NATIVE_DOUBLE_BUFFERING );
m_paramGridMgr->SetMinSize( wxSize( 440,-1 ) );
m_paramGrid = m_paramGridMgr->AddPage( _("Page"), wxNullBitmap );
bSizer12->Add( m_paramGridMgr, 1, wxALL|wxEXPAND, 5 );
@ -310,6 +312,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
m_staticTextSpiceType->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onTypeLabelUpdate ), NULL, this );
m_typeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onTypeChoice ), NULL, this );
m_paramGridMgr->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( DIALOG_SIM_MODEL_BASE::onParamGridChanged ), NULL, this );
m_paramGridMgr->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SIM_MODEL_BASE::onSizeParamGrid ), NULL, this );
m_codePreview->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onCodePreviewSetFocus ), NULL, this );
m_saveInValueCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this );
m_pinAssignmentsGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridCellChange ), NULL, this );
@ -352,6 +355,7 @@ DIALOG_SIM_MODEL_BASE::~DIALOG_SIM_MODEL_BASE()
m_staticTextSpiceType->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onTypeLabelUpdate ), NULL, this );
m_typeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onTypeChoice ), NULL, this );
m_paramGridMgr->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( DIALOG_SIM_MODEL_BASE::onParamGridChanged ), NULL, this );
m_paramGridMgr->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SIM_MODEL_BASE::onSizeParamGrid ), NULL, this );
m_codePreview->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onCodePreviewSetFocus ), NULL, this );
m_saveInValueCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this );
m_pinAssignmentsGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridCellChange ), NULL, this );

View File

@ -1488,7 +1488,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="minimum_size">440,-1</property>
<property name="moveable">1</property>
<property name="name">m_paramGridMgr</property>
<property name="pane_border">1</property>
@ -1508,6 +1508,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnPropertyGridChanged">onParamGridChanged</event>
<event name="OnSize">onSizeParamGrid</event>
<object class="propGridPage" expanded="0">
<property name="bitmap"></property>
<property name="label">Page</property>

View File

@ -111,6 +111,7 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM
virtual void onTypeLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onTypeChoice( wxCommandEvent& event ) { event.Skip(); }
virtual void onParamGridChanged( wxPropertyGridEvent& event ) { event.Skip(); }
virtual void onSizeParamGrid( wxSizeEvent& event ) { event.Skip(); }
virtual void onCodePreviewSetFocus( wxFocusEvent& event ) { event.Skip(); }
virtual void onSaveInValueCheckbox( wxCommandEvent& event ) { event.Skip(); }
virtual void onPinAssignmentsGridCellChange( wxGridEvent& event ) { event.Skip(); }