Feature: Address book & accessible devices side panels resizable (#17153)

* Feature: Make the address book & accessible devices side panels resizable

The Address book panel and the Accessible devices panel can now
be resized by dragging a divider on their right edge. The width is clamped
(150–300px) and persisted per panel as a local option, so it survives restarts.

* Fix side panel overflow in narrow windows

A saved panel width can push the divider and the peer list off the
screen. The panel now uses the row width to limit its visible width.
When there is space, the peer list shows one full peer card.
This commit is contained in:
StealUrKill authored and GitHub committed 2026-12-02 15:35:14 +08:00
1 parent 621cace696
commit fbebada5bf
4 files changed
+121 -6

No files matched your search

+3 -3
View File
@@ -8,6 +8,7 @@ import 'package:flutter_hbb/common/formatter/id_formatter.dart';
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
import 'package:flutter_hbb/common/widgets/peer_card.dart';
import 'package:flutter_hbb/common/widgets/peers_view.dart';
import 'package:flutter_hbb/common/widgets/resizable_side_panel.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/desktop/widgets/popup_menu.dart';
import 'package:flutter_hbb/models/ab_model.dart';
@@ -73,7 +74,7 @@ class _AddressBookState extends State<AddressBook> {
});
Widget _buildAddressBookLandscape() {
return Row(
return ResizablePanelRow(
children: [
Offstage(
offstage: hideAbTagsPanel.value,
@@ -83,7 +84,6 @@ class _AddressBookState extends State<AddressBook> {
border: Border.all(
color: Theme.of(context).colorScheme.background)),
child: Container(
width: 200,
height: double.infinity,
child: Column(
children: [
@@ -103,7 +103,7 @@ class _AddressBookState extends State<AddressBook> {
],
),
),
).marginOnly(right: 12.0)),
).resizable(kOptionAbTagsPanelWidth, defaultWidth: 200)),
_buildPeersViews()
],
);
+4 -3
View File
@@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
import 'package:flutter_hbb/common/widgets/login.dart';
import 'package:flutter_hbb/common/widgets/peers_view.dart';
import 'package:flutter_hbb/common/widgets/resizable_side_panel.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/models/state_model.dart';
import 'package:get/get.dart';
@@ -58,7 +60,7 @@ class _MyGroupState extends State<MyGroup> {
}
Widget _buildLandscape() {
return Row(
return ResizablePanelRow(
children: [
Container(
decoration: BoxDecoration(
@@ -66,7 +68,6 @@ class _MyGroupState extends State<MyGroup> {
border:
Border.all(color: Theme.of(context).colorScheme.background)),
child: Container(
width: 150,
height: double.infinity,
child: Column(
children: [
@@ -81,7 +82,7 @@ class _MyGroupState extends State<MyGroup> {
],
),
),
).marginOnly(right: 12.0),
).resizable(kOptionAccessibleDevicesPanelWidth, defaultWidth: 150),
Expanded(
child: Align(
alignment: Alignment.topLeft,
@@ -0,0 +1,111 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/models/platform_model.dart';
const double _kDividerWidth = 12;
const double _kMinContentWidth = 120;
// One 220 px peer card (see peers_view.dart) plus the 12 px spacing.
const double _kPeerCardWidth = 232;
/// A [Row] that lets a [ResizableSidePanel] inside it cap its width to the space the row actually has.
class ResizablePanelRow extends StatelessWidget {
final List<Widget> children;
const ResizablePanelRow({Key? key, required this.children})
: super(key: key);
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) => _AvailableWidth(
width: constraints.maxWidth, child: Row(children: children)));
}
class _AvailableWidth extends InheritedWidget {
final double width;
const _AvailableWidth({required this.width, required Widget child})
: super(child: child);
@override
bool updateShouldNotify(_AvailableWidth oldWidget) =>
width != oldWidget.width;
}
class ResizableSidePanel extends StatefulWidget {
static const double minWidth = 150;
static const double maxWidth = 300;
final String optionKey;
final double defaultWidth;
final Widget child;
const ResizableSidePanel({
Key? key,
required this.optionKey,
required this.defaultWidth,
required this.child,
}) : super(key: key);
@override
State<ResizableSidePanel> createState() => _ResizableSidePanelState();
}
class _ResizableSidePanelState extends State<ResizableSidePanel> {
late double _width;
double _cap = double.infinity;
@override
void initState() {
super.initState();
final saved =
double.tryParse(bind.mainGetLocalOption(key: widget.optionKey));
_width = _clamp(saved ?? widget.defaultWidth);
}
double _clamp(double w) =>
w.clamp(ResizableSidePanel.minWidth, ResizableSidePanel.maxWidth)
.toDouble();
void _persist() => bind.mainSetLocalOption(
key: widget.optionKey, value: _width.toStringAsFixed(0));
@override
Widget build(BuildContext context) {
final available = context
.dependOnInheritedWidgetOfExactType<_AvailableWidth>()
?.width;
final room = (available ?? double.infinity) - _kDividerWidth;
_cap = room.isFinite
? max(
0.0,
max(room - _kPeerCardWidth,
min(ResizableSidePanel.minWidth, room - _kMinContentWidth)))
: double.infinity;
final sign = Directionality.of(context) == TextDirection.rtl ? -1.0 : 1.0;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(width: min(_width, _cap), child: widget.child),
MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onHorizontalDragUpdate: (details) => setState(() => _width =
_clamp(min(_width, _cap) + sign * details.delta.dx)),
onHorizontalDragEnd: (_) => _persist(),
onHorizontalDragCancel: _persist,
child:
const SizedBox(width: _kDividerWidth, height: double.infinity),
),
),
],
);
}
}
extension ResizableSidePanelExt on Widget {
Widget resizable(String optionKey, {required double defaultWidth}) =>
ResizableSidePanel(
optionKey: optionKey, defaultWidth: defaultWidth, child: this);
}
+3
View File
@@ -163,6 +163,9 @@ const String kOptionRemoteMenubarFraction = "remote-menubar-frac";
const String kOptionAllowMultiEdgeToolbarDock =
"allow-multi-edge-toolbar-dock";
const String kOptionHideAbTagsPanel = "hideAbTagsPanel";
const String kOptionAbTagsPanelWidth = "ab-tags-panel-width";
const String kOptionAccessibleDevicesPanelWidth =
"accessible-devices-panel-width";
const String kOptionRemoteMenubarState = "remoteMenubarState";
const String kOptionPeerSorting = "peer-sorting";
const String kOptionPeerTabIndex = "peer-tab-index";