From 59f0ffa82fafb7f8ace87b1a5503f2ec2cdd418d Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 31 Aug 2022 16:41:05 +0800 Subject: [PATCH] flutter_desktop: menu bar, switch menu & shrink-stretch -> adaptive Signed-off-by: fufesou --- flutter/lib/desktop/widgets/popup_menu.dart | 38 ++++++++++--------- .../lib/desktop/widgets/remote_menubar.dart | 7 ++-- flutter/lib/models/model.dart | 38 +++---------------- flutter/lib/models/native_model.dart | 22 +++++------ src/lang/cn.rs | 2 + src/lang/cs.rs | 2 + src/lang/da.rs | 2 + src/lang/de.rs | 2 + src/lang/eo.rs | 2 + src/lang/es.rs | 2 + src/lang/fr.rs | 2 + src/lang/hu.rs | 2 + src/lang/id.rs | 2 + src/lang/it.rs | 2 + src/lang/ja.rs | 2 + src/lang/ko.rs | 2 + src/lang/pl.rs | 2 + src/lang/pt_PT.rs | 2 + src/lang/ptbr.rs | 2 + src/lang/ru.rs | 2 + src/lang/sk.rs | 2 + src/lang/template.rs | 2 + src/lang/tr.rs | 2 + src/lang/tw.rs | 2 + src/lang/vn.rs | 2 + 25 files changed, 81 insertions(+), 66 deletions(-) diff --git a/flutter/lib/desktop/widgets/popup_menu.dart b/flutter/lib/desktop/widgets/popup_menu.dart index 3d5fdf7f6..6dbe4f8cd 100644 --- a/flutter/lib/desktop/widgets/popup_menu.dart +++ b/flutter/lib/desktop/widgets/popup_menu.dart @@ -315,29 +315,31 @@ abstract class MenuEntrySwitchBase extends MenuEntryBase { mod_menu.PopupMenuItem( padding: EdgeInsets.zero, height: conf.height, - child: Obx( - () => SwitchListTile( - value: curOption.value, - onChanged: (v) { - setOption(v); - }, - title: Container( - alignment: AlignmentDirectional.centerStart, - constraints: BoxConstraints(minHeight: conf.height), - child: Text( + child: TextButton( + child: Container( + alignment: AlignmentDirectional.centerStart, + height: conf.height, + child: Row(children: [ + // const SizedBox(width: MenuConfig.midPadding), + Text( text, style: const TextStyle( color: Colors.black, fontSize: MenuConfig.fontSize, fontWeight: FontWeight.normal), - )), - dense: true, - visualDensity: const VisualDensity( - horizontal: VisualDensity.minimumDensity, - vertical: VisualDensity.minimumDensity, - ), - contentPadding: const EdgeInsets.only(left: 8.0), - ), + ), + Expanded( + child: Align( + alignment: Alignment.centerRight, + child: Obx(() => Switch( + value: curOption.value, + onChanged: (v) => setOption(v), + )), + )) + ])), + onPressed: () { + setOption(!curOption.value); + }, ), ) ]; diff --git a/flutter/lib/desktop/widgets/remote_menubar.dart b/flutter/lib/desktop/widgets/remote_menubar.dart index 0e931dd71..2e8c7fb63 100644 --- a/flutter/lib/desktop/widgets/remote_menubar.dart +++ b/flutter/lib/desktop/widgets/remote_menubar.dart @@ -406,14 +406,13 @@ class _RemoteMenubarState extends State { MenuEntryRadios( text: translate('Ratio'), optionsGetter: () => [ - Tuple2(translate('Original'), 'original'), - Tuple2(translate('Shrink'), 'shrink'), - Tuple2(translate('Stretch'), 'stretch'), + Tuple2(translate('Scale original'), 'original'), + Tuple2(translate('Scale adaptive'), 'adaptive'), ], curOptionGetter: () async { return await bind.sessionGetOption( id: widget.id, arg: 'view-style') ?? - ''; + 'adaptive'; }, optionSetter: (String v) async { await bind.sessionPeerOption( diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index c01451280..da06b7fb9 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -497,39 +497,11 @@ class CanvasModel with ChangeNotifier { return; } - final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); - final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); - - // Closure to perform shrink operation. - final shrinkOp = () { - 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(); + _scale = 1.0; + if (style == 'adaptive') { + final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); + final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); + _scale = s1 < s2 ? s1 : s2; } _x = (size.width - getDisplayWidth() * _scale) / 2; diff --git a/flutter/lib/models/native_model.dart b/flutter/lib/models/native_model.dart index 57372cdb9..2a8391723 100644 --- a/flutter/lib/models/native_model.dart +++ b/flutter/lib/models/native_model.dart @@ -30,7 +30,7 @@ class PlatformFFI { String _dir = ''; String _homeDir = ''; F2? _translate; - var _eventHandlers = Map>(); + final _eventHandlers = Map>(); late RustdeskImpl _ffiBind; late String _appType; void Function(Map)? _eventCallback; @@ -50,27 +50,27 @@ class PlatformFFI { } bool registerEventHandler( - String event_name, String handler_name, HandleEvent handler) { - debugPrint('registerEventHandler $event_name $handler_name'); - var handlers = _eventHandlers[event_name]; + String eventName, String handlerName, HandleEvent handler) { + debugPrint('registerEventHandler $eventName $handlerName'); + var handlers = _eventHandlers[eventName]; if (handlers == null) { - _eventHandlers[event_name] = {handler_name: handler}; + _eventHandlers[eventName] = {handlerName: handler}; return true; } else { - if (handlers.containsKey(handler_name)) { + if (handlers.containsKey(handlerName)) { return false; } else { - handlers[handler_name] = handler; + handlers[handlerName] = handler; return true; } } } - void unregisterEventHandler(String event_name, String handler_name) { - debugPrint('unregisterEventHandler $event_name $handler_name'); - var handlers = _eventHandlers[event_name]; + void unregisterEventHandler(String eventName, String handlerName) { + debugPrint('unregisterEventHandler $eventName $handlerName'); + var handlers = _eventHandlers[eventName]; if (handlers != null) { - handlers.remove(handler_name); + handlers.remove(handlerName); } } diff --git a/src/lang/cn.rs b/src/lang/cn.rs index fdb23f88e..c6efaee85 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "中继连接"), ("Secure Connection", "安全连接"), ("Insecure Connection", "非安全连接"), + ("Scale original", "原始尺寸"), + ("Scale adaptive", "适应窗口"), ].iter().cloned().collect(); } diff --git a/src/lang/cs.rs b/src/lang/cs.rs index d9ddf78cc..99d0ae694 100644 --- a/src/lang/cs.rs +++ b/src/lang/cs.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Připojení relé"), ("Secure Connection", "Zabezpečené připojení"), ("Insecure Connection", "Nezabezpečené připojení"), + ("Scale original", "Měřítko původní"), + ("Scale adaptive", "Měřítko adaptivní"), ].iter().cloned().collect(); } diff --git a/src/lang/da.rs b/src/lang/da.rs index 0e2d99425..883ef27a5 100644 --- a/src/lang/da.rs +++ b/src/lang/da.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Relæforbindelse"), ("Secure Connection", "Sikker forbindelse"), ("Insecure Connection", "Usikker forbindelse"), + ("Scale original", "Skala original"), + ("Scale adaptive", "Skala adaptiv"), ].iter().cloned().collect(); } diff --git a/src/lang/de.rs b/src/lang/de.rs index 20cd9330e..649199f0d 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Relaisverbindung"), ("Secure Connection", "Sichere Verbindung"), ("Insecure Connection", "Unsichere Verbindung"), + ("Scale original", "Original skalieren"), + ("Scale adaptive", "Adaptiv skalieren"), ].iter().cloned().collect(); } diff --git a/src/lang/eo.rs b/src/lang/eo.rs index fe12e2d24..34b89c350 100644 --- a/src/lang/eo.rs +++ b/src/lang/eo.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Relajsa Konekto"), ("Secure Connection", "Sekura Konekto"), ("Insecure Connection", "Nesekura Konekto"), + ("Scale original", "Skalo originalo"), + ("Scale adaptive", "Skalo adapta"), ].iter().cloned().collect(); } diff --git a/src/lang/es.rs b/src/lang/es.rs index 313ea8cac..82395dd7a 100644 --- a/src/lang/es.rs +++ b/src/lang/es.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Conexión de relé"), ("Secure Connection", "Conexión segura"), ("Insecure Connection", "Conexión insegura"), + ("Scale original", "escala originales"), + ("Scale adaptive", "Adaptable a escala"), ].iter().cloned().collect(); } diff --git a/src/lang/fr.rs b/src/lang/fr.rs index c8b12243f..00cfe3a3c 100644 --- a/src/lang/fr.rs +++ b/src/lang/fr.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Connexion relais"), ("Secure Connection", "Connexion sécurisée"), ("Insecure Connection", "Connexion non sécurisée"), + ("Scale original", "Échelle d'origine"), + ("Scale adaptive", "Échelle adaptative"), ].iter().cloned().collect(); } diff --git a/src/lang/hu.rs b/src/lang/hu.rs index a6356b000..d1a259119 100644 --- a/src/lang/hu.rs +++ b/src/lang/hu.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Relé csatlakozás"), ("Secure Connection", "Biztonságos kapcsolat"), ("Insecure Connection", "Nem biztonságos kapcsolat"), + ("Scale original", "Eredeti méretarány"), + ("Scale adaptive", "Skála adaptív"), ].iter().cloned().collect(); } diff --git a/src/lang/id.rs b/src/lang/id.rs index 8548eb6bc..3447d3388 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Koneksi Relay"), ("Secure Connection", "Koneksi aman"), ("Insecure Connection", "Koneksi Tidak Aman"), + ("Scale original", "Skala asli"), + ("Scale adaptive", "Skala adaptif"), ].iter().cloned().collect(); } diff --git a/src/lang/it.rs b/src/lang/it.rs index fdf8d27d9..65cdd4b3d 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -316,5 +316,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Collegamento a relè"), ("Secure Connection", "Connessione sicura"), ("Insecure Connection", "Connessione insicura"), + ("Scale original", "Scala originale"), + ("Scale adaptive", "Scala adattiva"), ].iter().cloned().collect(); } diff --git a/src/lang/ja.rs b/src/lang/ja.rs index 1d031f2f2..cbe31bf9f 100644 --- a/src/lang/ja.rs +++ b/src/lang/ja.rs @@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "リレー接続"), ("Secure Connection", "安全な接続"), ("Insecure Connection", "安全でない接続"), + ("Scale original", "オリジナルサイズ"), + ("Scale adaptive", "フィットウィンドウ"), ].iter().cloned().collect(); } diff --git a/src/lang/ko.rs b/src/lang/ko.rs index 19d4c7ddf..44ba589f6 100644 --- a/src/lang/ko.rs +++ b/src/lang/ko.rs @@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "릴레이 연결"), ("Secure Connection", "보안 연결"), ("Insecure Connection", "안전하지 않은 연결"), + ("Scale original", "원래 크기"), + ("Scale adaptive", "맞는 창"), ].iter().cloned().collect(); } \ No newline at end of file diff --git a/src/lang/pl.rs b/src/lang/pl.rs index 251c349a2..42bd49bbb 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -318,5 +318,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Połączenie przekaźnika"), ("Secure Connection", "Bezpieczne połączenie"), ("Insecure Connection", "Niepewne połączenie"), + ("Scale original", "Skala oryginalna"), + ("Scale adaptive", "Skala adaptacyjna"), ].iter().cloned().collect(); } diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs index fd4384767..e8c62d78a 100644 --- a/src/lang/pt_PT.rs +++ b/src/lang/pt_PT.rs @@ -314,5 +314,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Conexão de relé"), ("Secure Connection", "Conexão segura"), ("Insecure Connection", "Conexão insegura"), + ("Scale original", "Escala original"), + ("Scale adaptive", "Escala adaptável"), ].iter().cloned().collect(); } diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs index 85eda60e6..cdd4128b5 100644 --- a/src/lang/ptbr.rs +++ b/src/lang/ptbr.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", ""), ("Secure Connection", ""), ("Insecure Connection", ""), + ("Scale original", ""), + ("Scale adaptive", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index def560217..5bbdd846d 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Релейное соединение"), ("Secure Connection", "Безопасное соединение"), ("Insecure Connection", "Небезопасное соединение"), + ("Scale original", "Оригинал масштаба"), + ("Scale adaptive", "Масштаб адаптивный"), ].iter().cloned().collect(); } diff --git a/src/lang/sk.rs b/src/lang/sk.rs index 4c04618aa..b92d0aca6 100644 --- a/src/lang/sk.rs +++ b/src/lang/sk.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Reléové pripojenie"), ("Secure Connection", "Zabezpečené pripojenie"), ("Insecure Connection", "Nezabezpečené pripojenie"), + ("Scale original", "Pôvodná mierka"), + ("Scale adaptive", "Prispôsobivá mierka"), ].iter().cloned().collect(); } diff --git a/src/lang/template.rs b/src/lang/template.rs index 081b7bf55..8cf46a196 100644 --- a/src/lang/template.rs +++ b/src/lang/template.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", ""), ("Secure Connection", ""), ("Insecure Connection", ""), + ("Scale original", ""), + ("Scale adaptive", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tr.rs b/src/lang/tr.rs index 9738ed469..c5ec537b4 100644 --- a/src/lang/tr.rs +++ b/src/lang/tr.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "Röle Bağlantısı"), ("Secure Connection", "Güvenli bağlantı"), ("Insecure Connection", "Güvenli Bağlantı"), + ("Scale original", "Orijinali ölçeklendir"), + ("Scale adaptive", "Ölçek uyarlanabilir"), ].iter().cloned().collect(); } diff --git a/src/lang/tw.rs b/src/lang/tw.rs index 46276dd2a..836b5ad12 100644 --- a/src/lang/tw.rs +++ b/src/lang/tw.rs @@ -317,5 +317,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Relay Connection", "中繼連接"), ("Secure Connection", "安全連接"), ("Insecure Connection", "非安全連接"), + ("Scale original", "原始尺寸"), + ("Scale adaptive", "適應窗口"), ].iter().cloned().collect(); } diff --git a/src/lang/vn.rs b/src/lang/vn.rs index 474e57337..ba9e4cb86 100644 --- a/src/lang/vn.rs +++ b/src/lang/vn.rs @@ -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"), ("Secure Connection", "Kết nối 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(); }