Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Sizing wip
Browse files Browse the repository at this point in the history
Signed-off-by: akleja <storspov@gmail.com>
  • Loading branch information
akleja committed Oct 8, 2021
1 parent 168d06e commit 5339684
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
64 changes: 34 additions & 30 deletions src/toolbars/MeterToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ MeterToolBar::MeterToolBar(AudacityProject &project, int type)
mSizer = NULL;
mPlayMeter = NULL;
mRecordMeter = NULL;

mChannelsMenu = safenew wxMenu();
mIOMenu = safenew wxMenu();

Expand All @@ -107,8 +108,8 @@ void MeterToolBar::Create(wxWindow * parent)
UpdatePrefs();

// Simulate a size event to set initial meter placement/size
wxSizeEvent dummy;
OnSize(dummy);
/* wxSizeEvent dummy;
OnSize(dummy);*/
}

void MeterToolBar::ReCreateButtons()
Expand Down Expand Up @@ -157,7 +158,7 @@ void MeterToolBar::Populate()
mInButton->SetLabel(XO("Input"));
mInButton->SetFocusRect( mInButton->GetClientRect().Deflate( 1, 1 ) );
mInButton->SetToolTip(XO("Input settings"));
mSizer->Add( mInButton, wxGBPosition( 0, (mWhichMeters & kWithPlayMeter)?2:0 ), wxGBSpan(2,1), wxALIGN_CENTER_VERTICAL );
mSizer->Add( mInButton, wxGBPosition( 0, 0), wxGBSpan(2,2), wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER );

//JKC: Record on left, playback on right. Left to right flow
//(maybe we should do it differently for Arabic language :-) )
Expand All @@ -173,12 +174,13 @@ void MeterToolBar::Populate()
This is the name used in screen reader software, where having 'Meter' first
apparently is helpful to partially sighted people. */
mRecordMeter->SetLabel( XO("Meter-Record") );
mSizer->Add( mRecordMeter, wxGBPosition( 0, (mWhichMeters & kWithPlayMeter)?3:1 ), wxDefaultSpan, wxEXPAND );
mSizer->Add( mRecordMeter, wxGBPosition( 0, 2 ), wxDefaultSpan, wxEXPAND );

Bind(wxEVT_BUTTON, &MeterToolBar::OnInputButton, this, ID_INPUT_BUTTON);
}

