flutter_desktop: menu bar, switch menu & shrink-stretch -> adaptive

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-08-31 16:41:05 +08:00
parent 027ffbb405
commit 59f0ffa82f
25 changed files with 81 additions and 66 deletions

View File

@ -315,29 +315,31 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
mod_menu.PopupMenuItem( mod_menu.PopupMenuItem(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
height: conf.height, height: conf.height,
child: Obx( child: TextButton(
() => SwitchListTile( child: Container(
value: curOption.value, alignment: AlignmentDirectional.centerStart,
onChanged: (v) { height: conf.height,
setOption(v); child: Row(children: [
}, // const SizedBox(width: MenuConfig.midPadding),
title: Container( Text(
alignment: AlignmentDirectional.centerStart,
constraints: BoxConstraints(minHeight: conf.height),
child: Text(
text, text,
style: const TextStyle( style: const TextStyle(
color: Colors.black, color: Colors.black,
fontSize: MenuConfig.fontSize, fontSize: MenuConfig.fontSize,
fontWeight: FontWeight.normal), fontWeight: FontWeight.normal),
)), ),
dense: true, Expanded(
visualDensity: const VisualDensity( child: Align(
horizontal: VisualDensity.minimumDensity, alignment: Alignment.centerRight,
vertical: VisualDensity.minimumDensity, child: Obx(() => Switch(
), value: curOption.value,
contentPadding: const EdgeInsets.only(left: 8.0), onChanged: (v) => setOption(v),
), )),
))
])),
onPressed: () {
setOption(!curOption.value);
},
), ),
) )
]; ];

View File

