diff --git a/kuhy_credit/README.md b/kuhy_credit/README.md index 4a734e1..7b1e431 100644 --- a/kuhy_credit/README.md +++ b/kuhy_credit/README.md @@ -44,7 +44,7 @@ Nothing loads over the network and nothing opens without a click. ```jsonc // package.json -"@kuhyx/kuhy-credit": "github:kuhyx/utils#kuhy-credit-v0.3.0&path:kuhy_credit/web" +"@kuhyx/kuhy-credit": "github:kuhyx/utils#kuhy-credit-v0.3.1&path:kuhy_credit/web" ``` ```html @@ -70,7 +70,7 @@ dependencies: kuhy_credit: git: url: https://github.com/kuhyx/utils - ref: kuhy-credit-v0.3.0 + ref: kuhy-credit-v0.3.1 path: kuhy_credit/flutter ``` @@ -87,7 +87,7 @@ app on Android). Back closes an open panel. Demo: `flutter/example`. ```bash cache="$(mktemp -d)" -git clone --depth 1 --branch kuhy-credit-v0.3.0 https://github.com/kuhyx/utils "$cache" +git clone --depth 1 --branch kuhy-credit-v0.3.1 https://github.com/kuhyx/utils "$cache" cp -r "$cache/kuhy_credit/godot/addons/kuhy_credit" addons/ ``` @@ -103,7 +103,7 @@ The script opens the site with `OS.shell_open`. Demo: ## Python / Tkinter ```bash -pip install "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.0#subdirectory=kuhy_credit" +pip install "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.3.1#subdirectory=kuhy_credit" ``` ```python @@ -124,7 +124,7 @@ vector TikZ, no image file) and makes it a link to the site. No words appear. ```bash # vendor the generated package from the tag, like the Godot addon cache="$(mktemp -d)" -git clone --depth 1 --branch kuhy-credit-v0.3.0 https://github.com/kuhyx/utils "$cache" +git clone --depth 1 --branch kuhy-credit-v0.3.1 https://github.com/kuhyx/utils "$cache" cp "$cache/kuhy_credit/latex/kuhy-credit.sty" kuhy-credit/ TEXINPUTS="$PWD/kuhy-credit//:" pdflatex doc.tex ``` diff --git a/kuhy_credit/flutter/example/pubspec.lock b/kuhy_credit/flutter/example/pubspec.lock index 6637121..40b253e 100644 --- a/kuhy_credit/flutter/example/pubspec.lock +++ b/kuhy_credit/flutter/example/pubspec.lock @@ -70,7 +70,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.3.1" leak_tracker: dependency: transitive description: diff --git a/kuhy_credit/flutter/lib/src/kuhy_credit.dart b/kuhy_credit/flutter/lib/src/kuhy_credit.dart index d650653..d457aaf 100644 --- a/kuhy_credit/flutter/lib/src/kuhy_credit.dart +++ b/kuhy_credit/flutter/lib/src/kuhy_credit.dart @@ -129,38 +129,47 @@ class _KuhyCreditState extends State { ), ), ); - return PopScope( - canPop: !_portal.isShowing, - onPopInvokedWithResult: (didPop, _) { - if (!didPop) _close(); - }, - child: TapRegion( - groupId: this, - onTapOutside: (_) => _close(), - child: CompositedTransformTarget( - link: _link, - child: OverlayPortal( - controller: _portal, - overlayChildBuilder: (context) => CompositedTransformFollower( - link: _link, - targetAnchor: Alignment(end ? 1 : -1, above ? -1 : 1), - followerAnchor: Alignment(end ? 1 : -1, above ? 1 : -1), - offset: Offset(0, above ? -kSpaceSm : kSpaceSm), - child: Align( - alignment: Alignment(end ? 1 : -1, above ? 1 : -1), - child: TapRegion( - groupId: this, - child: _Panel( - dark: dark, - size: widget.size, - focusNode: _panelFocus, - onKey: _onPanelKey, - onTap: _activate, + // A stretching parent (ListView, Column.stretch) would force the logo + // to the full row width: the painter then scaled the dark field across + // the screen and the glyph fell outside the clip, an invisible logo. + // Loosen the constraints here so the logo, the tap target and the panel + // anchor all keep [KuhyCredit.size]. + return Center( + widthFactor: 1, + heightFactor: 1, + child: PopScope( + canPop: !_portal.isShowing, + onPopInvokedWithResult: (didPop, _) { + if (!didPop) _close(); + }, + child: TapRegion( + groupId: this, + onTapOutside: (_) => _close(), + child: CompositedTransformTarget( + link: _link, + child: OverlayPortal( + controller: _portal, + overlayChildBuilder: (context) => CompositedTransformFollower( + link: _link, + targetAnchor: Alignment(end ? 1 : -1, above ? -1 : 1), + followerAnchor: Alignment(end ? 1 : -1, above ? 1 : -1), + offset: Offset(0, above ? -kSpaceSm : kSpaceSm), + child: Align( + alignment: Alignment(end ? 1 : -1, above ? 1 : -1), + child: TapRegion( + groupId: this, + child: _Panel( + dark: dark, + size: widget.size, + focusNode: _panelFocus, + onKey: _onPanelKey, + onTap: _activate, + ), ), ), ), + child: logo, ), - child: logo, ), ), ), diff --git a/kuhy_credit/flutter/lib/src/kuhy_credit_logo.dart b/kuhy_credit/flutter/lib/src/kuhy_credit_logo.dart index f42408a..65a8b18 100644 --- a/kuhy_credit/flutter/lib/src/kuhy_credit_logo.dart +++ b/kuhy_credit/flutter/lib/src/kuhy_credit_logo.dart @@ -16,8 +16,11 @@ class _LogoPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { + // Scale by the short side and clip, so a non-square box can never + // push the glyph out of view. canvas - ..scale(size.width / kLogoSize) + ..clipRect(Offset.zero & size) + ..scale(size.shortestSide / kLogoSize) ..drawRect( const Rect.fromLTWH(0, 0, kLogoSize, kLogoSize), Paint()..color = const Color(kLogoField), diff --git a/kuhy_credit/flutter/pubspec.yaml b/kuhy_credit/flutter/pubspec.yaml index 897dcde..a2707bd 100644 --- a/kuhy_credit/flutter/pubspec.yaml +++ b/kuhy_credit/flutter/pubspec.yaml @@ -3,7 +3,7 @@ description: >- The shared "Created by kuhy" credit: an M1 logo button that opens a small panel, whose tap opens kuhy.duckdns.org. Android and Flutter web. publish_to: 'none' -version: 0.3.0 +version: 0.3.1 environment: sdk: ^3.12.2 diff --git a/kuhy_credit/flutter/test/kuhy_credit_layout_test.dart b/kuhy_credit/flutter/test/kuhy_credit_layout_test.dart new file mode 100644 index 0000000..d3bc48a --- /dev/null +++ b/kuhy_credit/flutter/test/kuhy_credit_layout_test.dart @@ -0,0 +1,27 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:kuhy_credit/kuhy_credit.dart'; + +void main() { + testWidgets('a stretching parent (ListView) keeps the logo at its size', ( + tester, + ) async { + await tester.pumpWidget( + WidgetsApp( + color: const Color(kDarkBg), + pageRouteBuilder: (settings, builder) => PageRouteBuilder( + settings: settings, + pageBuilder: (context, _, _) => builder(context), + ), + home: ListView(children: const [KuhyCredit(size: 40)]), + ), + ); + final logo = find.byKey(KuhyCredit.logoKey); + expect(tester.getSize(logo), const Size(40, 40)); + // The tap target shrank with the logo: the row's far end opens nothing. + final row = tester.getRect(find.byType(KuhyCredit)); + await tester.tapAt(row.centerRight - const Offset(4, 0)); + await tester.pumpAndSettle(); + expect(find.byKey(KuhyCredit.panelKey), findsNothing); + }); +} diff --git a/kuhy_credit/pyproject.toml b/kuhy_credit/pyproject.toml index 909935d..6a3b171 100644 --- a/kuhy_credit/pyproject.toml +++ b/kuhy_credit/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "kuhy-credit" -version = "0.3.0" +version = "0.3.1" description = "The shared 'Created by kuhy' logo credit: Tkinter widget and terminal line" requires-python = ">=3.14" dependencies = [] # pure stdlib: tkinter and webbrowser ship with Python diff --git a/kuhy_credit/web/package.json b/kuhy_credit/web/package.json index 6b498b9..103cd00 100644 --- a/kuhy_credit/web/package.json +++ b/kuhy_credit/web/package.json @@ -1,6 +1,6 @@ { "name": "@kuhyx/kuhy-credit", - "version": "0.3.0", + "version": "0.3.1", "private": false, "type": "module", "description": ": the shared 'Created by kuhy' logo credit as a dependency-free custom element.",