Regularize ellipsization of menu and status text.
Fixes https://gitlab.com/kicad/code/kicad/issues/12257
This commit is contained in:
parent
952669e747
commit
f42b66bc1c
|
@ -493,36 +493,6 @@ void EDA_TEXT::AddRenderCacheGlyph( const SHAPE_POLY_SET& aPoly )
|
|||
}
|
||||
|
||||
|
||||
wxString EDA_TEXT::ShortenedText() const
|
||||
{
|
||||
wxString tmp = GetText();
|
||||
|
||||
tmp.Replace( wxT( "\n" ), wxT( " " ) );
|
||||
tmp.Replace( wxT( "\r" ), wxT( " " ) );
|
||||
tmp.Replace( wxT( "\t" ), wxT( " " ) );
|
||||
|
||||
if( tmp.Length() > 54 )
|
||||
tmp = tmp.Left( 52 ) + wxT( "..." );
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
wxString EDA_TEXT::ShortenedShownText() const
|
||||
{
|
||||
wxString tmp = GetShownText();
|
||||
|
||||
tmp.Replace( wxT( "\n" ), wxT( " " ) );
|
||||
tmp.Replace( wxT( "\r" ), wxT( " " ) );
|
||||
tmp.Replace( wxT( "\t" ), wxT( " " ) );
|
||||
|
||||
if( tmp.Length() > 36 )
|
||||
tmp = tmp.Left( 34 ) + wxT( "..." );
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
int EDA_TEXT::GetInterline() const
|
||||
{
|
||||
return KiROUND( GetDrawFont()->GetInterline( GetTextHeight() ) );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2018-2022 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
|
||||
|
@ -28,7 +28,6 @@
|
|||
#include <wx/srchctrl.h>
|
||||
#include <wx/stc/stc.h>
|
||||
#include <wx/scrolbar.h>
|
||||
#include <wx/scrolwin.h>
|
||||
#include <wx/grid.h>
|
||||
#include <widgets/ui_common.h>
|
||||
|
||||
|
@ -37,6 +36,7 @@
|
|||
#include <pgm_base.h>
|
||||
#include <wx/settings.h>
|
||||
#include <bitmaps/bitmap_types.h>
|
||||
#include <string_utils.h>
|
||||
|
||||
int KIUI::GetStdMargin()
|
||||
{
|
||||
|
@ -182,6 +182,34 @@ bool KIUI::EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
|
|||
}
|
||||
|
||||
|
||||
wxString KIUI::EllipsizeStatusText( wxWindow* aWindow, const wxString& aString )
|
||||
{
|
||||
wxString msg = UnescapeString( aString );
|
||||
|
||||
msg.Replace( wxT( "\n" ), wxT( " " ) );
|
||||
msg.Replace( wxT( "\r" ), wxT( " " ) );
|
||||
msg.Replace( wxT( "\t" ), wxT( " " ) );
|
||||
|
||||
wxClientDC dc( aWindow );
|
||||
return wxControl::Ellipsize( msg, dc, wxELLIPSIZE_END, aWindow->GetSize().GetWidth() / 3 );
|
||||
}
|
||||
|
||||
|
||||
wxString KIUI::EllipsizeMenuText( const wxString& aString )
|
||||
{
|
||||
wxString msg = UnescapeString( aString );
|
||||
|
||||
msg.Replace( wxT( "\n" ), wxT( " " ) );
|
||||
msg.Replace( wxT( "\r" ), wxT( " " ) );
|
||||
msg.Replace( wxT( "\t" ), wxT( " " ) );
|
||||
|
||||
if( msg.Length() > 36 )
|
||||
msg = msg.Left( 34 ) + wxT( "..." );
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
void KIUI::SelectReferenceNumber( wxTextEntry* aTextEntry )
|
||||
{
|
||||
wxString ref = aTextEntry->GetValue();
|
||||
|
|
|
@ -455,7 +455,7 @@ void LIB_FIELD::SetName( const wxString& aName )
|
|||
|
||||
wxString LIB_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() );
|
||||
return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -422,7 +422,7 @@ const EDA_RECT LIB_TEXT::GetBoundingBox() const
|
|||
|
||||
wxString LIB_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() );
|
||||
return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -392,7 +392,7 @@ void LIB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL
|
|||
EDA_UNITS units = aFrame->GetUserUnits();
|
||||
|
||||
// Don't use GetShownText() here; we want to show the user the variable references
|
||||
aList.emplace_back( _( "Text Box" ), UnescapeString( ShortenedText() ) );
|
||||
aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
||||
|
||||
aList.emplace_back( _( "Font" ), GetDrawFont()->GetName() );
|
||||
|
||||
|
|
|
@ -671,7 +671,7 @@ void SCH_FIELD::Rotate( const VECTOR2I& aCenter )
|
|||
|
||||
wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() );
|
||||
return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -957,7 +957,7 @@ const EDA_RECT SCH_LABEL::GetBodyBoundingBox() const
|
|||
|
||||
wxString SCH_LABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Label '%s'" ), ShortenedShownText() );
|
||||
return wxString::Format( _( "Label '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1411,7 +1411,7 @@ void SCH_GLOBALLABEL::CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings
|
|||
|
||||
wxString SCH_GLOBALLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Global Label '%s'" ), ShortenedShownText() );
|
||||
return wxString::Format( _( "Global Label '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1544,7 +1544,8 @@ VECTOR2I SCH_HIERLABEL::GetSchematicTextOffset( const RENDER_SETTINGS* aSettings
|
|||
|
||||
wxString SCH_HIERLABEL::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Hierarchical Label '%s'" ), ShortenedShownText() );
|
||||
return wxString::Format( _( "Hierarchical Label '%s'" ),
|
||||
KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -327,7 +327,8 @@ void SCH_SHEET_PIN::GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList )
|
|||
|
||||
wxString SCH_SHEET_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Hierarchical Sheet Pin %s" ), ShortenedShownText() );
|
||||
return wxString::Format( _( "Hierarchical Sheet Pin %s" ),
|
||||
KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -383,7 +383,7 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
|
|||
|
||||
wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() );
|
||||
return wxString::Format( _( "Graphic Text '%s'" ), KIUI::EllipsizeMenuText( GetShownText() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -475,7 +475,7 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
|
|||
wxString msg;
|
||||
|
||||
// Don't use GetShownText() here; we want to show the user the variable references
|
||||
aList.emplace_back( _( "Graphic Text" ), UnescapeString( ShortenedText() ) );
|
||||
aList.emplace_back( _( "Graphic Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
||||
|
||||
aList.emplace_back( _( "Font" ), GetDrawFont()->GetName() );
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ void SCH_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL
|
|||
EDA_UNITS units = aFrame->GetUserUnits();
|
||||
|
||||
// Don't use GetShownText() here; we want to show the user the variable references
|
||||
aList.emplace_back( _( "Text Box" ), UnescapeString( ShortenedText() ) );
|
||||
aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
||||
|
||||
aList.emplace_back( _( "Font" ), GetDrawFont()->GetName() );
|
||||
|
||||
|
|
|
@ -87,11 +87,6 @@ public:
|
|||
*/
|
||||
virtual const wxString& GetText() const { return m_text; }
|
||||
|
||||
/**
|
||||
* Returns a shortened version (max 54 characters) of the shown text
|
||||
*/
|
||||
wxString ShortenedText() const;
|
||||
|
||||
/**
|
||||
* Return the string actually shown after processing of the base text.
|
||||
*
|
||||
|
@ -100,11 +95,6 @@ public:
|
|||
*/
|
||||
virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; }
|
||||
|
||||
/**
|
||||
* Returns a shortened version (max 36 characters) of the shown text
|
||||
*/
|
||||
wxString ShortenedShownText() const;
|
||||
|
||||
/**
|
||||
* Indicates the ShownText has text var references which need to be processed.
|
||||
*/
|
||||
|
|
|
@ -77,6 +77,20 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = nullptr )
|
|||
*/
|
||||
void SelectReferenceNumber( wxTextEntry* aTextEntry );
|
||||
|
||||
/**
|
||||
* Ellipsize text (at the end) to be no more than 1/3 of the window width.
|
||||
*
|
||||
* @return shortened text ending with an ellipsis.
|
||||
*/
|
||||
wxString EllipsizeStatusText( wxWindow* aWindow, const wxString& aString );
|
||||
|
||||
/**
|
||||
* Ellipsize text (at the end) to be no more than 36 characters.
|
||||
*
|
||||
* @return shortened text ending with an ellipsis.
|
||||
*/
|
||||
wxString EllipsizeMenuText( const wxString& aString );
|
||||
|
||||
/**
|
||||
* Check if a input control has focus.
|
||||
*
|
||||
|
|
|
@ -316,7 +316,7 @@ wxString FP_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
|||
|
||||
default:
|
||||
return wxString::Format( _( "Footprint Text '%s' of %s" ),
|
||||
ShortenedShownText(),
|
||||
KIUI::EllipsizeMenuText( GetShownText() ),
|
||||
static_cast<FOOTPRINT*>( GetParent() )->GetReference() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ void PCB_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
|
|||
EDA_UNITS units = aFrame->GetUserUnits();
|
||||
|
||||
// Don't use GetShownText() here; we want to show the user the variable references
|
||||
aList.emplace_back( _( "PCB Text" ), UnescapeString( GetText() ) );
|
||||
aList.emplace_back( _( "PCB Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
||||
|
||||
if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
|
||||
aList.emplace_back( _( "Status" ), _( "Locked" ) );
|
||||
|
@ -233,7 +233,9 @@ void PCB_TEXT::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
|||
|
||||
wxString PCB_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
||||
{
|
||||
return wxString::Format( _( "PCB Text '%s' on %s"), ShortenedShownText(), GetLayerName() );
|
||||
return wxString::Format( _( "PCB Text '%s' on %s"),
|
||||
KIUI::EllipsizeMenuText( GetShownText() ),
|
||||
GetLayerName() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ void PCB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL
|
|||
EDA_UNITS units = aFrame->GetUserUnits();
|
||||
|
||||
// Don't use GetShownText() here; we want to show the user the variable references
|
||||
aList.emplace_back( _( "Text Box" ), UnescapeString( GetText() ) );
|
||||
aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
|
||||
|
||||
if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
|
||||
aList.emplace_back( _( "Status" ), _( "Locked" ) );
|
||||
|
|
Loading…
Reference in New Issue