Skip to content

Commit e62e9b3

Browse files
committed
connected_tab: fix State/Device column autosizing
Because ListView only supports autosizing the last column to fill the remaining space, the State and Device column were swapped, since State has a know max width ("Not shared" string). When creating the list view, a dummy row is inserted with max-width content to size the State column properly.
1 parent c76e4fa commit e62e9b3

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/gui/connected_tab/mod.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use nwg::stretch::{
1111
geometry::{Rect, Size},
1212
style::{Dimension as D, FlexDirection},
1313
};
14+
use windows_sys::Win32::UI::Controls::LVSCW_AUTOSIZE;
1415
use windows_sys::Win32::UI::Controls::LVSCW_AUTOSIZE_USEHEADER;
1516
use windows_sys::Win32::UI::Shell::SIID_SHIELD;
1617

@@ -20,7 +21,7 @@ use crate::gui::{
2021
nwg_ext::{BitmapEx, MenuItemEx},
2122
usbipd_gui::GuiTab,
2223
};
23-
use crate::usbipd::{self, UsbDevice};
24+
use crate::usbipd::{self, UsbDevice, UsbipState};
2425

2526
const PADDING_LEFT: Rect<D> = Rect {
2627
start: D::Points(8.0),
@@ -137,16 +138,22 @@ impl ConnectedTab {
137138
}
138139

139140
fn init_list(&self) {
140-
let dv = &self.list_view;
141-
dv.clear();
142-
dv.insert_column("Bus ID");
143-
dv.insert_column("Device");
144-
dv.insert_column("State");
145-
dv.set_headers_enabled(true);
146-
147-
dv.set_column_width(0, LVSCW_AUTOSIZE_USEHEADER as isize);
148-
dv.set_column_width(1, 415);
149-
dv.set_column_width(2, LVSCW_AUTOSIZE_USEHEADER as isize);
141+
let list = &self.list_view;
142+
list.clear();
143+
list.insert_column("Bus ID");
144+
list.insert_column("State");
145+
list.insert_column("Device");
146+
list.set_headers_enabled(true);
147+
148+
// Insert a dummy row, with max-width content in columns where AUTOSIZE is used
149+
list.insert_items_row(None, &["-", &format!("{} ", UsbipState::None), "Device"]);
150+
151+
list.set_column_width(0, LVSCW_AUTOSIZE_USEHEADER as isize);
152+
list.set_column_width(1, LVSCW_AUTOSIZE as isize);
153+
list.set_column_width(2, LVSCW_AUTOSIZE_USEHEADER as isize);
154+
155+
// Clear the dummy row
156+
list.clear();
150157
}
151158

152159
/// Clears the device list and reloads it with the currently connected devices.
@@ -159,8 +166,8 @@ impl ConnectedTab {
159166
None,
160167
&[
161168
device.bus_id.as_deref().unwrap_or("-"),
162-
device.description.as_deref().unwrap_or("Unknown device"),
163169
&device.state().to_string(),
170+
device.description.as_deref().unwrap_or("Unknown device"),
164171
],
165172
);
166173
}

0 commit comments

Comments
 (0)