2022-08-06 17:08:48 +08:00
|
|
|
import 'dart:math';
|
|
|
|
|
2022-08-18 11:07:53 +08:00
|
|
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
2022-08-06 17:08:48 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hbb/common.dart';
|
|
|
|
import 'package:flutter_hbb/consts.dart';
|
2022-08-18 11:07:53 +08:00
|
|
|
import 'package:flutter_hbb/main.dart';
|
2022-08-09 09:01:06 +08:00
|
|
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
2022-08-06 17:08:48 +08:00
|
|
|
import 'package:get/get.dart';
|
2022-08-18 11:07:53 +08:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2022-08-18 10:54:09 +08:00
|
|
|
import 'package:scroll_pos/scroll_pos.dart';
|
2022-08-06 17:08:48 +08:00
|
|
|
|
|
|
|
const double _kTabBarHeight = kDesktopRemoteTabBarHeight;
|
|
|
|
const double _kIconSize = 18;
|
|
|
|
const double _kDividerIndent = 10;
|
2022-08-20 19:57:16 +08:00
|
|
|
const double _kActionIconSize = 12;
|
2022-08-06 17:08:48 +08:00
|
|
|
|
2022-08-11 16:03:04 +08:00
|
|
|
class TabInfo {
|
2022-08-22 20:18:31 +08:00
|
|
|
late final String key;
|
2022-08-11 16:03:04 +08:00
|
|
|
late final String label;
|
2022-08-22 20:18:31 +08:00
|
|
|
late final IconData? selectedIcon;
|
|
|
|
late final IconData? unselectedIcon;
|
2022-08-11 16:03:04 +08:00
|
|
|
late final bool closable;
|
|
|
|
|
2022-08-18 10:54:09 +08:00
|
|
|
TabInfo(
|
2022-08-22 20:18:31 +08:00
|
|
|
{required this.key,
|
|
|
|
required this.label,
|
|
|
|
this.selectedIcon,
|
|
|
|
this.unselectedIcon,
|
2022-08-18 10:54:09 +08:00
|
|
|
this.closable = true});
|
2022-08-11 16:03:04 +08:00
|
|
|
}
|
|
|
|
|
2022-08-06 17:08:48 +08:00
|
|
|
class DesktopTabBar extends StatelessWidget {
|
2022-08-11 18:08:35 +08:00
|
|
|
late final RxList<TabInfo> tabs;
|
2022-08-18 10:54:09 +08:00
|
|
|
late final Function(String)? onTabClose;
|
2022-08-09 22:35:29 +08:00
|
|
|
late final bool dark;
|
|
|
|
late final _Theme _theme;
|
2022-08-11 16:03:04 +08:00
|
|
|
late final bool mainTab;
|
2022-08-22 20:18:31 +08:00
|
|
|
late final bool showLogo;
|
|
|
|
late final bool showTitle;
|
|
|
|
late final bool showMinimize;
|
|
|
|
late final bool showMaximize;
|
|
|
|
late final bool showClose;
|
|
|
|
late final void Function()? onAddSetting;
|
|
|
|
late final void Function(int)? onSelected;
|
2022-08-18 10:54:09 +08:00
|
|
|
final ScrollPosController scrollController =
|
|
|
|
ScrollPosController(itemCount: 0);
|
|
|
|
static final Rx<PageController> controller = PageController().obs;
|
|
|
|
static final Rx<int> selected = 0.obs;
|
2022-08-22 20:18:31 +08:00
|
|
|
static final _tabBarListViewKey = GlobalKey();
|
2022-08-06 17:08:48 +08:00
|
|
|
|
2022-08-22 20:18:31 +08:00
|
|
|
DesktopTabBar(
|
|
|
|
{Key? key,
|
|
|
|
required this.tabs,
|
|
|
|
this.onTabClose,
|
|
|
|
required this.dark,
|
|
|
|
required this.mainTab,
|
|
|
|
this.onAddSetting,
|
|
|
|
this.onSelected,
|
|
|
|
this.showLogo = true,
|
|
|
|
this.showTitle = true,
|
|
|
|
this.showMinimize = true,
|
|
|
|
this.showMaximize = true,
|
|
|
|
this.showClose = true})
|
|
|
|
: _theme = dark ? _Theme.dark() : _Theme.light(),
|
2022-08-18 10:54:09 +08:00
|
|
|
super(key: key) {
|
|
|
|
scrollController.itemCount = tabs.length;
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
scrollController.scrollToItem(selected.value,
|
|
|
|
center: true, animate: true);
|
|
|
|
});
|
|
|
|
}
|
2022-08-06 17:08:48 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: _kTabBarHeight,
|
2022-08-20 19:57:16 +08:00
|
|
|
child: Column(
|
2022-08-11 16:03:04 +08:00
|
|
|
children: [
|
2022-08-20 19:57:16 +08:00
|
|
|
Container(
|
|
|
|
height: _kTabBarHeight - 1,
|
2022-08-11 16:03:04 +08:00
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-08-18 11:07:53 +08:00
|
|
|
Expanded(
|
2022-08-20 19:57:16 +08:00
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-08-22 20:18:31 +08:00
|
|
|
Row(children: [
|
|
|
|
Offstage(
|
|
|
|
offstage: !showLogo,
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/logo.ico',
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
)),
|
|
|
|
Offstage(
|
|
|
|
offstage: !showTitle,
|
|
|
|
child: Text(
|
|
|
|
"RustDesk",
|
|
|
|
style: TextStyle(fontSize: 13),
|
|
|
|
).marginOnly(left: 2))
|
|
|
|
]).marginOnly(
|
|
|
|
left: 5,
|
|
|
|
right: 10,
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: GestureDetector(
|
|
|
|
onPanStart: (_) {
|
|
|
|
if (mainTab) {
|
|
|
|
windowManager.startDragging();
|
|
|
|
} else {
|
|
|
|
WindowController.fromWindowId(windowId!)
|
|
|
|
.startDragging();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: _ListView(
|
2022-08-22 20:18:31 +08:00
|
|
|
key: _tabBarListViewKey,
|
2022-08-20 19:57:16 +08:00
|
|
|
controller: controller,
|
|
|
|
scrollController: scrollController,
|
|
|
|
tabInfos: tabs,
|
|
|
|
selected: selected,
|
|
|
|
onTabClose: onTabClose,
|
2022-08-22 20:18:31 +08:00
|
|
|
theme: _theme,
|
|
|
|
onSelected: onSelected)),
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: mainTab,
|
|
|
|
child: _AddButton(
|
|
|
|
theme: _theme,
|
|
|
|
).paddingOnly(left: 10),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-08-11 16:03:04 +08:00
|
|
|
),
|
|
|
|
Offstage(
|
2022-08-20 19:57:16 +08:00
|
|
|
offstage: onAddSetting == null,
|
|
|
|
child: _ActionIcon(
|
|
|
|
message: 'Settings',
|
|
|
|
icon: IconFont.menu,
|
2022-08-11 16:03:04 +08:00
|
|
|
theme: _theme,
|
2022-08-20 19:57:16 +08:00
|
|
|
onTap: () => onAddSetting?.call(),
|
|
|
|
is_close: false,
|
|
|
|
),
|
2022-08-18 10:54:09 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
WindowActionPanel(
|
|
|
|
mainTab: mainTab,
|
|
|
|
theme: _theme,
|
2022-08-22 20:18:31 +08:00
|
|
|
showMinimize: showMinimize,
|
|
|
|
showMaximize: showMaximize,
|
|
|
|
showClose: showClose,
|
2022-08-20 19:57:16 +08:00
|
|
|
)
|
2022-08-11 16:03:04 +08:00
|
|
|
],
|
2022-08-09 22:35:29 +08:00
|
|
|
),
|
2022-08-11 16:03:04 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
Divider(
|
|
|
|
height: 1,
|
|
|
|
thickness: 1,
|
2022-08-18 11:07:53 +08:00
|
|
|
),
|
2022-08-11 16:03:04 +08:00
|
|
|
],
|
2022-08-06 17:08:48 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-08-11 18:08:35 +08:00
|
|
|
|
2022-08-18 10:54:09 +08:00
|
|
|
static onAdd(RxList<TabInfo> tabs, TabInfo tab) {
|
2022-08-23 15:25:18 +08:00
|
|
|
if (!isDesktop) return;
|
2022-08-22 20:18:31 +08:00
|
|
|
int index = tabs.indexWhere((e) => e.key == tab.key);
|
2022-08-11 18:08:35 +08:00
|
|
|
if (index >= 0) {
|
|
|
|
selected.value = index;
|
|
|
|
} else {
|
|
|
|
tabs.add(tab);
|
|
|
|
selected.value = tabs.length - 1;
|
2022-08-18 10:54:09 +08:00
|
|
|
assert(selected.value >= 0);
|
2022-08-11 18:08:35 +08:00
|
|
|
}
|
2022-08-22 20:18:31 +08:00
|
|
|
try {
|
|
|
|
controller.value.jumpToPage(selected.value);
|
|
|
|
} catch (e) {
|
|
|
|
// call before binding controller will throw
|
|
|
|
debugPrint("Failed to jumpToPage: $e");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static remove(RxList<TabInfo> tabs, int index) {
|
2022-08-23 15:25:18 +08:00
|
|
|
if (!isDesktop) return;
|
2022-08-22 20:18:31 +08:00
|
|
|
if (index < 0) return;
|
|
|
|
if (index == tabs.length - 1) {
|
|
|
|
selected.value = max(0, selected.value - 1);
|
|
|
|
} else if (index < tabs.length - 1 && index < selected.value) {
|
|
|
|
selected.value = max(0, selected.value - 1);
|
|
|
|
}
|
|
|
|
tabs.removeAt(index);
|
|
|
|
controller.value.jumpToPage(selected.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jumpTo(RxList<TabInfo> tabs, int index) {
|
2022-08-23 15:25:18 +08:00
|
|
|
if (!isDesktop) return;
|
2022-08-22 20:18:31 +08:00
|
|
|
if (index < 0 || index >= tabs.length) return;
|
|
|
|
selected.value = index;
|
2022-08-18 10:54:09 +08:00
|
|
|
controller.value.jumpToPage(selected.value);
|
2022-08-11 18:08:35 +08:00
|
|
|
}
|
2022-08-22 20:18:31 +08:00
|
|
|
|
|
|
|
static void close(String? key) {
|
2022-08-23 15:25:18 +08:00
|
|
|
if (!isDesktop) return;
|
2022-08-22 20:18:31 +08:00
|
|
|
final tabBar = _tabBarListViewKey.currentWidget as _ListView?;
|
|
|
|
if (tabBar == null) return;
|
|
|
|
final tabs = tabBar.tabs;
|
|
|
|
if (key == null) {
|
|
|
|
if (tabBar.selected.value < tabs.length) {
|
|
|
|
tabs[tabBar.selected.value].onClose();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (final tab in tabs) {
|
|
|
|
if (tab.key == key) {
|
|
|
|
tab.onClose();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-06 17:08:48 +08:00
|
|
|
}
|
|
|
|
|
2022-08-18 11:07:53 +08:00
|
|
|
class WindowActionPanel extends StatelessWidget {
|
|
|
|
final bool mainTab;
|
2022-08-20 19:57:16 +08:00
|
|
|
final _Theme theme;
|
2022-08-18 11:07:53 +08:00
|
|
|
|
2022-08-22 20:18:31 +08:00
|
|
|
final bool showMinimize;
|
|
|
|
final bool showMaximize;
|
|
|
|
final bool showClose;
|
|
|
|
|
2022-08-18 11:07:53 +08:00
|
|
|
const WindowActionPanel(
|
2022-08-22 20:18:31 +08:00
|
|
|
{Key? key,
|
|
|
|
required this.mainTab,
|
|
|
|
required this.theme,
|
|
|
|
this.showMinimize = true,
|
|
|
|
this.showMaximize = true,
|
|
|
|
this.showClose = true})
|
2022-08-18 11:07:53 +08:00
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
2022-08-22 20:18:31 +08:00
|
|
|
Offstage(
|
|
|
|
offstage: !showMinimize,
|
|
|
|
child: _ActionIcon(
|
|
|
|
message: 'Minimize',
|
|
|
|
icon: IconFont.min,
|
2022-08-20 19:57:16 +08:00
|
|
|
theme: theme,
|
|
|
|
onTap: () {
|
|
|
|
if (mainTab) {
|
2022-08-22 20:18:31 +08:00
|
|
|
windowManager.minimize();
|
2022-08-20 19:57:16 +08:00
|
|
|
} else {
|
2022-08-22 20:18:31 +08:00
|
|
|
WindowController.fromWindowId(windowId!).minimize();
|
2022-08-20 19:57:16 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
is_close: false,
|
2022-08-22 20:18:31 +08:00
|
|
|
)),
|
2022-08-22 17:58:48 +08:00
|
|
|
// TODO: drag makes window restore
|
2022-08-22 20:18:31 +08:00
|
|
|
Offstage(
|
|
|
|
offstage: !showMaximize,
|
|
|
|
child: FutureBuilder(builder: (context, snapshot) {
|
|
|
|
RxBool is_maximized = false.obs;
|
|
|
|
if (mainTab) {
|
|
|
|
windowManager.isMaximized().then((maximized) {
|
|
|
|
is_maximized.value = maximized;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
final wc = WindowController.fromWindowId(windowId!);
|
|
|
|
wc.isMaximized().then((maximized) {
|
|
|
|
is_maximized.value = maximized;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Obx(
|
|
|
|
() => _ActionIcon(
|
|
|
|
message: is_maximized.value ? "Restore" : "Maximize",
|
|
|
|
icon: is_maximized.value ? IconFont.restore : IconFont.max,
|
|
|
|
theme: theme,
|
|
|
|
onTap: () {
|
|
|
|
if (mainTab) {
|
|
|
|
if (is_maximized.value) {
|
|
|
|
windowManager.unmaximize();
|
|
|
|
} else {
|
2022-08-22 17:58:48 +08:00
|
|
|
windowManager.maximize();
|
2022-08-22 20:18:31 +08:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-22 17:58:48 +08:00
|
|
|
// TODO: subwindow is maximized but first query result is not maximized.
|
2022-08-22 20:18:31 +08:00
|
|
|
final wc = WindowController.fromWindowId(windowId!);
|
|
|
|
if (is_maximized.value) {
|
|
|
|
wc.unmaximize();
|
|
|
|
} else {
|
2022-08-22 17:58:48 +08:00
|
|
|
wc.maximize();
|
2022-08-22 20:18:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
is_maximized.value = !is_maximized.value;
|
|
|
|
},
|
|
|
|
is_close: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
})),
|
|
|
|
Offstage(
|
|
|
|
offstage: !showClose,
|
|
|
|
child: _ActionIcon(
|
|
|
|
message: 'Close',
|
|
|
|
icon: IconFont.close,
|
|
|
|
theme: theme,
|
|
|
|
onTap: () {
|
|
|
|
if (mainTab) {
|
|
|
|
windowManager.close();
|
|
|
|
} else {
|
|
|
|
WindowController.fromWindowId(windowId!).close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
is_close: true,
|
|
|
|
)),
|
2022-08-18 11:07:53 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-20 19:57:16 +08:00
|
|
|
// ignore: must_be_immutable
|
2022-08-18 10:54:09 +08:00
|
|
|
class _ListView extends StatelessWidget {
|
2022-08-20 19:57:16 +08:00
|
|
|
final Rx<PageController> controller;
|
2022-08-18 10:54:09 +08:00
|
|
|
final ScrollPosController scrollController;
|
|
|
|
final RxList<TabInfo> tabInfos;
|
|
|
|
final Rx<int> selected;
|
2022-08-22 20:18:31 +08:00
|
|
|
final Function(String key)? onTabClose;
|
2022-08-18 10:54:09 +08:00
|
|
|
final _Theme _theme;
|
|
|
|
late List<_Tab> tabs;
|
2022-08-22 20:18:31 +08:00
|
|
|
late final void Function(int)? onSelected;
|
2022-08-18 10:54:09 +08:00
|
|
|
|
2022-08-22 20:18:31 +08:00
|
|
|
_ListView(
|
|
|
|
{Key? key,
|
|
|
|
required this.controller,
|
|
|
|
required this.scrollController,
|
|
|
|
required this.tabInfos,
|
|
|
|
required this.selected,
|
|
|
|
required this.onTabClose,
|
|
|
|
required _Theme theme,
|
|
|
|
this.onSelected})
|
|
|
|
: _theme = theme,
|
2022-08-18 10:54:09 +08:00
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Obx(() {
|
|
|
|
tabs = tabInfos.asMap().entries.map((e) {
|
|
|
|
int index = e.key;
|
|
|
|
return _Tab(
|
|
|
|
index: index,
|
2022-08-22 20:18:31 +08:00
|
|
|
label: e.value.label,
|
2022-08-18 10:54:09 +08:00
|
|
|
selectedIcon: e.value.selectedIcon,
|
|
|
|
unselectedIcon: e.value.unselectedIcon,
|
|
|
|
closable: e.value.closable,
|
|
|
|
selected: selected.value,
|
|
|
|
onClose: () {
|
2022-08-22 20:18:31 +08:00
|
|
|
tabInfos.removeWhere((tab) => tab.key == e.value.key);
|
|
|
|
onTabClose?.call(e.value.key);
|
2022-08-18 10:54:09 +08:00
|
|
|
if (index <= selected.value) {
|
|
|
|
selected.value = max(0, selected.value - 1);
|
|
|
|
}
|
|
|
|
assert(tabInfos.length == 0 || selected.value < tabInfos.length);
|
|
|
|
scrollController.itemCount = tabInfos.length;
|
|
|
|
if (tabInfos.length > 0) {
|
|
|
|
scrollController.scrollToItem(selected.value,
|
|
|
|
center: true, animate: true);
|
|
|
|
controller.value.jumpToPage(selected.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onSelected: () {
|
|
|
|
selected.value = index;
|
|
|
|
scrollController.scrollToItem(index, center: true, animate: true);
|
|
|
|
controller.value.jumpToPage(index);
|
2022-08-22 20:18:31 +08:00
|
|
|
onSelected?.call(selected.value);
|
2022-08-18 10:54:09 +08:00
|
|
|
},
|
|
|
|
theme: _theme,
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
return ListView(
|
|
|
|
controller: scrollController,
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
children: tabs);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-06 17:08:48 +08:00
|
|
|
class _Tab extends StatelessWidget {
|
|
|
|
late final int index;
|
2022-08-11 16:03:04 +08:00
|
|
|
late final String label;
|
2022-08-22 20:18:31 +08:00
|
|
|
late final IconData? selectedIcon;
|
|
|
|
late final IconData? unselectedIcon;
|
2022-08-11 16:03:04 +08:00
|
|
|
late final bool closable;
|
2022-08-06 17:08:48 +08:00
|
|
|
late final int selected;
|
|
|
|
late final Function() onClose;
|
|
|
|
late final Function() onSelected;
|
|
|
|
final RxBool _hover = false.obs;
|
2022-08-09 22:35:29 +08:00
|
|
|
late final _Theme theme;
|
2022-08-06 17:08:48 +08:00
|
|
|
|
2022-08-09 22:35:29 +08:00
|
|
|
_Tab(
|
|
|
|
{Key? key,
|
|
|
|
required this.index,
|
2022-08-11 16:03:04 +08:00
|
|
|
required this.label,
|
2022-08-22 20:18:31 +08:00
|
|
|
this.selectedIcon,
|
|
|
|
this.unselectedIcon,
|
2022-08-11 16:03:04 +08:00
|
|
|
required this.closable,
|
2022-08-09 22:35:29 +08:00
|
|
|
required this.selected,
|
|
|
|
required this.onClose,
|
|
|
|
required this.onSelected,
|
|
|
|
required this.theme})
|
|
|
|
: super(key: key);
|
2022-08-06 17:08:48 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-22 20:18:31 +08:00
|
|
|
bool show_icon = selectedIcon != null && unselectedIcon != null;
|
2022-08-06 17:08:48 +08:00
|
|
|
bool is_selected = index == selected;
|
|
|
|
bool show_divider = index != selected - 1 && index != selected;
|
2022-08-20 19:57:16 +08:00
|
|
|
return Ink(
|
|
|
|
child: InkWell(
|
|
|
|
onHover: (hover) => _hover.value = hover,
|
|
|
|
onTap: () => onSelected(),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
height: _kTabBarHeight,
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2022-08-18 10:54:09 +08:00
|
|
|
children: [
|
2022-08-22 20:18:31 +08:00
|
|
|
Offstage(
|
|
|
|
offstage: !show_icon,
|
|
|
|
child: Icon(
|
|
|
|
is_selected ? selectedIcon : unselectedIcon,
|
|
|
|
size: _kIconSize,
|
|
|
|
color: is_selected
|
|
|
|
? theme.selectedtabIconColor
|
|
|
|
: theme.unSelectedtabIconColor,
|
|
|
|
).paddingOnly(right: 5)),
|
2022-08-20 19:57:16 +08:00
|
|
|
Text(
|
|
|
|
translate(label),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
2022-08-18 10:54:09 +08:00
|
|
|
color: is_selected
|
2022-08-20 19:57:16 +08:00
|
|
|
? theme.selectedTextColor
|
|
|
|
: theme.unSelectedTextColor),
|
2022-08-18 10:54:09 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: !closable,
|
|
|
|
child: Obx((() => _CloseButton(
|
|
|
|
visiable: _hover.value,
|
|
|
|
tabSelected: is_selected,
|
|
|
|
onClose: () => onClose(),
|
|
|
|
theme: theme,
|
|
|
|
))),
|
|
|
|
)
|
|
|
|
])).paddingSymmetric(horizontal: 10),
|
|
|
|
Offstage(
|
|
|
|
offstage: !show_divider,
|
|
|
|
child: VerticalDivider(
|
|
|
|
width: 1,
|
|
|
|
indent: _kDividerIndent,
|
|
|
|
endIndent: _kDividerIndent,
|
|
|
|
color: theme.dividerColor,
|
|
|
|
thickness: 1,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2022-08-10 16:40:04 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
2022-08-06 17:08:48 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddButton extends StatelessWidget {
|
2022-08-09 22:35:29 +08:00
|
|
|
late final _Theme theme;
|
2022-08-06 17:08:48 +08:00
|
|
|
|
|
|
|
_AddButton({
|
|
|
|
Key? key,
|
2022-08-09 22:35:29 +08:00
|
|
|
required this.theme,
|
2022-08-06 17:08:48 +08:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-20 19:57:16 +08:00
|
|
|
return _ActionIcon(
|
|
|
|
message: 'New Connection',
|
|
|
|
icon: IconFont.add,
|
|
|
|
theme: theme,
|
2022-08-10 16:40:04 +08:00
|
|
|
onTap: () =>
|
|
|
|
rustDeskWinManager.call(WindowType.Main, "main_window_on_top", ""),
|
2022-08-20 19:57:16 +08:00
|
|
|
is_close: false);
|
2022-08-06 17:08:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CloseButton extends StatelessWidget {
|
2022-08-11 16:03:04 +08:00
|
|
|
final bool visiable;
|
2022-08-09 22:35:29 +08:00
|
|
|
final bool tabSelected;
|
2022-08-06 17:08:48 +08:00
|
|
|
final Function onClose;
|
2022-08-09 22:35:29 +08:00
|
|
|
late final _Theme theme;
|
2022-08-06 17:08:48 +08:00
|
|
|
|
|
|
|
_CloseButton({
|
|
|
|
Key? key,
|
2022-08-11 16:03:04 +08:00
|
|
|
required this.visiable,
|
2022-08-09 22:35:29 +08:00
|
|
|
required this.tabSelected,
|
2022-08-06 17:08:48 +08:00
|
|
|
required this.onClose,
|
2022-08-09 22:35:29 +08:00
|
|
|
required this.theme,
|
2022-08-06 17:08:48 +08:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-11 16:03:04 +08:00
|
|
|
return SizedBox(
|
|
|
|
width: _kIconSize,
|
|
|
|
child: Offstage(
|
|
|
|
offstage: !visiable,
|
|
|
|
child: InkWell(
|
|
|
|
customBorder: RoundedRectangleBorder(),
|
|
|
|
onTap: () => onClose(),
|
|
|
|
child: Icon(
|
|
|
|
Icons.close,
|
|
|
|
size: _kIconSize,
|
|
|
|
color: tabSelected
|
|
|
|
? theme.selectedIconColor
|
|
|
|
: theme.unSelectedIconColor,
|
|
|
|
),
|
|
|
|
),
|
2022-08-11 21:29:43 +08:00
|
|
|
)).paddingOnly(left: 5);
|
2022-08-06 17:08:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-20 19:57:16 +08:00
|
|
|
class _ActionIcon extends StatelessWidget {
|
|
|
|
final String message;
|
|
|
|
final IconData icon;
|
|
|
|
final _Theme theme;
|
|
|
|
final Function() onTap;
|
|
|
|
final bool is_close;
|
|
|
|
const _ActionIcon({
|
|
|
|
Key? key,
|
|
|
|
required this.message,
|
|
|
|
required this.icon,
|
|
|
|
required this.theme,
|
|
|
|
required this.onTap,
|
|
|
|
required this.is_close,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
RxBool hover = false.obs;
|
|
|
|
return Obx(() => Tooltip(
|
|
|
|
message: translate(message),
|
|
|
|
child: InkWell(
|
|
|
|
hoverColor: is_close ? Colors.red : theme.hoverColor,
|
|
|
|
onHover: (value) => hover.value = value,
|
|
|
|
child: Container(
|
|
|
|
height: _kTabBarHeight - 1,
|
|
|
|
width: _kTabBarHeight - 1,
|
|
|
|
child: Icon(
|
|
|
|
icon,
|
|
|
|
color: hover.value && is_close
|
|
|
|
? Colors.white
|
|
|
|
: theme.unSelectedIconColor,
|
|
|
|
size: _kActionIconSize,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: onTap,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-09 22:35:29 +08:00
|
|
|
class _Theme {
|
2022-08-11 16:03:04 +08:00
|
|
|
late Color unSelectedtabIconColor;
|
|
|
|
late Color selectedtabIconColor;
|
2022-08-09 22:35:29 +08:00
|
|
|
late Color selectedTextColor;
|
|
|
|
late Color unSelectedTextColor;
|
|
|
|
late Color selectedIconColor;
|
|
|
|
late Color unSelectedIconColor;
|
|
|
|
late Color dividerColor;
|
2022-08-20 19:57:16 +08:00
|
|
|
late Color hoverColor;
|
2022-08-09 22:35:29 +08:00
|
|
|
|
|
|
|
_Theme.light() {
|
2022-08-11 16:03:04 +08:00
|
|
|
unSelectedtabIconColor = Color.fromARGB(255, 162, 203, 241);
|
|
|
|
selectedtabIconColor = MyTheme.accent;
|
2022-08-09 22:35:29 +08:00
|
|
|
selectedTextColor = Color.fromARGB(255, 26, 26, 26);
|
|
|
|
unSelectedTextColor = Color.fromARGB(255, 96, 96, 96);
|
|
|
|
selectedIconColor = Color.fromARGB(255, 26, 26, 26);
|
|
|
|
unSelectedIconColor = Color.fromARGB(255, 96, 96, 96);
|
|
|
|
dividerColor = Color.fromARGB(255, 238, 238, 238);
|
2022-08-20 19:57:16 +08:00
|
|
|
hoverColor = Colors.grey.withOpacity(0.2);
|
2022-08-09 22:35:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_Theme.dark() {
|
2022-08-11 16:03:04 +08:00
|
|
|
unSelectedtabIconColor = Color.fromARGB(255, 30, 65, 98);
|
|
|
|
selectedtabIconColor = MyTheme.accent;
|
2022-08-09 22:35:29 +08:00
|
|
|
selectedTextColor = Color.fromARGB(255, 255, 255, 255);
|
|
|
|
unSelectedTextColor = Color.fromARGB(255, 207, 207, 207);
|
|
|
|
selectedIconColor = Color.fromARGB(255, 215, 215, 215);
|
|
|
|
unSelectedIconColor = Color.fromARGB(255, 255, 255, 255);
|
|
|
|
dividerColor = Color.fromARGB(255, 64, 64, 64);
|
2022-08-20 19:57:16 +08:00
|
|
|
hoverColor = Colors.black26;
|
2022-08-09 22:35:29 +08:00
|
|
|
}
|
|
|
|
}
|