eeschema: neatly wrap placeholder text in symbol chooser

This commit is contained in:
Chris Pavlina 2018-01-03 18:51:27 -07:00
parent 04beb20e3e
commit 6cee19d37d
3 changed files with 91 additions and 20 deletions

View File

@ -1,3 +1,24 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2018 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 3 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, see <http://www.gnu.org/licenses/>.
*/
/********************************/ /********************************/
/* Low level graphics routines */ /* Low level graphics routines */
/********************************/ /********************************/
@ -13,6 +34,7 @@
#include <bezier_curves.h> #include <bezier_curves.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
#include <wx/graphics.h> #include <wx/graphics.h>
#include <wx/tokenzr.h>
#if defined(__WXMAC__) && defined(USE_WX_GRAPHICS_CONTEXT) #if defined(__WXMAC__) && defined(USE_WX_GRAPHICS_CONTEXT)
#include <wx/dcgraph.h> #include <wx/dcgraph.h>
#endif #endif
@ -1275,3 +1297,52 @@ void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y,
x, y - anchor_size, x, y - anchor_size,
x, y + anchor_size, 0, aColor ); x, y + anchor_size, 0, aColor );
} }
void GRDrawWrappedText( wxDC& aDC, wxString const& aText )
{
wxStringTokenizer tokenizer( aText, " " );
wxSize const dc_size = aDC.GetSize();
wxSize const margin = aDC.GetTextExtent( " " );
std::vector<wxString> lines;
wxString line_accumulator;
int total_height = 0;
while( tokenizer.HasMoreTokens() )
{
wxString word = tokenizer.GetNextToken();
wxSize linesize = aDC.GetTextExtent( line_accumulator + " " + word );
if( linesize.x >= dc_size.x - margin.x && !line_accumulator.IsEmpty() )
{
lines.push_back( line_accumulator );
line_accumulator = word;
}
else
{
line_accumulator += " ";
line_accumulator += word;
}
}
if( !line_accumulator.IsEmpty() )
{
lines.push_back( line_accumulator );
}
for( auto const& line: lines )
{
wxSize linesize = aDC.GetTextExtent( line );
total_height += linesize.y;
}
int top = ( dc_size.y - total_height ) / 2;
int pos = top;
for( auto const& line: lines )
{
wxSize linesize = aDC.GetTextExtent( line );
aDC.DrawText( line, ( dc_size.x - linesize.x ) / 2, pos );
pos += linesize.y;
}
}

View File

@ -464,11 +464,8 @@ void DIALOG_CHOOSE_COMPONENT::RenderPreview( LIB_PART* aComponent, int aUnit )
if( !aComponent ) // display a tooltip if( !aComponent ) // display a tooltip
{ {
wxString tooltip = _( "Double click here to select a symbol\nfrom the library browser" ); wxString tooltip = _( "Double-click here to select a symbol from the library browser" );
wxSize tsize = dc.GetTextExtent( tooltip.BeforeLast( '\n' ) ); GRDrawWrappedText( dc, tooltip );
dc.DrawText( tooltip.BeforeLast( '\n' ), ( dc_size.x - tsize.x )/2, ( dc_size.y - tsize.y )/2 );
tsize = dc.GetTextExtent( tooltip.AfterLast( '\n' ) );
dc.DrawText( tooltip.AfterLast( '\n' ), ( dc_size.x - tsize.x )/2, ( dc_size.y + tsize.y )/2 );
return; return;
} }

View File

@ -3,24 +3,20 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software: you can redistribute it and/or modify it
* modify it under the terms of the GNU General Public License * under the terms of the GNU General Public License as published by the
* as published by the Free Software Foundation; either version 2 * Free Software Foundation, either version 3 of the License, or (at your
* of the License, or (at your option) any later version. * option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, you may find one here: * with this program. If not, see <http://www.gnu.org/licenses/>.
* 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
*/ */
/** /**
@ -259,4 +255,11 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC,std::vector<wxPoint>& aLines,
void GRDrawAnchor( EDA_RECT* aClipBox, wxDC *aDC, int x, int y, int aSize, void GRDrawAnchor( EDA_RECT* aClipBox, wxDC *aDC, int x, int y, int aSize,
COLOR4D aColor ); COLOR4D aColor );
/**
* Draw text centered on a wxDC with wrapping.
* @param aDC wxDC instance onto which the text will be drawn
* @param aText the text to draw
*/
void GRDrawWrappedText( wxDC& aDC, wxString const& aText );
#endif /* define GR_BASIC */ #endif /* define GR_BASIC */