mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 16:49:41 +02:00
Better localization of tooltips in ASlider...
... i18n-hints, avoid syntax assumptions (for Right and Left), avoid assumptions about widths of non-numerical data
This commit is contained in:
parent
cfa62d1d30
commit
0bca8d15f9
@ -88,7 +88,7 @@ const int sliderFontSize = 12;
|
|||||||
class TipPanel final : public wxFrame
|
class TipPanel final : public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TipPanel(wxWindow *parent, const wxString & label);
|
TipPanel(wxWindow *parent, const wxArrayString & labels);
|
||||||
virtual ~TipPanel() {}
|
virtual ~TipPanel() {}
|
||||||
|
|
||||||
wxSize GetSize() const;
|
wxSize GetSize() const;
|
||||||
@ -102,7 +102,6 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxString mMaxLabel;
|
|
||||||
wxString mLabel;
|
wxString mLabel;
|
||||||
int mWidth;
|
int mWidth;
|
||||||
int mHeight;
|
int mHeight;
|
||||||
@ -117,15 +116,20 @@ BEGIN_EVENT_TABLE(TipPanel, wxFrame)
|
|||||||
#endif
|
#endif
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
TipPanel::TipPanel(wxWindow *parent, const wxString & maxLabel)
|
TipPanel::TipPanel(wxWindow *parent, const wxArrayString & labels)
|
||||||
: wxFrame(parent, wxID_ANY, wxString{}, wxDefaultPosition, wxDefaultSize,
|
: wxFrame(parent, wxID_ANY, wxString{}, wxDefaultPosition, wxDefaultSize,
|
||||||
wxFRAME_SHAPED | wxFRAME_FLOAT_ON_PARENT)
|
wxFRAME_SHAPED | wxFRAME_FLOAT_ON_PARENT)
|
||||||
{
|
{
|
||||||
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||||
|
|
||||||
mMaxLabel = maxLabel;
|
|
||||||
wxFont labelFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL);
|
wxFont labelFont(sliderFontSize, wxSWISS, wxNORMAL, wxNORMAL);
|
||||||
GetTextExtent(mMaxLabel, &mWidth, &mHeight, NULL, NULL, &labelFont);
|
mWidth = mHeight = 0;
|
||||||
|
for ( const auto &label : labels ) {
|
||||||
|
int width, height;
|
||||||
|
GetTextExtent(label, &width, &height, NULL, NULL, &labelFont);
|
||||||
|
mWidth = std::max( mWidth, width );
|
||||||
|
mHeight = std::max( mHeight, height );
|
||||||
|
}
|
||||||
|
|
||||||
mWidth += 8;
|
mWidth += 8;
|
||||||
mHeight += 8;
|
mHeight += 8;
|
||||||
@ -915,7 +919,7 @@ void LWSlider::ShowTip(bool show)
|
|||||||
|
|
||||||
void LWSlider::CreatePopWin()
|
void LWSlider::CreatePopWin()
|
||||||
{
|
{
|
||||||
mTipPanel = std::make_unique<TipPanel>(mParent, GetMaxTip());
|
mTipPanel = std::make_unique<TipPanel>(mParent, GetWidestTips());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LWSlider::SetPopWinPosition()
|
void LWSlider::SetPopWinPosition()
|
||||||
@ -967,10 +971,17 @@ wxString LWSlider::GetTip(float value) const
|
|||||||
|
|
||||||
case DB_SLIDER:
|
case DB_SLIDER:
|
||||||
val.Printf( wxT("%+.1f dB"), value );
|
val.Printf( wxT("%+.1f dB"), value );
|
||||||
|
|
||||||
|
/*
|
||||||
|
// PRL: This erroneous code never had effect because
|
||||||
|
// the condition was always false (at least for the English format
|
||||||
|
// string), and the body had no side effect
|
||||||
if (val.Right(1) == wxT("0"))
|
if (val.Right(1) == wxT("0"))
|
||||||
{
|
{
|
||||||
val.Left(val.Length() - 2);
|
val.Left(val.Length() - 2);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PAN_SLIDER:
|
case PAN_SLIDER:
|
||||||
@ -980,21 +991,29 @@ wxString LWSlider::GetTip(float value) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
val.Printf(wxT("%.0f%% %s"),
|
const auto v = 100.0f * fabsf(value);
|
||||||
value * (value < 0.0 ? -100.0f : 100.0f),
|
if (value < 0.0)
|
||||||
value < 0.0 ? _("Left") : _("Right"));
|
/* i18n-hint: Stereo pan setting */
|
||||||
|
val = wxString::Format( _("%.0f%% Left"), v );
|
||||||
|
else
|
||||||
|
/* i18n-hint: Stereo pan setting */
|
||||||
|
val = wxString::Format( _("%.0f%% Right"), v );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPEED_SLIDER:
|
case SPEED_SLIDER:
|
||||||
|
/* i18n-hint: "x" suggests a multiplicative factor */
|
||||||
val.Printf( wxT("%.2fx"), value );
|
val.Printf( wxT("%.2fx"), value );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||||
case VEL_SLIDER:
|
case VEL_SLIDER:
|
||||||
val.Printf(wxT("%s%d"),
|
if (value > 0.0f)
|
||||||
(value > 0.0f ? _("+") : wxT("")),
|
// Signed
|
||||||
(int) value);
|
val.Printf( wxT("%+d"), (int) value );
|
||||||
|
else
|
||||||
|
// Zero, or signed negative
|
||||||
|
val.Printf( wxT("%d"), (int) value );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1009,9 +1028,9 @@ wxString LWSlider::GetTip(float value) const
|
|||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString LWSlider::GetMaxTip() const
|
wxArrayString LWSlider::GetWidestTips() const
|
||||||
{
|
{
|
||||||
wxString label;
|
wxArrayString results;
|
||||||
|
|
||||||
if (mTipTemplate.IsEmpty())
|
if (mTipTemplate.IsEmpty())
|
||||||
{
|
{
|
||||||
@ -1020,36 +1039,38 @@ wxString LWSlider::GetMaxTip() const
|
|||||||
switch(mStyle)
|
switch(mStyle)
|
||||||
{
|
{
|
||||||
case FRAC_SLIDER:
|
case FRAC_SLIDER:
|
||||||
val.Printf(wxT("%d.99"), (int) (mMinValue - mMaxValue));
|
results.push_back( GetTip( -1.99f ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DB_SLIDER:
|
case DB_SLIDER:
|
||||||
val = wxT("-99.999 dB");
|
results.push_back( GetTip( -99.9f ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PAN_SLIDER:
|
case PAN_SLIDER:
|
||||||
val = wxT("-100% Right");
|
// Don't assume we know which of "Left", "Right", or "Center"
|
||||||
|
// is the longest string, when localized
|
||||||
|
results.push_back( GetTip( 0.f ) );
|
||||||
|
results.push_back( GetTip( 1.f ) );
|
||||||
|
results.push_back( GetTip( -1.f ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPEED_SLIDER:
|
case SPEED_SLIDER:
|
||||||
val = wxT("9.99x");
|
results.push_back( GetTip( 9.99f ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||||
case VEL_SLIDER:
|
case VEL_SLIDER:
|
||||||
val = wxT("+127");
|
results.push_back( GetTip( 999.f ) );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
label.Printf(_("%s: %s"), mName, val);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
label.Printf(mTipTemplate, floor(mMaxValue - mMinValue) + 0.999);
|
results.push_back( GetTip( floor(mMaxValue - mMinValue) + 0.999 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return label;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LWSlider::ShowDialog()
|
bool LWSlider::ShowDialog()
|
||||||
|
@ -161,7 +161,7 @@ class LWSlider
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
wxString GetTip(float value) const;
|
wxString GetTip(float value) const;
|
||||||
wxString GetMaxTip() const;
|
wxArrayString GetWidestTips() const;
|
||||||
void FormatPopWin();
|
void FormatPopWin();
|
||||||
void SetPopWinPosition();
|
void SetPopWinPosition();
|
||||||
void CreatePopWin();
|
void CreatePopWin();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user