3030#include " ShowHideOptionsButton.h"
3131
3232#include < math.h>
33+ #include < algorithm>
34+ #include < cmath>
3335
3436#define MS_FROM_START Time::highResolutionTicksToSeconds (Time::getHighResolutionTicks() - start) * 1000
3537
@@ -750,6 +752,27 @@ String LfpDisplaySplitter::getStreamKey()
750752 return stream->getKey ();
751753}
752754
755+ void LfpDisplaySplitter::refreshLeftMargin ()
756+ {
757+ int newMargin = minimumLeftMargin;
758+
759+ if (displayBuffer != nullptr )
760+ {
761+ const auto labelFont = Font (FontOptions (14 .0f ));
762+ constexpr int padding = 20 ;
763+
764+ for (int i = 0 ; i < displayBuffer->channelMetadata .size (); ++i)
765+ {
766+ const auto & metadata = displayBuffer->channelMetadata .getReference (i);
767+ const float textWidth = labelFont.getStringWidthFloat (metadata.name );
768+ const int requiredWidth = static_cast <int > (std::ceil (textWidth)) + padding;
769+ newMargin = std::max (newMargin, requiredWidth);
770+ }
771+ }
772+
773+ leftmargin = newMargin;
774+ }
775+
753776void LfpDisplaySplitter::resized ()
754777{
755778 const int timescaleHeight = 30 ;
@@ -928,6 +951,7 @@ void LfpDisplaySplitter::updateSettings()
928951 sampleRate = 44100 .0f ;
929952
930953 options->setEnabled (true );
954+ leftmargin = minimumLeftMargin;
931955 }
932956 else
933957 {
@@ -942,6 +966,8 @@ void LfpDisplaySplitter::updateSettings()
942966
943967 options->setEnabled (true );
944968 channelOverlapFactor = options->selectedOverlapValue .getFloatValue ();
969+
970+ refreshLeftMargin ();
945971 }
946972
947973 if (eventDisplayBuffer == nullptr ) // not yet initialized
@@ -968,12 +994,14 @@ void LfpDisplaySplitter::updateSettings()
968994 lfpDisplay->channels [i]->setDepth (displayBuffer->channelMetadata [i].ypos );
969995 lfpDisplay->channels [i]->setRecorded (displayBuffer->channelMetadata [i].isRecorded );
970996 lfpDisplay->channels [i]->updateType (displayBuffer->channelMetadata [i].type );
997+ lfpDisplay->channels [i]->setUnits (displayBuffer->channelMetadata [i].units );
971998
972999 lfpDisplay->channelInfo [i]->setName (displayBuffer->channelMetadata [i].name );
9731000 lfpDisplay->channelInfo [i]->setGroup (displayBuffer->channelMetadata [i].group );
9741001 lfpDisplay->channelInfo [i]->setDepth (displayBuffer->channelMetadata [i].ypos );
9751002 lfpDisplay->channelInfo [i]->setRecorded (displayBuffer->channelMetadata [i].isRecorded );
9761003 lfpDisplay->channelInfo [i]->updateType (displayBuffer->channelMetadata [i].type );
1004+ lfpDisplay->channelInfo [i]->setUnits (displayBuffer->channelMetadata [i].units );
9771005
9781006 lfpDisplay->updateRange (i);
9791007
0 commit comments