if( mWhichMeters & kWithPlayMeter ){

//Add Button
AButton *mOutButton = MeterToolBar::MakeButton(this,
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall, bmpRecoloredHiliteSmall,
Expand All @@ -189,7 +191,7 @@ void MeterToolBar::Populate()
mOutButton->SetLabel(XO("Output"));
mOutButton->SetFocusRect( mOutButton->GetClientRect().Deflate( 1, 1 ) );
mOutButton->SetToolTip(XO("Output settings"));
mSizer->Add( mOutButton, wxGBPosition( 0, 0 ), wxGBSpan(2,1), wxALIGN_CENTER_VERTICAL );
mSizer->Add( mOutButton, wxGBPosition( 0, 0 ), wxGBSpan(2,2), wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER );

mPlayMeter = safenew MeterPanel( &mProject,
this,
Expand All @@ -203,8 +205,8 @@ void MeterToolBar::Populate()
This is the name used in screen reader software, where having 'Meter' first
apparently is helpful to partially sighted people. */
mPlayMeter->SetLabel( XO("Meter-Play"));
mSizer->Add( mPlayMeter, wxGBPosition( 0, 2 ), wxDefaultSpan, wxEXPAND );

mOutSizer->Add( mPlayMeter, wxGBPosition( 0, 2 ), wxDefaultSpan, wxEXPAND );
Bind(wxEVT_BUTTON, &MeterToolBar::OnOutputButton, this, ID_OUTPUT_BUTTON);
}

Expand Down Expand Up @@ -238,58 +240,60 @@ void MeterToolBar::OnSize( wxSizeEvent & event) //WXUNUSED(event) )
int width, height;

// We can be resized before populating...protect against it
if( !mSizer ) {
if( !mSizer && mRecordMeter || !mSizer && mPlayMeter || !GetSizer() ) {
return;
}

// Update the layout
Layout();

// Get the usable area
wxSize sz = GetSizer()->GetSize();
width = sz.x; height = sz.y;
width -= 27;// get button size

//Check propotions
//20 is the initial reset size for toolbars. Makes sure toolbars are treated
//as horizontal on reset.
bHorizontal = ( width > height || width==20 || height==20 );

//Update MinSize
sz.SetWidth(GetMinToolbarWidth());
sz.SetHeight(GetMinToolbarHeight());
SetMinSize(sz);


int nMeters =
((mRecordMeter ==NULL) ? 0:1) +
((mPlayMeter ==NULL) ? 0:1);

bool bHorizontal = ( width > height );
bool bEndToEnd = ( nMeters > 1 ) && wxMin( width, height ) < (60 * nMeters);

// Default location for second meter
wxGBPosition pos( 0, 0 );
wxGBPosition pos;
// If 2 meters, share the height or width.
if( nMeters > 1 ){
if( bHorizontal ^ bEndToEnd ){
height /= nMeters;
pos = wxGBPosition( 1, 0 );
} else {
if( bHorizontal ){
width /= nMeters;
pos = wxGBPosition( 0, 1 );
width -= 27;// get button size + extra för att de är flera cells
pos = wxGBPosition( 0, 2 );
} else {
height /= nMeters;
height -= 27;// get button size + extra för att de är flera cells
pos = wxGBPosition( 2, 0 );
}

float tmp;

if( mRecordMeter && mWhichMeters & kWithRecordMeter ) {
//auto inButton = static_cast<AButton*>(FindWindow(ID_INPUT_BUTTON));

mRecordMeter->SetMinSize( wxSize( std::max(width-wd,20), std::max(height-hd,20)));
mInSizer->SetItemPosition( mRecordMeter, pos );

mSizer->SetItemPosition( mRecordMeter, pos );
mRecordMeter->SetMinSize( wxSize( width, height));
}

if( mPlaydMeter && mWhichMeters & kWithPlayMeter ) {

mPlayMeter->SetMinSize( wxSize( std::max(width-wd,20), std::max(height-hd,20)));
mOutSizer->SetItemPosition( mPlayMeter, pos );
if( mPlayMeter && mWhichMeters & kWithPlayMeter ) {
mSizer->SetItemPosition( mPlayMeter, pos );
mPlayMeter->SetMinSize( wxSize( width, height));
}

// And make it happen
Layout();
Fit();
}


bool MeterToolBar::Expose( bool show )
{
auto &projectAudioIO = ProjectAudioIO::Get( mProject );
Expand Down
7 changes: 4 additions & 3 deletions src/toolbars/MeterToolBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class MeterToolBar final : public ToolBar {

MeterToolBar(AudacityProject &project, int type);
virtual ~MeterToolBar();

void Create(wxWindow *parent) override;

void Populate() override;
Expand All @@ -48,8 +47,9 @@ class MeterToolBar final : public ToolBar {
bool Expose(bool show) override;

int GetInitialWidth() override {return (mWhichMeters ==
(kWithRecordMeter + kWithPlayMeter)) ? 338 : 460;} // Separate bars used to be smaller.
int GetMinToolbarWidth() override { return 150; }
(kWithRecordMeter + kWithPlayMeter)) ? 554 : 277;} // Separate bars used to be smaller.
int GetMinToolbarWidth() override {return (bHorizontal) ? 145 : toolbarSingle+11; }
int GetMinToolbarHeight() {return (bHorizontal) ? toolbarSingle : 145; }
wxSize GetDockedSize() override {
return GetSmartDockedSize();
};
Expand All @@ -76,6 +76,7 @@ class MeterToolBar final : public ToolBar {
void OnRecPreferences(wxCommandEvent &event);


bool bHorizontal;
int mWhichMeters;
wxGridBagSizer *mSizer;
MeterPanel *mPlayMeter;
Expand Down
11 changes: 9 additions & 2 deletions src/toolbars/ToolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ToolManager.h"

#include "../commands/CommandContext.h"
#include "ToolBar.h"

// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
Expand Down Expand Up @@ -134,11 +135,15 @@ ToolFrame::ToolFrame
// Make sure resizable floaters don't get any smaller than initial size
if( bar->IsResizable() )
{
// Calc the minimum size of the frame
mMinSize = bar->GetMinSize() + ( GetSize() - bar->GetSize() );
mMinSize=CalcMinSize(bar);
}
}

wxSize ToolFrame::CalcMinSize(ToolBar * bar) {
// Calc the minimum size of the frame
return bar->GetMinSize() + ( GetSize() - bar->GetSize() );
}

ToolFrame::~ToolFrame()
{
if(HasCapture())
Expand Down Expand Up @@ -212,6 +217,8 @@ void ToolFrame::OnMotion( wxMouseEvent & event )
{
return;
}
// Calc the minimum size of the frame
mMinSize=CalcMinSize(mBar);

// Retrieve the mouse position
wxPoint pos = ClientToScreen( event.GetPosition() );
Expand Down
2 changes: 2 additions & 0 deletions src/toolbars/ToolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class ToolFrame final : public wxFrame
void ClearBar() { mBar = nullptr; }
void LockInMinSize(ToolBar * pBar);

wxSize CalcMinSize(ToolBar * bar);

//
// Transition a toolbar from float to dragging
//
Expand Down

0 comments on commit 5339684

Please sign in to comment.