General TC > Programming & Scripting - Unofficial
mnttool auto button width to accommodate longer device names
(1/1)
Rich:
Hi polikuo
The updated mnttool does not properly resize the buttons to
the correct height in x86 fltk-1.3:
I traced the issue to this line:
--- Code: ---pack->resize(0,0,12*wotbp>80 ? 12*wotbp : 80,(25*(mount_list_size)));
--- End code ---
I rearranged the code to:
compute the button width ahead of time
create the pack widget at the correct size.
create the buttons at the correct width
This way the buttons get added to the pack widget at the
correct size. Here's a diff of the changes:
--- Code: ------ mnttool.cxx.bak 2025-03-02 09:18:16.496342577 +0000
+++ mnttool.cxx 2025-03-02 10:38:30.186260710 +0000
@@ -47,12 +47,19 @@
// width of the button pack
size_t wotbp = 1;
+ for (int i=0; i < mount_list_size; i++)
+ {
+ if ( strlen(mountList[i].c_str()) > wotbp )
+ wotbp = strlen(mountList[i].c_str());
+ }
+ wotbp = 12*wotbp>80 ? 12*wotbp : 80;
+ pack->resize(0,0,wotbp,(25*(mount_list_size)));
for (int i=0; i < mount_list_size; i++)
{
Fl_Button* btn[i];
- btn[i] = new Fl_Button(0,0,80,25);
+ btn[i] = new Fl_Button(0,0,wotbp,25);
btn[i]->label(mountList[i].c_str());
btn[i]->tooltip(mountLabels[i].c_str());
btn[i]->callback((Fl_Callback*)btnCallback,(void*)(uintptr_t)i);
@@ -63,20 +70,17 @@
btn[i]->color((Fl_Color)1);
pack->add(btn[i]);
- if ( strlen(mountList[i].c_str()) > wotbp )
- wotbp = strlen(mountList[i].c_str());
}
Fl_Button* btnRefresh;
- btnRefresh = new Fl_Button(0,0,80,25);
+ btnRefresh = new Fl_Button(0,0,wotbp,25);
btnRefresh->label("Refresh");
btnRefresh->callback((Fl_Callback*)btnRefreshCallback);
pack->add(btnRefresh);
selected = 0;
- pack->resize(0,0,12*wotbp>80 ? 12*wotbp : 80,(25*(mount_list_size)));
pack->redraw();
- w->resize(0,0,12*wotbp>80 ? 12*wotbp : 80,(25*(mount_list_size+1)));
+ w->resize(0,0,wotbp,(25*(mount_list_size+1)));
w->position(xPos,yPos);
w->redraw();
}
--- End code ---
Side by side of the non auto version and the corrected version:
Comments welcome.
Navigation
[0] Message Index
Go to full version