Merge pull request #15 from pietro1991-dot/devin/1781679998-panel-autofit

Co-authored-by: Pietro Giacobazzi <giacobazzipietro@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
pietro1991-dot
2026-06-17 09:07:48 +02:00
committed by GitHub
+22 -9
View File
@@ -440,6 +440,14 @@ int OnCalculate(const int rates_total,
}
//+------------------------------------------------------------------+
// larghezza in pixel di un testo nel font del pannello
int TxtW(string s,int fs,bool bold)
{
TextSetFont(bold?"Consolas Bold":"Consolas",-fs*10);
uint w=0,h=0; TextGetSize(s,w,h);
return (int)w;
}
//+------------------------------------------------------------------+
void DrawInfo()
{
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
@@ -456,7 +464,7 @@ void DrawInfo()
double cluCur,cluPct,velCur,velPct,accCur,accPct,volCur,volPct;
AllMetrics(CLWIN,cluCur,cluPct,velCur,velPct,accCur,accPct,volCur,volPct);
string sT = "PaPP Median ["+EnumToString((ENUM_TIMEFRAMES)_Period)+"]";
string sT = "PaPP Median ["+StringSubstr(EnumToString((ENUM_TIMEFRAMES)_Period),7)+"]";
string sM = "Median: "+DoubleToString(median,_Digits);
string sD = StringFormat("Dist: %+.2f%% - %s (P%.0f)",distPct,DistWord(distPct,distAbsPct),distAbsPct*100);
string sV = StringFormat("Cluster %.3f%% - %s (P%.0f)",cluCur,MagWord(cluPct,"molto stretto","stretto","normale","largo","molto largo"),cluPct*100);
@@ -467,15 +475,20 @@ void DrawInfo()
for(int m=0;m<7;m++) sMA[m]=StringFormat("MA %3dg: %s",gDays[m],DoubleToString(GetMA(m,1),_Digits));
string sH = "Sopra=SELL | Sotto=BUY";
//--- 2) larghezza/altezza del box dal contenuto
int maxc=StringLen(sT);
int lens[7]; lens[0]=StringLen(sM); lens[1]=StringLen(sD); lens[2]=StringLen(sV);
lens[3]=StringLen(sVE); lens[4]=StringLen(sAC); lens[5]=StringLen(sVO); lens[6]=StringLen(sH);
for(int k=0;k<7;k++) if(lens[k]>maxc) maxc=lens[k];
for(int m=0;m<7;m++) if(StringLen(sMA[m])>maxc) maxc=StringLen(sMA[m]);
//--- 2) larghezza/altezza del box: misuro la larghezza REALE in pixel (TextGetSize)
int maxw=0;
maxw=MathMax(maxw,TxtW(sT,FontSize+2,true));
maxw=MathMax(maxw,TxtW(sM,FontSize,false));
maxw=MathMax(maxw,TxtW(sD,FontSize,true));
maxw=MathMax(maxw,TxtW(sV,FontSize,false));
maxw=MathMax(maxw,TxtW(sVE,FontSize,false));
maxw=MathMax(maxw,TxtW(sAC,FontSize,false));
maxw=MathMax(maxw,TxtW(sVO,FontSize,false));
maxw=MathMax(maxw,TxtW(sH,FontSize-1,false));
for(int m=0;m<7;m++) maxw=MathMax(maxw,TxtW(sMA[m],FontSize-1,false));
int boxX=x-6, boxY=y0-6;
int w=(int)(maxc*FontSize*0.62)+18;
int bodyH=15*lh+6; // 7 righe in alto + 7 MA + riga finale + padding
int w=maxw+(x-boxX)+10; // padding sinistro (x-boxX) + destro 10
int bodyH=15*lh+6; // 7 righe in alto + 7 MA + riga finale + padding
PanelBox(boxX,boxY,w,bodyH);
//--- 3) scritte (aggiornate in-place: niente ObjectsDeleteAll -> niente lampeggio)