1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 16:41:14 +02:00

Dialog for the name of a label: positioning fixes

Problems fixed:
1. When adding a label at playback position, the position of the dialog was calculated using the position of the edit cursor
2. When adding a label at selection, the dialog could be to the left of the Audacity Window, and indeed offscreen.
This commit is contained in:
David Bailes 2018-10-24 11:07:17 +01:00
parent d716b61b1e
commit 5494185a88
3 changed files with 11 additions and 6 deletions

View File

@ -2102,7 +2102,7 @@ bool LabelTrack::OnChar(SelectedRegion &WXUNUSED(newSel), wxKeyEvent & event)
gPrefs->Read(wxT("/Gui/DialogForNameNewLabel"), &useDialog, false);
if (useDialog) {
wxString title;
if (MenuCommandHandler::DialogForLabelName(*p, charCode, title) ==
if (MenuCommandHandler::DialogForLabelName(*p, p->mViewInfo.selectedRegion, charCode, title) ==
wxID_CANCEL) {
return false;
}

View File

@ -9437,14 +9437,18 @@ void MenuCommandHandler::OnRescanDevices(const CommandContext &WXUNUSED(context)
}
int MenuCommandHandler::DialogForLabelName(
AudacityProject &project, const wxString& initialValue, wxString& value)
AudacityProject &project,
const SelectedRegion& region, const wxString& initialValue, wxString& value)
{
auto trackPanel = project.GetTrackPanel();
auto &viewInfo = project.GetViewInfo();
wxPoint position = trackPanel->FindTrackRect(trackPanel->GetFocusedTrack(), false).GetBottomLeft();
// the start of the text in the text box will be roughly in line with Audacity's edit cursor
position.x += trackPanel->GetLabelWidth() + viewInfo.TimeToPosition(viewInfo.selectedRegion.t0()) - 40;
// The start of the text in the text box will be roughly in line with the label's position
// if it's a point label, or the start of its region if it's a region label.
position.x += trackPanel->GetLabelWidth()
+ std::max(0, static_cast<int>(viewInfo.TimeToPosition(region.t0())))
-40;
position.y += 2; // just below the bottom of the track
position = trackPanel->ClientToScreen(position);
AudacityTextEntryDialog dialog{ &project,
@ -9615,7 +9619,7 @@ int MenuCommandHandler::DoAddLabel(
bool useDialog;
gPrefs->Read(wxT("/GUI/DialogForNameNewLabel"), &useDialog, false);
if (useDialog) {
if (DialogForLabelName(project, wxEmptyString, title) == wxID_CANCEL)
if (DialogForLabelName(project, region, wxEmptyString, title) == wxID_CANCEL)
return -1; // index
}

View File

@ -43,7 +43,8 @@ int DoAddLabel(
AudacityProject &project,
const SelectedRegion& region, bool preserveFocus = false);
static int DialogForLabelName(
AudacityProject &project, const wxString& initialValue, wxString& value);
AudacityProject &project,
const SelectedRegion& region, const wxString& initialValue, wxString& value);
double NearestZeroCrossing(AudacityProject &project, double t0);