MCPcopy Create free account
hub / github.com/78/tenbox / UpdateToolbarSpring

Function UpdateToolbarSpring

src/manager/ui/win32_ui_shell.cpp:455–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453// Adjusts the spring separator width so that buttons after it are right-aligned.
454
455static void UpdateToolbarSpring(HWND tb) {
456 int spring_idx = static_cast<int>(SendMessage(tb, TB_COMMANDTOINDEX, IDC_SPRING_SEP, 0));
457 if (spring_idx < 0) return;
458
459 int count = static_cast<int>(SendMessage(tb, TB_BUTTONCOUNT, 0, 0));
460
461 // First, set spring to minimal width so TB_AUTOSIZE computes natural layout
462 TBBUTTONINFOW info{};
463 info.cbSize = sizeof(info);
464 info.dwMask = TBIF_SIZE;
465 info.cx = 0;
466 SendMessageW(tb, TB_SETBUTTONINFOW, IDC_SPRING_SEP, reinterpret_cast<LPARAM>(&info));
467 SendMessage(tb, TB_AUTOSIZE, 0, 0);
468
469 // Measure width of all buttons after the spring
470 int right_width = 0;
471 for (int i = spring_idx + 1; i < count; ++i) {
472 RECT r{};
473 SendMessage(tb, TB_GETITEMRECT, i, reinterpret_cast<LPARAM>(&r));
474 right_width += r.right - r.left;
475 }
476
477 // Get toolbar client width
478 RECT rc;
479 GetClientRect(tb, &rc);
480 int tb_width = rc.right;
481
482 // Get the left edge of the spring separator (= total width of all buttons before it)
483 RECT spring_rc{};
484 SendMessage(tb, TB_GETITEMRECT, spring_idx, reinterpret_cast<LPARAM>(&spring_rc));
485 int left_width = spring_rc.left;
486
487 int spring_width = tb_width - left_width - right_width;
488 if (spring_width < 0) spring_width = 0;
489
490 info.cx = static_cast<WORD>(spring_width);
491 SendMessageW(tb, TB_SETBUTTONINFOW, IDC_SPRING_SEP, reinterpret_cast<LPARAM>(&info));
492}
493
494// ── Layout helper ──
495

Callers 1

LayoutControlsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected