cm tabs add tooltips and selected color

This commit is contained in:
csf 2022-10-20 23:56:23 +09:00
parent 6e6a359809
commit ee744d7de3
2 changed files with 71 additions and 36 deletions
flutter/lib/desktop

@ -126,6 +126,20 @@ class ConnectionManagerState extends State<ConnectionManager> {
controller: serverModel.tabController, controller: serverModel.tabController,
maxLabelWidth: 100, maxLabelWidth: 100,
tail: buildScrollJumper(), tail: buildScrollJumper(),
selectedTabBackgroundColor:
Theme.of(context).hintColor.withOpacity(0.2),
tabBuilder: (key, icon, label, themeConf) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
icon,
Tooltip(
message: key,
waitDuration: Duration(seconds: 1),
child: label),
],
);
},
pageViewBuilder: (pageView) => Row(children: [ pageViewBuilder: (pageView) => Row(children: [
Expanded(child: pageView), Expanded(child: pageView),
Consumer<ChatModel>( Consumer<ChatModel>(

@ -178,6 +178,9 @@ typedef TabBuilder = Widget Function(
String key, Widget icon, Widget label, TabThemeConf themeConf); String key, Widget icon, Widget label, TabThemeConf themeConf);
typedef LabelGetter = Rx<String> Function(String key); typedef LabelGetter = Rx<String> Function(String key);
/// [_lastClickTime], help to handle double click
int _lastClickTime = DateTime.now().millisecondsSinceEpoch;
class DesktopTab extends StatelessWidget { class DesktopTab extends StatelessWidget {
final Function(String)? onTabClose; final Function(String)? onTabClose;
final bool showTabBar; final bool showTabBar;
@ -192,15 +195,14 @@ class DesktopTab extends StatelessWidget {
final TabBuilder? tabBuilder; final TabBuilder? tabBuilder;
final LabelGetter? labelGetter; final LabelGetter? labelGetter;
final double? maxLabelWidth; final double? maxLabelWidth;
final Color? selectedTabBackgroundColor;
final Color? unSelectedTabBackgroundColor;
final DesktopTabController controller; final DesktopTabController controller;
Rx<DesktopTabState> get state => controller.state; Rx<DesktopTabState> get state => controller.state;
final isMaximized = false.obs; final isMaximized = false.obs;
final _scrollDebounce = Debouncer(delay: Duration(milliseconds: 50)); final _scrollDebounce = Debouncer(delay: Duration(milliseconds: 50));
/// [_lastClickTime], help to handle double click
int _lastClickTime = DateTime.now().millisecondsSinceEpoch;
late final DesktopTabType tabType; late final DesktopTabType tabType;
late final bool isMainWindow; late final bool isMainWindow;
@ -220,6 +222,8 @@ class DesktopTab extends StatelessWidget {
this.tabBuilder, this.tabBuilder,
this.labelGetter, this.labelGetter,
this.maxLabelWidth, this.maxLabelWidth,
this.selectedTabBackgroundColor,
this.unSelectedTabBackgroundColor,
}) : super(key: key) { }) : super(key: key) {
tabType = controller.tabType; tabType = controller.tabType;
isMainWindow = isMainWindow =
@ -364,7 +368,11 @@ class DesktopTab extends StatelessWidget {
onTabClose: onTabClose, onTabClose: onTabClose,
tabBuilder: tabBuilder, tabBuilder: tabBuilder,
labelGetter: labelGetter, labelGetter: labelGetter,
maxLabelWidth: maxLabelWidth))), maxLabelWidth: maxLabelWidth,
selectedTabBackgroundColor:
selectedTabBackgroundColor,
unSelectedTabBackgroundColor:
unSelectedTabBackgroundColor))),
], ],
))), ))),
WindowActionPanel( WindowActionPanel(
@ -617,6 +625,8 @@ class _ListView extends StatelessWidget {
final TabBuilder? tabBuilder; final TabBuilder? tabBuilder;
final LabelGetter? labelGetter; final LabelGetter? labelGetter;
final double? maxLabelWidth; final double? maxLabelWidth;
final Color? selectedTabBackgroundColor;
final Color? unSelectedTabBackgroundColor;
Rx<DesktopTabState> get state => controller.state; Rx<DesktopTabState> get state => controller.state;
@ -625,7 +635,9 @@ class _ListView extends StatelessWidget {
required this.onTabClose, required this.onTabClose,
this.tabBuilder, this.tabBuilder,
this.labelGetter, this.labelGetter,
this.maxLabelWidth}); this.maxLabelWidth,
this.selectedTabBackgroundColor,
this.unSelectedTabBackgroundColor});
/// Check whether to show ListView /// Check whether to show ListView
/// ///
@ -667,7 +679,7 @@ class _ListView extends StatelessWidget {
onSelected: () => controller.jumpTo(index), onSelected: () => controller.jumpTo(index),
tabBuilder: tabBuilder == null tabBuilder: tabBuilder == null
? null ? null
: (Widget icon, Widget labelWidget, : (String key, Widget icon, Widget labelWidget,
TabThemeConf themeConf) { TabThemeConf themeConf) {
return tabBuilder!( return tabBuilder!(
tab.label, tab.label,
@ -677,6 +689,8 @@ class _ListView extends StatelessWidget {
); );
}, },
maxLabelWidth: maxLabelWidth, maxLabelWidth: maxLabelWidth,
selectedTabBackgroundColor: selectedTabBackgroundColor,
unSelectedTabBackgroundColor: unSelectedTabBackgroundColor,
); );
}).toList())); }).toList()));
} }
@ -691,9 +705,10 @@ class _Tab extends StatefulWidget {
final int selected; final int selected;
final Function() onClose; final Function() onClose;
final Function() onSelected; final Function() onSelected;
final Widget Function(Widget icon, Widget label, TabThemeConf themeConf)? final TabBuilder? tabBuilder;
tabBuilder;
final double? maxLabelWidth; final double? maxLabelWidth;
final Color? selectedTabBackgroundColor;
final Color? unSelectedTabBackgroundColor;
const _Tab({ const _Tab({
Key? key, Key? key,
@ -707,6 +722,8 @@ class _Tab extends StatefulWidget {
required this.onClose, required this.onClose,
required this.onSelected, required this.onSelected,
this.maxLabelWidth, this.maxLabelWidth,
this.selectedTabBackgroundColor,
this.unSelectedTabBackgroundColor,
}) : super(key: key); }) : super(key: key);
@override @override
@ -753,8 +770,8 @@ class _TabState extends State<_Tab> with RestorationMixin {
], ],
); );
} else { } else {
return widget.tabBuilder!( return widget.tabBuilder!(widget.label.value, icon, labelWidget,
icon, labelWidget, TabThemeConf(iconSize: _kIconSize)); TabThemeConf(iconSize: _kIconSize));
} }
} }
@ -771,32 +788,36 @@ class _TabState extends State<_Tab> with RestorationMixin {
restoreHover.value = value; restoreHover.value = value;
}, },
onTap: () => widget.onSelected(), onTap: () => widget.onSelected(),
child: Row( child: Container(
children: [ color: isSelected
SizedBox( ? widget.selectedTabBackgroundColor
height: _kTabBarHeight, : widget.unSelectedTabBackgroundColor,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ SizedBox(
_buildTabContent(), height: _kTabBarHeight,
Obx((() => _CloseButton( child: Row(
visiable: hover.value && widget.closable, crossAxisAlignment: CrossAxisAlignment.center,
tabSelected: isSelected, children: [
onClose: () => widget.onClose(), _buildTabContent(),
))) Obx((() => _CloseButton(
])).paddingSymmetric(horizontal: 10), visiable: hover.value && widget.closable,
Offstage( tabSelected: isSelected,
offstage: !showDivider, onClose: () => widget.onClose(),
child: VerticalDivider( )))
width: 1, ])).paddingSymmetric(horizontal: 10),
indent: _kDividerIndent, Offstage(
endIndent: _kDividerIndent, offstage: !showDivider,
color: MyTheme.tabbar(context).dividerColor, child: VerticalDivider(
thickness: 1, width: 1,
), indent: _kDividerIndent,
) endIndent: _kDividerIndent,
], color: MyTheme.tabbar(context).dividerColor,
), thickness: 1,
),
)
],
)),
), ),
); );
} }