@ -406,14 +406,13 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
MenuEntryRadios<String>( MenuEntryRadios<String>(
text: translate('Ratio'), text: translate('Ratio'),
optionsGetter: () => [ optionsGetter: () => [
Tuple2<String, String>(translate('Original'), 'original'), Tuple2<String, String>(translate('Scale original'), 'original'),
Tuple2<String, String>(translate('Shrink'), 'shrink'), Tuple2<String, String>(translate('Scale adaptive'), 'adaptive'),
Tuple2<String, String>(translate('Stretch'), 'stretch'),
], ],
curOptionGetter: () async { curOptionGetter: () async {
return await bind.sessionGetOption( return await bind.sessionGetOption(
id: widget.id, arg: 'view-style') ?? id: widget.id, arg: 'view-style') ??
''; 'adaptive';
}, },
optionSetter: (String v) async { optionSetter: (String v) async {
await bind.sessionPeerOption( await bind.sessionPeerOption(

View File

@ -497,39 +497,11 @@ class CanvasModel with ChangeNotifier {
return; return;
} }
final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); _scale = 1.0;
final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); if (style == 'adaptive') {
final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720);
// Closure to perform shrink operation. final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280);
final shrinkOp = () { _scale = s1 < s2 ? s1 : s2;
final s = s1 < s2 ? s1 : s2;
if (s < 1) {
_scale = s;
}
};
// Closure to perform stretch operation.
final stretchOp = () {
final s = s1 < s2 ? s1 : s2;
if (s > 1) {
_scale = s;
}
};
// Closure to perform default operation(set the scale to 1.0).
final defaultOp = () {
_scale = 1.0;
};
// // On desktop, shrink is the default behavior.
// if (isDesktop) {
// shrinkOp();
// } else {
defaultOp();
// }
if (style == 'shrink') {
shrinkOp();
} else if (style == 'stretch') {
stretchOp();
} }
_x = (size.width - getDisplayWidth() * _scale) / 2; _x = (size.width - getDisplayWidth() * _scale) / 2;

View File

@ -30,7 +30,7 @@ class PlatformFFI {
String _dir = ''; String _dir = '';
String _homeDir = ''; String _homeDir = '';
F2? _translate; F2? _translate;
var _eventHandlers = Map<String, Map<String, HandleEvent>>(); final _eventHandlers = Map<String, Map<String, HandleEvent>>();
late RustdeskImpl _ffiBind; late RustdeskImpl _ffiBind;
late String _appType; late String _appType;
void Function(Map<String, dynamic>)? _eventCallback; void Function(Map<String, dynamic>)? _eventCallback;
@ -50,27 +50,27 @@ class PlatformFFI {
} }
bool registerEventHandler( bool registerEventHandler(
String event_name, String handler_name, HandleEvent handler) { String eventName, String handlerName, HandleEvent handler) {
debugPrint('registerEventHandler $event_name $handler_name'); debugPrint('registerEventHandler $eventName $handlerName');
var handlers = _eventHandlers[event_name]; var handlers = _eventHandlers[eventName];
if (handlers == null) { if (handlers == null) {
_eventHandlers[event_name] = {handler_name: handler}; _eventHandlers[eventName] = {handlerName: handler};
return true; return true;
} else { } else {
if (handlers.containsKey(handler_name)) { if (handlers.containsKey(handlerName)) {
return false; return false;
} else { } else {
handlers[handler_name] = handler; handlers[handlerName] = handler;
return true; return true;
} }
} }
} }
void unregisterEventHandler(String event_name, String handler_name) { void unregisterEventHandler(String eventName, String handlerName) {
debugPrint('unregisterEventHandler $event_name $handler_name'); debugPrint('unregisterEventHandler $eventName $handlerName');
var handlers = _eventHandlers[event_name]; var handlers = _eventHandlers[eventName];
if (handlers != null) { if (handlers != null) {
handlers.remove(handler_name); handlers.remove(handlerName);
} }
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "中继连接"), ("Relay Connection", "中继连接"),
("Secure Connection", "安全连接"), ("Secure Connection", "安全连接"),
("Insecure Connection", "非安全连接"), ("Insecure Connection", "非安全连接"),
("Scale original", "原始尺寸"),
("Scale adaptive", "适应窗口"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Připojení relé"), ("Relay Connection", "Připojení relé"),
("Secure Connection", "Zabezpečené připojení"), ("Secure Connection", "Zabezpečené připojení"),
("Insecure Connection", "Nezabezpečené připojení"), ("Insecure Connection", "Nezabezpečené připojení"),
("Scale original", "Měřítko původní"),
("Scale adaptive", "Měřítko adaptivní"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Relæforbindelse"), ("Relay Connection", "Relæforbindelse"),
("Secure Connection", "Sikker forbindelse"), ("Secure Connection", "Sikker forbindelse"),
("Insecure Connection", "Usikker forbindelse"), ("Insecure Connection", "Usikker forbindelse"),
("Scale original", "Skala original"),
("Scale adaptive", "Skala adaptiv"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Relaisverbindung"), ("Relay Connection", "Relaisverbindung"),
("Secure Connection", "Sichere Verbindung"), ("Secure Connection", "Sichere Verbindung"),
("Insecure Connection", "Unsichere Verbindung"), ("Insecure Connection", "Unsichere Verbindung"),
("Scale original", "Original skalieren"),
("Scale adaptive", "Adaptiv skalieren"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Relajsa Konekto"), ("Relay Connection", "Relajsa Konekto"),
("Secure Connection", "Sekura Konekto"), ("Secure Connection", "Sekura Konekto"),
("Insecure Connection", "Nesekura Konekto"), ("Insecure Connection", "Nesekura Konekto"),
("Scale original", "Skalo originalo"),
("Scale adaptive", "Skalo adapta"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Conexión de relé"), ("Relay Connection", "Conexión de relé"),
("Secure Connection", "Conexión segura"), ("Secure Connection", "Conexión segura"),
("Insecure Connection", "Conexión insegura"), ("Insecure Connection", "Conexión insegura"),
("Scale original", "escala originales"),
("Scale adaptive", "Adaptable a escala"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Connexion relais"), ("Relay Connection", "Connexion relais"),
("Secure Connection", "Connexion sécurisée"), ("Secure Connection", "Connexion sécurisée"),
("Insecure Connection", "Connexion non sécurisée"), ("Insecure Connection", "Connexion non sécurisée"),
("Scale original", "Échelle d'origine"),
("Scale adaptive", "Échelle adaptative"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Relé csatlakozás"), ("Relay Connection", "Relé csatlakozás"),
("Secure Connection", "Biztonságos kapcsolat"), ("Secure Connection", "Biztonságos kapcsolat"),
("Insecure Connection", "Nem biztonságos kapcsolat"), ("Insecure Connection", "Nem biztonságos kapcsolat"),
("Scale original", "Eredeti méretarány"),
("Scale adaptive", "Skála adaptív"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Koneksi Relay"), ("Relay Connection", "Koneksi Relay"),
("Secure Connection", "Koneksi aman"), ("Secure Connection", "Koneksi aman"),
("Insecure Connection", "Koneksi Tidak Aman"), ("Insecure Connection", "Koneksi Tidak Aman"),
("Scale original", "Skala asli"),
("Scale adaptive", "Skala adaptif"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -316,5 +316,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Collegamento a relè"), ("Relay Connection", "Collegamento a relè"),
("Secure Connection", "Connessione sicura"), ("Secure Connection", "Connessione sicura"),
("Insecure Connection", "Connessione insicura"), ("Insecure Connection", "Connessione insicura"),
("Scale original", "Scala originale"),
("Scale adaptive", "Scala adattiva"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "リレー接続"), ("Relay Connection", "リレー接続"),
("Secure Connection", "安全な接続"), ("Secure Connection", "安全な接続"),
("Insecure Connection", "安全でない接続"), ("Insecure Connection", "安全でない接続"),
("Scale original", "オリジナルサイズ"),
("Scale adaptive", "フィットウィンドウ"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "릴레이 연결"), ("Relay Connection", "릴레이 연결"),
("Secure Connection", "보안 연결"), ("Secure Connection", "보안 연결"),
("Insecure Connection", "안전하지 않은 연결"), ("Insecure Connection", "안전하지 않은 연결"),
("Scale original", "원래 크기"),
("Scale adaptive", "맞는 창"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -318,5 +318,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Połączenie przekaźnika"), ("Relay Connection", "Połączenie przekaźnika"),
("Secure Connection", "Bezpieczne połączenie"), ("Secure Connection", "Bezpieczne połączenie"),
("Insecure Connection", "Niepewne połączenie"), ("Insecure Connection", "Niepewne połączenie"),
("Scale original", "Skala oryginalna"),
("Scale adaptive", "Skala adaptacyjna"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Conexão de relé"), ("Relay Connection", "Conexão de relé"),
("Secure Connection", "Conexão segura"), ("Secure Connection", "Conexão segura"),
("Insecure Connection", "Conexão insegura"), ("Insecure Connection", "Conexão insegura"),
("Scale original", "Escala original"),
("Scale adaptive", "Escala adaptável"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", ""), ("Relay Connection", ""),
("Secure Connection", ""), ("Secure Connection", ""),
("Insecure Connection", ""), ("Insecure Connection", ""),
("Scale original", ""),
("Scale adaptive", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Релейное соединение"), ("Relay Connection", "Релейное соединение"),
("Secure Connection", "Безопасное соединение"), ("Secure Connection", "Безопасное соединение"),
("Insecure Connection", "Небезопасное соединение"), ("Insecure Connection", "Небезопасное соединение"),
("Scale original", "Оригинал масштаба"),
("Scale adaptive", "Масштаб адаптивный"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Reléové pripojenie"), ("Relay Connection", "Reléové pripojenie"),
("Secure Connection", "Zabezpečené pripojenie"), ("Secure Connection", "Zabezpečené pripojenie"),
("Insecure Connection", "Nezabezpečené pripojenie"), ("Insecure Connection", "Nezabezpečené pripojenie"),
("Scale original", "Pôvodná mierka"),
("Scale adaptive", "Prispôsobivá mierka"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", ""), ("Relay Connection", ""),
("Secure Connection", ""), ("Secure Connection", ""),
("Insecure Connection", ""), ("Insecure Connection", ""),
("Scale original", ""),
("Scale adaptive", ""),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Röle Bağlantısı"), ("Relay Connection", "Röle Bağlantısı"),
("Secure Connection", "Güvenli bağlantı"), ("Secure Connection", "Güvenli bağlantı"),
("Insecure Connection", "Güvenli Bağlantı"), ("Insecure Connection", "Güvenli Bağlantı"),
("Scale original", "Orijinali ölçeklendir"),
("Scale adaptive", "Ölçek uyarlanabilir"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "中繼連接"), ("Relay Connection", "中繼連接"),
("Secure Connection", "安全連接"), ("Secure Connection", "安全連接"),
("Insecure Connection", "非安全連接"), ("Insecure Connection", "非安全連接"),
("Scale original", "原始尺寸"),
("Scale adaptive", "適應窗口"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }

View File

@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Relay Connection", "Kết nối chuyển tiếp"), ("Relay Connection", "Kết nối chuyển tiếp"),
("Secure Connection", "Kết nối an toàn"), ("Secure Connection", "Kết nối an toàn"),
("Insecure Connection", "Kết nối không an toàn"), ("Insecure Connection", "Kết nối không an toàn"),
("Scale original", "Quy mô gốc"),
("Scale adaptive", "Quy mô thích ứng"),
].iter().cloned().collect(); ].iter().cloned().collect();
} }