From 7b74d83c2318e58dc3a9339d5687329d1acc6b9f Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Fri, 8 Mar 2024 01:18:11 -0600 Subject: [PATCH] new: ssh page zoom (#256) --- lib/l10n/app_de.arb | 1 + lib/l10n/app_en.arb | 1 + lib/l10n/app_es.arb | 3 +- lib/l10n/app_fr.arb | 1 + lib/l10n/app_id.arb | 1 + lib/l10n/app_ja.arb | 3 +- lib/l10n/app_pt.arb | 3 +- lib/l10n/app_ru.arb | 3 +- lib/l10n/app_zh.arb | 1 + lib/l10n/app_zh_tw.arb | 1 + lib/view/page/setting/entry.dart | 15 ++++---- lib/view/page/ssh/page.dart | 63 +++++++++++++++++++++----------- 12 files changed, 64 insertions(+), 32 deletions(-) diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index a94a0cda..021c6beb 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -241,6 +241,7 @@ "system": "Systeme", "tag": "Tags", "temperature": "Temperatur", + "termFontSizeTip": "Diese Einstellung beeinflusst die Größe des Terminals (Breite und Höhe).", "terminal": "Terminal", "test": "Prüfung", "textScaler": "Skalierung der Schriftart", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 359b5288..6ae5300c 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -241,6 +241,7 @@ "system": "System", "tag": "Tags", "temperature": "Temperature", + "termFontSizeTip": "This setting will affect the terminal size (width and height).", "terminal": "Terminal", "test": "Test", "textScaler": "Text scaler", diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 0a465013..b5dfb8a5 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -241,6 +241,7 @@ "system": "Sistema", "tag": "Etiqueta", "temperature": "Temperatura", + "termFontSizeTip": "Este ajuste afectará el tamaño del terminal (ancho y alto).", "terminal": "Terminal", "test": "Prueba", "textScaler": "Escalar texto", @@ -282,4 +283,4 @@ "whenOpenApp": "Al abrir la App", "willTakEeffectImmediately": "Los cambios tendrán efecto inmediatamente", "write": "Escribir" -} +} \ No newline at end of file diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 66f2c13e..2261c248 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -241,6 +241,7 @@ "system": "Système", "tag": "Étiquettes", "temperature": "Température", + "termFontSizeTip": "Ce paramètre affectera la taille du terminal (largeur et hauteur).", "terminal": "Terminal", "test": "Tester", "textScaler": "Mise à l'échelle du texte", diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index 44020b1c..c0e8a474 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -241,6 +241,7 @@ "system": "Sistem", "tag": "Tag", "temperature": "Suhu", + "termFontSizeTip": "Pengaturan ini akan memengaruhi ukuran terminal (lebar dan tinggi).", "terminal": "Terminal", "test": "pengujian", "textScaler": "Penskalaan font", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index ed6fa7b1..465079e6 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -241,6 +241,7 @@ "system": "システム", "tag": "タグ", "temperature": "温度", + "termFontSizeTip": "この設定は端末のサイズ(幅と高さ)に影響します", "terminal": "ターミナル", "test": "テスト", "textScaler": "テキストスケーラー", @@ -282,4 +283,4 @@ "whenOpenApp": "アプリを開くとき", "willTakEeffectImmediately": "変更は即座に有効になります", "write": "書き込み" -} +} \ No newline at end of file diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index 4c7d89cd..a9f7d292 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -241,6 +241,7 @@ "system": "Sistema", "tag": "Tag", "temperature": "Temperatura", + "termFontSizeTip": "Esta configuração afetará o tamanho do terminal (largura e altura).", "terminal": "Terminal", "test": "Teste", "textScaler": "Escala de texto", @@ -282,4 +283,4 @@ "whenOpenApp": "Ao abrir o app", "willTakEeffectImmediately": "As alterações serão aplicadas imediatamente", "write": "Escrita" -} +} \ No newline at end of file diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index a829fa5a..1f8f0203 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -241,6 +241,7 @@ "system": "система", "tag": "тег", "temperature": "температура", + "termFontSizeTip": "Эта настройка повлияет на размер терминала (ширина и высота).", "terminal": "терминал", "test": "тест", "textScaler": "масштабирование текста", @@ -282,4 +283,4 @@ "whenOpenApp": "при открытии приложения", "willTakEeffectImmediately": "Изменения вступят в силу немедленно", "write": "запись" -} +} \ No newline at end of file diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 08a664d4..538cc500 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -241,6 +241,7 @@ "system": "系统", "tag": "标签", "temperature": "温度", + "termFontSizeTip": "此设置会影响终端大小(宽高)", "terminal": "终端", "test": "测试", "textScaler": "字体缩放", diff --git a/lib/l10n/app_zh_tw.arb b/lib/l10n/app_zh_tw.arb index 5359a751..2f19c06d 100644 --- a/lib/l10n/app_zh_tw.arb +++ b/lib/l10n/app_zh_tw.arb @@ -241,6 +241,7 @@ "system": "系統", "tag": "标签", "temperature": "溫度", + "termFontSizeTip": "此設置將影響終端大小(寬度和高度)", "terminal": "终端機", "test": "測試", "textScaler": "字體縮放", diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index 4256f227..67dbe8b7 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -563,16 +563,17 @@ class _SettingPageState extends State { } Widget _buildTermFontSize() { - return ListenableBuilder( - listenable: _termFontSize, - builder: (_, __) => ListTile( - title: Text(l10n.fontSize), - trailing: Text( - _termFontSize.value.toString(), + return ListTile( + title: Text(l10n.fontSize), + subtitle: Text(l10n.termFontSizeTip, style: UIs.textGrey), + trailing: ValueListenableBuilder( + valueListenable: _setting.termFontSize.listenable(), + builder: (_, val, __) => Text( + val.toString(), style: UIs.text15, ), - onTap: () => _showFontSizeDialog(_termFontSize, _setting.termFontSize), ), + onTap: () => _showFontSizeDialog(_termFontSize, _setting.termFontSize), ); } diff --git a/lib/view/page/ssh/page.dart b/lib/view/page/ssh/page.dart index 609f7ff7..0874fb58 100644 --- a/lib/view/page/ssh/page.dart +++ b/lib/view/page/ssh/page.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:math' as math; import 'package:dartssh2/dartssh2.dart'; import 'package:flutter/material.dart'; @@ -57,6 +58,7 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { late TerminalStyle _terminalStyle; late TerminalTheme _terminalTheme; late TextInputType _keyboardType; + late double _originTextSize; double _virtKeyWidth = 0; double _virtKeysHeight = 0; @@ -69,13 +71,7 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { @override void initState() { super.initState(); - final fontFamilly = getFileName(Stores.setting.fontPath.fetch()); - final textStyle = TextStyle( - fontFamily: fontFamilly, - fontSize: Stores.setting.termFontSize.fetch(), - ); - _terminalStyle = TerminalStyle.fromTextStyle(textStyle); - _keyboardType = TextInputType.values[Stores.setting.keyboardType.fetch()]; + _initStoredCfg(); _initVirtKeys(); Future.delayed(const Duration(milliseconds: 77), () async { @@ -138,17 +134,31 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { _media.padding.bottom - _media.padding.top, child: Padding( - padding: EdgeInsets.only(top: _media.padding.top), - child: TerminalView( - _terminal, - controller: _terminalController, - keyboardType: _keyboardType, - textStyle: _terminalStyle, - theme: _terminalTheme, - deleteDetection: isMobile, - autofocus: true, - keyboardAppearance: _isDark ? Brightness.dark : Brightness.light, - //hideScrollBar: false, + padding: EdgeInsets.only(top: _media.padding.top, left: 7, right: 7), + child: GestureDetector( + onScaleUpdate: (details) { + if (details.scale == 1) { + return; + } + final scale = math.pow(details.scale, 0.3); + final fontSize = _originTextSize * scale; + if (fontSize < 7 || fontSize > 17) { + return; + } + _terminalStyle = _terminalStyle.copyWith(fontSize: fontSize); + setState(() {}); + }, + child: TerminalView( + _terminal, + controller: _terminalController, + keyboardType: _keyboardType, + textStyle: _terminalStyle, + theme: _terminalTheme, + deleteDetection: isMobile, + autofocus: true, + keyboardAppearance: _isDark ? Brightness.dark : Brightness.light, + //hideScrollBar: false, + ), ), ), ); @@ -225,9 +235,7 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { child: SizedBox( width: _virtKeyWidth, height: _virtKeysHeight / _virtKeysList.length, - child: Center( - child: child, - ), + child: Center(child: child), ), ); } @@ -474,6 +482,19 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { iosConfiguration: IosConfiguration(), ); } + + void _initStoredCfg() { + final fontFamilly = getFileName(Stores.setting.fontPath.fetch()); + final textSize = Stores.setting.termFontSize.fetch(); + _originTextSize = textSize; + final textStyle = TextStyle( + fontFamily: fontFamilly, + fontSize: textSize, + ); + + _terminalStyle = TerminalStyle.fromTextStyle(textStyle); + _keyboardType = TextInputType.values[Stores.setting.keyboardType.fetch()]; + } } Future _onStart(ServiceInstance service) async {}