feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
This commit was merged in pull request #13.
This commit is contained in:
1 parent
aa5255d1e4
commit
abc1868550
260 files changed
+43964
-5591
No files matched your search
@@ -6,6 +6,7 @@ Cutdex workspace 内部 Flutter 原生插件,暂不发布。
|
||||
| --- | --- | --- |
|
||||
| 窗口标题栏、拖动区域与关闭请求拦截 | 支持 | 支持 |
|
||||
| 本地文件拖放区域 | 支持 | 支持 |
|
||||
| 附着主窗口的异步文件选择弹窗 | 支持 | 由应用使用 Filegate |
|
||||
| 原生上下文菜单 | 支持 | 由 UI 包回退为 Flutter 菜单 |
|
||||
| 原生窗口全屏会话 | 支持 | 未提供 |
|
||||
|
||||
@@ -23,6 +24,8 @@ macOS 宿主窗口继承 `CutdexNativeWindow`,导入 `cutdex_native` 后按 Fl
|
||||
|
||||
## 文件拖放
|
||||
|
||||
`NativeFilePicker.pickFiles` 在 macOS 使用主窗口的异步 `NSOpenPanel` sheet,支持多选和扩展名过滤,返回本地路径;取消返回空列表。窗口不存在或已有弹窗时返回平台异常。原生选择器不进入 `runModal` 的同步嵌套事件循环,导入与聊天附件共用此入口。
|
||||
|
||||
`NativeFileDropRegion` 接收稳定的 `regionId`、`NativeDropConfiguration`、启用状态与回调,回调中的文件是原始路径列表。扩展名白名单与数量上限由调用方提供。
|
||||
|
||||
两端均拒绝目录和不存在的文件,并在落下时重新检查文件引用。
|
||||
@@ -51,6 +54,7 @@ macOS 标题栏手势使用真实 AppKit 响应链,文件引用策略使用临
|
||||
python3 tool/build.py macos --mode debug --flavor development
|
||||
bash packages/cutdex_native/tool/macos/test_header_control_gestures.sh
|
||||
bash packages/cutdex_native/tool/macos/test_file_drop_policy.sh
|
||||
bash packages/cutdex_native/tool/macos/test_file_picker.sh
|
||||
```
|
||||
|
||||
Windows 标题栏回归验证真实 HWND、命中区域、最大化、DPI 与标题栏恢复;先准备 Flutter C++ wrapper:
|
||||
|
||||
@@ -4,6 +4,7 @@ export 'src/window_chrome_session.dart';
|
||||
export 'src/window_header_layout.dart';
|
||||
export 'src/fullscreen.dart';
|
||||
export 'src/file_drop.dart';
|
||||
export 'src/file_picker.dart';
|
||||
export 'src/file_drop_region.dart';
|
||||
export 'src/context_menu.dart';
|
||||
export 'src/device_info.dart';
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Selects local files in a sheet attached to the macOS host window.
|
||||
abstract final class NativeFilePicker {
|
||||
static const _channel = MethodChannel('cutdex_native/file_picker');
|
||||
|
||||
/// Returns an empty list when the user cancels the selection.
|
||||
static Future<List<String>> pickFiles({
|
||||
required List<String> allowedExtensions,
|
||||
}) async {
|
||||
final paths = await _channel.invokeListMethod<String>('pickFiles', {
|
||||
'allowedExtensions': allowedExtensions,
|
||||
});
|
||||
return paths ?? const [];
|
||||
}
|
||||
}
|
||||
+8
@@ -5,12 +5,14 @@ public final class CutdexNativePlugin: NSObject, FlutterPlugin {
|
||||
private let view: NSView
|
||||
private let messenger: FlutterBinaryMessenger
|
||||
private let menu: NativeContextMenuBridge
|
||||
private let filePicker: NativeFilePickerBridge
|
||||
private var drops: [String: NativeFileDropView] = [:]
|
||||
|
||||
private init(view: NSView, messenger: FlutterBinaryMessenger) {
|
||||
self.view = view
|
||||
self.messenger = messenger
|
||||
menu = NativeContextMenuBridge(view: view, messenger: messenger)
|
||||
filePicker = NativeFilePickerBridge(view: view)
|
||||
super.init()
|
||||
(view.window as? CutdexNativeWindow)?.configureNative(messenger: messenger)
|
||||
}
|
||||
@@ -23,9 +25,15 @@ public final class CutdexNativePlugin: NSObject, FlutterPlugin {
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
registrar.addMethodCallDelegate(instance, channel: FlutterMethodChannel(
|
||||
name: "cutdex_native/device_info", binaryMessenger: registrar.messenger))
|
||||
registrar.addMethodCallDelegate(instance, channel: FlutterMethodChannel(
|
||||
name: "cutdex_native/file_picker", binaryMessenger: registrar.messenger))
|
||||
}
|
||||
|
||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
if call.method == "pickFiles" {
|
||||
filePicker.pickFiles(arguments: call.arguments, result: result)
|
||||
return
|
||||
}
|
||||
if call.method == "getApplicationInfo" {
|
||||
result(["appVersion": Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "unknown",
|
||||
"appBuild": Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "unknown"])
|
||||
|
||||
+2
-1
@@ -304,7 +304,8 @@ open class CutdexNativeWindow: NSWindow {
|
||||
target.mouseDown(with: event)
|
||||
return
|
||||
}
|
||||
if top >= 0, top < headerHeight, point.x >= 88 {
|
||||
// Matches the Flutter reservation for the native button group (x=0...68).
|
||||
if top >= 0, top < headerHeight, point.x >= 68 {
|
||||
if event.clickCount == 2 {
|
||||
switch UserDefaults.standard.string(forKey: "AppleActionOnDoubleClick") {
|
||||
case "Minimize": miniaturize(nil)
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import Cocoa
|
||||
import FlutterMacOS
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
final class NativeFilePickerBridge {
|
||||
private weak var view: NSView?
|
||||
private var activePanel: NSOpenPanel?
|
||||
private let makePanel: () -> NSOpenPanel
|
||||
|
||||
init(view: NSView, makePanel: @escaping () -> NSOpenPanel = { NSOpenPanel() }) {
|
||||
self.view = view
|
||||
self.makePanel = makePanel
|
||||
}
|
||||
|
||||
func pickFiles(arguments: Any?, result: @escaping FlutterResult) {
|
||||
DispatchQueue.main.async { [self] in
|
||||
guard activePanel == nil else {
|
||||
return result(FlutterError(code: "picker_active",
|
||||
message: "A file selection is already open.", details: nil))
|
||||
}
|
||||
guard let window = view?.window else {
|
||||
return result(FlutterError(code: "window_unavailable",
|
||||
message: "The file picker requires a host window.", details: nil))
|
||||
}
|
||||
guard window.attachedSheet == nil else {
|
||||
return result(FlutterError(code: "picker_active",
|
||||
message: "The host window already has an open sheet.", details: nil))
|
||||
}
|
||||
guard let args = arguments as? [String: Any],
|
||||
let extensions = args["allowedExtensions"] as? [String] else {
|
||||
return result(FlutterError(code: "invalid_args",
|
||||
message: "File extensions are required.", details: nil))
|
||||
}
|
||||
let panel = makePanel()
|
||||
panel.canChooseFiles = true
|
||||
panel.canChooseDirectories = false
|
||||
panel.allowsMultipleSelection = true
|
||||
panel.canCreateDirectories = false
|
||||
let types = extensions.compactMap { UTType(filenameExtension: $0) }
|
||||
if !types.isEmpty {
|
||||
panel.allowedContentTypes = types
|
||||
panel.allowsOtherFileTypes = false
|
||||
}
|
||||
activePanel = panel
|
||||
// An owned, asynchronous sheet stays with the editor, including fullscreen,
|
||||
// without entering runModal's nested application event loop.
|
||||
panel.beginSheetModal(for: window) { [self, panel] response in
|
||||
DispatchQueue.main.async { [self, panel] in
|
||||
activePanel = nil
|
||||
result(response == .OK ? panel.urls.map { $0.path } : nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import Cocoa
|
||||
import FlutterMacOS
|
||||
|
||||
final class TestOpenPanel: NSOpenPanel {
|
||||
var owner: NSWindow?
|
||||
var reply: ((NSApplication.ModalResponse) -> Void)?
|
||||
override var urls: [URL] { [URL(fileURLWithPath: "/tmp/a b.mp4")] }
|
||||
override func beginSheetModal(for window: NSWindow,
|
||||
completionHandler handler: @escaping (NSApplication.ModalResponse) -> Void) {
|
||||
owner = window
|
||||
reply = handler
|
||||
}
|
||||
override func runModal() -> NSApplication.ModalResponse {
|
||||
fatalError("The picker must not block the application event loop")
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct FilePickerTest {
|
||||
static func main() {
|
||||
_ = NSApplication.shared
|
||||
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 640, height: 480),
|
||||
styleMask: [.titled], backing: .buffered, defer: false)
|
||||
let view = NSView()
|
||||
window.contentView = view
|
||||
let panel = TestOpenPanel()
|
||||
let picker = NativeFilePickerBridge(view: view, makePanel: { panel })
|
||||
let args = ["allowedExtensions": ["mp4", "wav"]]
|
||||
|
||||
func waitUntil(_ condition: () -> Bool) {
|
||||
let deadline = Date().addingTimeInterval(2)
|
||||
while !condition(), Date() < deadline {
|
||||
RunLoop.current.run(until: Date().addingTimeInterval(0.01))
|
||||
}
|
||||
precondition(condition(), "The asynchronous picker did not respond")
|
||||
}
|
||||
|
||||
var replies = 0
|
||||
var selected: [String]?
|
||||
picker.pickFiles(arguments: args) { result in
|
||||
replies += 1
|
||||
selected = result as? [String]
|
||||
}
|
||||
waitUntil { panel.reply != nil }
|
||||
precondition(panel.owner === window && replies == 0)
|
||||
precondition(panel.canChooseFiles && !panel.canChooseDirectories)
|
||||
precondition(panel.allowsMultipleSelection && !panel.allowedContentTypes.isEmpty)
|
||||
var duplicateError: FlutterError?
|
||||
picker.pickFiles(arguments: args) { duplicateError = $0 as? FlutterError }
|
||||
waitUntil { duplicateError != nil }
|
||||
precondition(duplicateError?.code == "picker_active" && replies == 0)
|
||||
// Completion may arrive from AppKit off the main queue.
|
||||
let reply = panel.reply!
|
||||
DispatchQueue.global().async { reply(.OK) }
|
||||
waitUntil { replies == 1 }
|
||||
precondition(selected == ["/tmp/a b.mp4"])
|
||||
|
||||
panel.reply = nil
|
||||
picker.pickFiles(arguments: args) { result in
|
||||
precondition(Thread.isMainThread && result == nil)
|
||||
replies += 1
|
||||
}
|
||||
waitUntil { panel.reply != nil }
|
||||
panel.reply?(.cancel)
|
||||
waitUntil { replies == 2 }
|
||||
|
||||
let detached = NSView()
|
||||
let orphanPicker = NativeFilePickerBridge(view: detached)
|
||||
var missingWindowError: FlutterError?
|
||||
orphanPicker.pickFiles(arguments: args) { missingWindowError = $0 as? FlutterError }
|
||||
waitUntil { missingWindowError != nil }
|
||||
precondition(missingWindowError?.code == "window_unavailable")
|
||||
print("Native file picker ownership, asynchronous completion, cancellation and busy guards passed")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
task_root=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
task_workspace_root=$(cd "$task_root/../.." && pwd)
|
||||
task_framework_dir=${1:-"$task_workspace_root/build/macos/Build/Products/Debug-development"}
|
||||
task_test_dir=$(mktemp -d)
|
||||
trap 'rm -rf "$task_test_dir"' EXIT HUP INT TERM
|
||||
|
||||
xcrun swiftc -F "$task_framework_dir" -framework FlutterMacOS -framework Cocoa \
|
||||
-Xlinker -rpath -Xlinker "$task_framework_dir" \
|
||||
"$task_root/macos/cutdex_native/Sources/cutdex_native/NativeFilePickerBridge.swift" \
|
||||
"$task_root/tool/macos/file_picker_test.swift" \
|
||||
-o "$task_test_dir/file-picker"
|
||||
"$task_test_dir/file-picker"
|
||||
@@ -4,7 +4,8 @@ Cutdex workspace 内部 Flutter 包,维护通用组件与基础视觉主题,
|
||||
|
||||
- `theme.dart`:主题、语义颜色、间距与控件尺寸。
|
||||
- `widgets.dart`:菜单、选择框、对话框、输入控件、标签页、面板、下载进度、滚动渐隐等。
|
||||
- `cutdex_ui.dart`:上述两个入口。
|
||||
- `icons.dart`:`AppIcons` 及 Phosphor Regular、Fill 静态图标目录。
|
||||
- `cutdex_ui.dart`:上述三个入口。
|
||||
|
||||
组件通过参数接收文本、数据与回调;应用本地化与项目状态由调用方提供。选择框的空列表文案使用 `emptyLabel`,可搜索选择框同时传入 `searchHint`。对话框默认关闭提示由 Flutter 的 Material 本地化提供,也可传入 `closeLabel`。
|
||||
|
||||
@@ -12,6 +13,8 @@ Cutdex workspace 内部 Flutter 包,维护通用组件与基础视觉主题,
|
||||
|
||||
原生菜单通过 `cutdex_native` 展示,无法展示时回退到 Flutter 菜单。时间线与编辑器的业务样式由应用维护。
|
||||
|
||||
桌面入口通过 `AppTheme.desktopWorkspaceTheme` 应用 `DesktopControlDensity`,使用 `AppDesktopMetrics` 中的按钮、输入框、面板标题与播放栏尺寸。移动端不继承这套密度。`AppCommandToolbar` 接收分组命令及固定的右侧命令,空间不足时将次要操作收入更多菜单;预览位于 `app_command_toolbar_previews.dart`。
|
||||
|
||||
在应用根目录执行 `fvm dart tool/flutter_local.dart pub get`;在本包目录执行:
|
||||
|
||||
```sh
|
||||
@@ -20,3 +23,41 @@ python3 ../../tool/project_tools.py flutter test
|
||||
```
|
||||
|
||||
生成的 Freezed 文件随源码提交。测试维护在本包 `test/`,应用接线测试保留在应用中。
|
||||
|
||||
## 图标
|
||||
|
||||
图标使用随包打包的 Phosphor 官方字体,由 Flutter `Icon` 渲染,无第三方图标包依赖。
|
||||
应用与共享组件优先使用 `AppIcons`,默认 Regular;填充图标使用显式的 `Filled` 名称。
|
||||
|
||||
```dart
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
|
||||
const Icon(AppIcons.search);
|
||||
const Icon(AppIcons.folderFilled);
|
||||
```
|
||||
|
||||
需要新增项目图标时,在 `lib/src/icons/app_icons.dart` 增加语义映射。完整目录通过
|
||||
`PhosphorIconsRegular` 与 `PhosphorIconsFill` 提供,例如
|
||||
`PhosphorIconsRegular.filmStrip`。颜色、尺寸及无障碍标签使用 `Icon` 的参数,或由
|
||||
`IconTheme` 继承。左右导航箭头和尖括号随 RTL 镜像,播放、撤销/重做及品牌图标保持原方向。
|
||||
|
||||
两套样式使用独立字体族,不能通过 `fontWeight` 在 Regular 与 Fill 之间切换。
|
||||
图标定义均为 `static const IconData`,支持 Flutter release 构建的字体裁剪;不要在运行时
|
||||
用 codepoint 创建图标。当前不包含 Duotone。
|
||||
|
||||
资源来自 [Phosphor web](https://github.com/phosphor-icons/web) 2.1.2,固定提交
|
||||
`3d40a3eaa73b25d20d263f0e1e55c9fed3e66809`。来源路径、字体及原始映射 SHA-256
|
||||
保存在 `tool/phosphor/catalog.json`,MIT 许可证随资源打包在
|
||||
`assets/fonts/PHOSPHOR_LICENSE.txt`。
|
||||
|
||||
在本包目录执行以下命令,生成过程只依赖 Python 标准库,不联网:
|
||||
|
||||
```sh
|
||||
python3 tool/generate_icons.py
|
||||
python3 tool/generate_icons.py --check
|
||||
```
|
||||
|
||||
升级时选定上游完整提交 SHA,并执行 `python3 tool/generate_icons.py --update <COMMIT_SHA>`。
|
||||
脚本从同一提交下载 Regular、Fill 字体及映射,保留上游别名,验证两套目录一致,再生成
|
||||
Dart 常量。字体、目录快照、生成代码和许可证一起提交。升级后运行图标测试及一次带字体
|
||||
裁剪的 release 构建,确认资源可加载、图形正确。
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2021 Phosphor Icons
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,3 @@
|
||||
export 'icons.dart';
|
||||
export 'theme.dart';
|
||||
export 'widgets.dart';
|
||||
@@ -0,0 +1,2 @@
|
||||
export 'src/icons/app_icons.dart';
|
||||
export 'src/icons/phosphor_icons.g.dart';
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'phosphor_icons.g.dart';
|
||||
|
||||
/// Shared Cutdex icons, using Regular by default and explicit Fill variants.
|
||||
@staticIconProvider
|
||||
abstract final class AppIcons {
|
||||
static const IconData close = PhosphorIconsRegular.x;
|
||||
static const IconData check = PhosphorIconsRegular.check;
|
||||
static const IconData add = PhosphorIconsRegular.plus;
|
||||
static const IconData remove = PhosphorIconsRegular.minus;
|
||||
static const IconData search = PhosphorIconsRegular.magnifyingGlass;
|
||||
static const IconData settings = PhosphorIconsRegular.gear;
|
||||
static const IconData appearance = PhosphorIconsRegular.palette;
|
||||
static const IconData more = PhosphorIconsRegular.dotsThree;
|
||||
static const IconData expandMore = PhosphorIconsRegular.caretDown;
|
||||
static const IconData expandLess = PhosphorIconsRegular.caretUp;
|
||||
static const IconData chevronLeft = PhosphorIconsRegular.caretLeft;
|
||||
static const IconData chevronRight = PhosphorIconsRegular.caretRight;
|
||||
static const IconData arrowBack = PhosphorIconsRegular.arrowLeft;
|
||||
static const IconData arrowForward = PhosphorIconsRegular.arrowRight;
|
||||
static const IconData arrowUp = PhosphorIconsRegular.arrowUp;
|
||||
static const IconData arrowDown = PhosphorIconsRegular.arrowDown;
|
||||
static const IconData sort = PhosphorIconsRegular.sortAscending;
|
||||
static const IconData play = PhosphorIconsRegular.play;
|
||||
static const IconData pause = PhosphorIconsRegular.pause;
|
||||
static const IconData stop = PhosphorIconsRegular.stop;
|
||||
static const IconData undo = PhosphorIconsRegular.arrowUUpLeft;
|
||||
static const IconData redo = PhosphorIconsRegular.arrowUUpRight;
|
||||
static const IconData refresh = PhosphorIconsRegular.arrowsClockwise;
|
||||
static const IconData reset = PhosphorIconsRegular.arrowCounterClockwise;
|
||||
static const IconData angle = PhosphorIconsRegular.angle;
|
||||
static const IconData seekStart = PhosphorIconsRegular.skipBack;
|
||||
static const IconData previousFrame = PhosphorIconsRegular.caretLineLeft;
|
||||
static const IconData nextFrame = PhosphorIconsRegular.caretLineRight;
|
||||
static const IconData cut = PhosphorIconsRegular.scissors;
|
||||
static const IconData delete = PhosphorIconsRegular.trash;
|
||||
static const IconData edit = PhosphorIconsRegular.pencilSimple;
|
||||
static const IconData rename = PhosphorIconsRegular.textbox;
|
||||
static const IconData copy = PhosphorIconsRegular.copy;
|
||||
static const IconData folder = PhosphorIconsRegular.folder;
|
||||
static const IconData folderOpen = PhosphorIconsRegular.folderOpen;
|
||||
static const IconData folderUnavailable = PhosphorIconsRegular.folderDashed;
|
||||
static const IconData file = PhosphorIconsRegular.file;
|
||||
static const IconData attachment = PhosphorIconsRegular.paperclip;
|
||||
static const IconData video = PhosphorIconsRegular.filmStrip;
|
||||
static const IconData image = PhosphorIconsRegular.image;
|
||||
static const IconData audio = PhosphorIconsRegular.musicNotes;
|
||||
static const IconData audioFile = PhosphorIconsRegular.fileAudio;
|
||||
static const IconData imageUnavailable = PhosphorIconsRegular.imageBroken;
|
||||
static const IconData mediaLibrary = PhosphorIconsRegular.images;
|
||||
static const IconData videoLibrary = PhosphorIconsRegular.filmReel;
|
||||
static const IconData timeline = PhosphorIconsRegular.rows;
|
||||
static const IconData audioWaveform = PhosphorIconsRegular.waveform;
|
||||
static const IconData removeBackground = PhosphorIconsRegular.userMinus;
|
||||
static const IconData subtitles = PhosphorIconsRegular.subtitles;
|
||||
static const IconData textWrap = PhosphorIconsRegular.arrowElbowDownLeft;
|
||||
static const IconData volume = PhosphorIconsRegular.speakerHigh;
|
||||
static const IconData mute = PhosphorIconsRegular.speakerSlash;
|
||||
static const IconData visible = PhosphorIconsRegular.eye;
|
||||
static const IconData hidden = PhosphorIconsRegular.eyeSlash;
|
||||
static const IconData lock = PhosphorIconsRegular.lock;
|
||||
static const IconData unlock = PhosphorIconsRegular.lockOpen;
|
||||
static const IconData fullscreen = PhosphorIconsRegular.arrowsOut;
|
||||
static const IconData exitFullscreen = PhosphorIconsRegular.arrowsIn;
|
||||
static const IconData fitContent = PhosphorIconsRegular.cornersIn;
|
||||
static const IconData menu = PhosphorIconsRegular.list;
|
||||
static const IconData sidebar = PhosphorIconsRegular.sidebarSimple;
|
||||
static const IconData splitVertical =
|
||||
PhosphorIconsRegular.squareSplitVertical;
|
||||
static const IconData listView = PhosphorIconsRegular.listBullets;
|
||||
static const IconData gridView = PhosphorIconsRegular.squaresFour;
|
||||
static const IconData collapseVertical =
|
||||
PhosphorIconsRegular.arrowsInLineVertical;
|
||||
static const IconData dragHandle = PhosphorIconsRegular.dotsSixVertical;
|
||||
static const IconData windowRestore = PhosphorIconsRegular.copy;
|
||||
static const IconData chat = PhosphorIconsRegular.chatCircle;
|
||||
static const IconData home = PhosphorIconsRegular.house;
|
||||
static const IconData conversations = PhosphorIconsRegular.chatsCircle;
|
||||
static const IconData assistant = PhosphorIconsRegular.sparkle;
|
||||
static const IconData model = PhosphorIconsRegular.brain;
|
||||
static const IconData lightning = PhosphorIconsRegular.lightning;
|
||||
static const IconData terminal = PhosphorIconsRegular.terminalWindow;
|
||||
static const IconData tune = PhosphorIconsRegular.slidersHorizontal;
|
||||
static const IconData error = PhosphorIconsRegular.warningCircle;
|
||||
static const IconData success = PhosphorIconsRegular.checkCircle;
|
||||
static const IconData info = PhosphorIconsRegular.info;
|
||||
static const IconData pin = PhosphorIconsRegular.pushPin;
|
||||
static const IconData pinFilled = PhosphorIconsFill.pushPin;
|
||||
static const IconData square = PhosphorIconsRegular.square;
|
||||
static const IconData squareFilled = PhosphorIconsFill.square;
|
||||
static const IconData circle = PhosphorIconsRegular.circle;
|
||||
static const IconData maskRegion = PhosphorIconsRegular.frameCorners;
|
||||
static const IconData maskIntersect = PhosphorIconsRegular.intersectSquare;
|
||||
static const IconData alignLeft = PhosphorIconsRegular.alignLeft;
|
||||
static const IconData alignRight = PhosphorIconsRegular.alignRight;
|
||||
static const IconData alignHorizontalCenter =
|
||||
PhosphorIconsRegular.alignCenterHorizontal;
|
||||
static const IconData alignTop = PhosphorIconsRegular.alignTop;
|
||||
static const IconData alignBottom = PhosphorIconsRegular.alignBottom;
|
||||
static const IconData alignVerticalCenter =
|
||||
PhosphorIconsRegular.alignCenterVertical;
|
||||
static const IconData download = PhosphorIconsRegular.downloadSimple;
|
||||
static const IconData upload = PhosphorIconsRegular.uploadSimple;
|
||||
static const IconData star = PhosphorIconsRegular.star;
|
||||
static const IconData folderFilled = PhosphorIconsFill.folder;
|
||||
static const IconData starFilled = PhosphorIconsFill.star;
|
||||
static const IconData lockFilled = PhosphorIconsFill.lock;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,2 @@
|
||||
/// Workspace color families, independent of light or dark appearance.
|
||||
enum AppPalette { graphite, violet, teal }
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import 'app_menu.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
@@ -31,6 +32,7 @@ class _AppComboboxState<T> extends State<AppCombobox<T>> {
|
||||
final _focus = FocusNode();
|
||||
final _input = TextEditingController();
|
||||
final _firstOption = GlobalKey();
|
||||
final _menuStorage = PageStorageBucket();
|
||||
String _query = '';
|
||||
|
||||
String get _selectedLabel =>
|
||||
@@ -122,121 +124,146 @@ class _AppComboboxState<T> extends State<AppCombobox<T>> {
|
||||
builder: (context, constraints) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final inputStyle = AppTheme.inputTextStyle(
|
||||
context,
|
||||
style: AppTheme.isDesktop(context)
|
||||
? theme.textTheme.bodyMedium
|
||||
: theme.textTheme.bodyLarge,
|
||||
);
|
||||
final width = constraints.hasBoundedWidth ? constraints.maxWidth : 240.0;
|
||||
final filtered = _filtered;
|
||||
return MenuAnchor(
|
||||
controller: _menu,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
alignmentOffset: const Offset(0, 4),
|
||||
style: AppMenuStyle.selectPanel(context, minWidth: width).copyWith(
|
||||
maximumSize: const WidgetStatePropertyAll(Size(double.infinity, 320)),
|
||||
),
|
||||
onClose: _restore,
|
||||
menuChildren: [
|
||||
if (filtered.isEmpty) AppMenuLabel(widget.emptyLabel),
|
||||
for (var i = 0; i < filtered.length; i++)
|
||||
Builder(
|
||||
key: i == 0 ? _firstOption : null,
|
||||
builder: (_) {
|
||||
final option = filtered[i];
|
||||
return AppMenuItem(
|
||||
label: option.label,
|
||||
selected: option.value == widget.value,
|
||||
selectOption: true,
|
||||
requestFocusOnHover: false,
|
||||
onPressed: widget.onChanged == null || !option.enabled
|
||||
? null
|
||||
: () => widget.onChanged!(option.value),
|
||||
);
|
||||
},
|
||||
return PageStorage(
|
||||
bucket: _menuStorage,
|
||||
child: MenuAnchor(
|
||||
controller: _menu,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
alignmentOffset: const Offset(0, 4),
|
||||
style: AppMenuStyle.selectPanel(context, minWidth: width).copyWith(
|
||||
maximumSize: const WidgetStatePropertyAll(
|
||||
Size(double.infinity, 320),
|
||||
),
|
||||
],
|
||||
child: Semantics(
|
||||
label: widget.label,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
onKeyEvent: _handleKey,
|
||||
child: Opacity(
|
||||
opacity: widget.onChanged == null ? .5 : 1,
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: AppSpacing.compact,
|
||||
end: AppSpacing.tiny,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.comboboxBackground(context),
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
border: Border.all(color: colors.outlineVariant),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .05),
|
||||
offset: const Offset(0, 1),
|
||||
blurRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _input,
|
||||
focusNode: _focus,
|
||||
enabled: widget.onChanged != null,
|
||||
onTap: _open,
|
||||
onTapAlwaysCalled: true,
|
||||
onChanged: (text) {
|
||||
setState(() => _query = text);
|
||||
if (!_menu.isOpen) _menu.open();
|
||||
},
|
||||
style: theme.textTheme.bodyLarge,
|
||||
decoration: InputDecoration(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppControlSize.input - 2,
|
||||
),
|
||||
onClose: _restore,
|
||||
menuChildren: [
|
||||
if (filtered.isEmpty) AppMenuLabel(widget.emptyLabel),
|
||||
for (var i = 0; i < filtered.length; i++)
|
||||
Builder(
|
||||
key: i == 0 ? _firstOption : null,
|
||||
builder: (_) {
|
||||
final option = filtered[i];
|
||||
return AppMenuItem(
|
||||
label: option.label,
|
||||
selected: option.value == widget.value,
|
||||
selectOption: true,
|
||||
requestFocusOnHover: false,
|
||||
onPressed: widget.onChanged == null || !option.enabled
|
||||
? null
|
||||
: () => widget.onChanged!(option.value),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
child: Semantics(
|
||||
label: widget.label,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
onKeyEvent: _handleKey,
|
||||
child: Opacity(
|
||||
opacity: widget.onChanged == null ? .5 : 1,
|
||||
child: Container(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: AppTheme.isDesktop(context)
|
||||
? theme.inputDecorationTheme.constraints?.minHeight ??
|
||||
AppDesktopMetrics.input
|
||||
: AppControlSize.input,
|
||||
),
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: AppSpacing.compact,
|
||||
end: AppSpacing.tiny,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.comboboxBackground(context),
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
border: Border.all(color: colors.outlineVariant),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .05),
|
||||
offset: const Offset(0, 1),
|
||||
blurRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _input,
|
||||
focusNode: _focus,
|
||||
enabled: widget.onChanged != null,
|
||||
onTap: _open,
|
||||
onTapAlwaysCalled: true,
|
||||
onChanged: (text) {
|
||||
setState(() => _query = text);
|
||||
if (!_menu.isOpen) _menu.open();
|
||||
},
|
||||
style: inputStyle,
|
||||
cursorHeight: AppTheme.inputCursorHeight(
|
||||
context,
|
||||
style: inputStyle,
|
||||
),
|
||||
hintText: widget.searchHint,
|
||||
isDense: true,
|
||||
filled: false,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: AppSpacing.inputVertical - 2,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppControlSize.input - 2,
|
||||
),
|
||||
hintText: widget.searchHint,
|
||||
hintStyle: AppTheme.inputHintStyle(
|
||||
context,
|
||||
style: inputStyle,
|
||||
),
|
||||
isDense: true,
|
||||
filled: false,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: AppSpacing.inputVertical - 2,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
focusedErrorBorder: InputBorder.none,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
focusedErrorBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: null,
|
||||
onPressed: widget.onChanged == null
|
||||
? null
|
||||
: () => _menu.isOpen ? _menu.close() : _open(),
|
||||
style: IconButton.styleFrom(
|
||||
overlayColor: Colors.transparent,
|
||||
minimumSize: const Size.square(
|
||||
AppControlSize.input - 2,
|
||||
IconButton(
|
||||
tooltip: null,
|
||||
onPressed: widget.onChanged == null
|
||||
? null
|
||||
: () => _menu.isOpen ? _menu.close() : _open(),
|
||||
style: IconButton.styleFrom(
|
||||
overlayColor: Colors.transparent,
|
||||
minimumSize: const Size.square(
|
||||
AppControlSize.input - 2,
|
||||
),
|
||||
padding: const EdgeInsets.all(
|
||||
AppSpacing.inputVertical,
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
padding: const EdgeInsets.all(
|
||||
AppSpacing.inputVertical,
|
||||
icon: Icon(
|
||||
AppIcons.expandMore,
|
||||
size: 16,
|
||||
color: colors.onSurfaceVariant.withValues(
|
||||
alpha: .5,
|
||||
),
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
icon: Icon(
|
||||
Icons.expand_more,
|
||||
size: 16,
|
||||
color: colors.onSurfaceVariant.withValues(alpha: .5),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'app_menu.dart';
|
||||
import 'app_popover.dart';
|
||||
|
||||
class AppToolbarCommand {
|
||||
const AppToolbarCommand({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.onPressed,
|
||||
this.key,
|
||||
this.semanticLabel,
|
||||
});
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final VoidCallback? onPressed;
|
||||
final Key? key;
|
||||
final String? semanticLabel;
|
||||
}
|
||||
|
||||
/// Keeps primary commands and view controls visible when a panel narrows.
|
||||
class AppCommandToolbar extends StatelessWidget {
|
||||
const AppCommandToolbar({
|
||||
super.key,
|
||||
required this.groups,
|
||||
this.trailing = const [],
|
||||
this.status,
|
||||
});
|
||||
final List<List<AppToolbarCommand>> groups;
|
||||
final List<AppToolbarCommand> trailing;
|
||||
final Widget? status;
|
||||
|
||||
Widget _button(AppToolbarCommand command) => IconButton(
|
||||
key: command.key,
|
||||
tooltip: command.label,
|
||||
onPressed: command.onPressed,
|
||||
icon: Icon(command.icon, semanticLabel: command.semanticLabel, size: 16),
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(AppDesktopMetrics.iconButton),
|
||||
minimumSize: const Size.square(AppDesktopMetrics.iconButton),
|
||||
maximumSize: const Size.square(AppDesktopMetrics.iconButton),
|
||||
padding: EdgeInsets.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(AppRadius.small)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final commands = groups.expand((group) => group).toList();
|
||||
final reserved = trailing.length * 32 + (status == null ? 0 : 24);
|
||||
final groupSpace = (groups.length - 1).clamp(0, groups.length) * 16;
|
||||
final allFit =
|
||||
constraints.maxWidth >= commands.length * 32 + groupSpace + reserved;
|
||||
final visibleCount = allFit
|
||||
? commands.length
|
||||
: ((constraints.maxWidth - reserved - groupSpace - 36) / 32)
|
||||
.floor()
|
||||
.clamp(0, commands.length);
|
||||
final hidden = commands.skip(visibleCount).toList();
|
||||
var index = 0;
|
||||
return Row(
|
||||
children: [
|
||||
for (final group in groups) ...[
|
||||
if (index > 0 && index < visibleCount)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: SizedBox(height: 16, child: VerticalDivider(width: 1)),
|
||||
),
|
||||
for (final command in group)
|
||||
if (index++ < visibleCount) ...[
|
||||
_button(command),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
],
|
||||
if (hidden.isNotEmpty)
|
||||
AppPopover(
|
||||
width: 240,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final command in hidden)
|
||||
AppMenuItem(
|
||||
label: command.label,
|
||||
icon: command.icon,
|
||||
onPressed: command.onPressed,
|
||||
),
|
||||
],
|
||||
),
|
||||
builder: (context, toggle) => _button(
|
||||
AppToolbarCommand(
|
||||
key: const Key('toolbar-overflow'),
|
||||
label: MaterialLocalizations.of(context).moreButtonTooltip,
|
||||
icon: AppIcons.more,
|
||||
onPressed: toggle,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
for (final command in trailing) _button(command),
|
||||
?status,
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'app_command_toolbar.dart';
|
||||
|
||||
@Preview(
|
||||
name: 'Timeline commands — light',
|
||||
group: 'Desktop workspace',
|
||||
size: Size(480, 36),
|
||||
)
|
||||
Widget desktopTimelineToolbarLightPreview() =>
|
||||
_toolbarPreview(Brightness.light);
|
||||
|
||||
@Preview(
|
||||
name: 'Timeline commands — dark',
|
||||
group: 'Desktop workspace',
|
||||
size: Size(480, 36),
|
||||
)
|
||||
@Preview(
|
||||
name: 'Narrow timeline commands',
|
||||
group: 'Desktop workspace',
|
||||
size: Size(180, 36),
|
||||
)
|
||||
Widget desktopTimelineToolbarPreview() => _toolbarPreview(Brightness.dark);
|
||||
|
||||
Widget _toolbarPreview(Brightness brightness) => MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
home: Scaffold(body: desktopTimelineCommands()),
|
||||
);
|
||||
|
||||
Widget desktopTimelineCommands() => Material(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: AppCommandToolbar(
|
||||
groups: [
|
||||
[
|
||||
AppToolbarCommand(
|
||||
label: 'Undo',
|
||||
icon: AppIcons.undo,
|
||||
onPressed: () {},
|
||||
),
|
||||
const AppToolbarCommand(
|
||||
label: 'Redo',
|
||||
icon: AppIcons.redo,
|
||||
onPressed: null,
|
||||
),
|
||||
],
|
||||
[
|
||||
AppToolbarCommand(
|
||||
label: 'Split',
|
||||
icon: AppIcons.cut,
|
||||
onPressed: () {},
|
||||
),
|
||||
AppToolbarCommand(
|
||||
label: 'Trim left',
|
||||
icon: AppIcons.alignLeft,
|
||||
onPressed: () {},
|
||||
),
|
||||
AppToolbarCommand(
|
||||
label: 'Trim right',
|
||||
icon: AppIcons.alignRight,
|
||||
onPressed: () {},
|
||||
),
|
||||
AppToolbarCommand(
|
||||
label: 'Delete',
|
||||
icon: AppIcons.delete,
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
],
|
||||
trailing: [
|
||||
AppToolbarCommand(
|
||||
label: 'Fit timeline',
|
||||
icon: AppIcons.fitContent,
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
Future<T?> showAppDialog<T>({
|
||||
@@ -307,7 +308,10 @@ class AppDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
icon: const Icon(Icons.close, size: AppIconSize.header),
|
||||
icon: const Icon(
|
||||
AppIcons.close,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// A rounded, non-modal dialog surface positioned by its parent.
|
||||
class AppFloatingDialog extends StatelessWidget {
|
||||
const AppFloatingDialog({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.backgroundColor,
|
||||
this.shape,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final Color? backgroundColor;
|
||||
final ShapeBorder? shape;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final background =
|
||||
backgroundColor ??
|
||||
theme.dialogTheme.backgroundColor ??
|
||||
theme.colorScheme.surfaceContainer;
|
||||
return Theme(
|
||||
data: theme.copyWith(
|
||||
canvasColor: background,
|
||||
colorScheme: theme.colorScheme.copyWith(surface: background),
|
||||
),
|
||||
child: Material(
|
||||
color: background,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
elevation: 8,
|
||||
shadowColor: theme.colorScheme.shadow,
|
||||
shape:
|
||||
shape ??
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.dialog),
|
||||
side: BorderSide(
|
||||
color: theme.dividerColor,
|
||||
width: theme.dividerTheme.thickness ?? 1,
|
||||
),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'app_floating_dialog.dart';
|
||||
|
||||
@Preview(name: 'Floating input — light', group: 'Dialogs', size: Size(600, 140))
|
||||
Widget floatingInputLightPreview() => _inputPreview(AppTheme.penLight);
|
||||
|
||||
@Preview(name: 'Floating input — dark', group: 'Dialogs', size: Size(600, 140))
|
||||
Widget floatingInputDarkPreview() => _inputPreview(AppTheme.penDark);
|
||||
|
||||
Widget _inputPreview(ThemeData theme) => MaterialApp(
|
||||
theme: theme,
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 560,
|
||||
child: AppFloatingDialog(
|
||||
shape: const StadiumBorder(),
|
||||
backgroundColor: theme.extension<AppSurfaces>()!.composerBackground,
|
||||
child: Builder(
|
||||
builder: (context) => Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.small),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
style: _controlStyle(),
|
||||
onPressed: () {},
|
||||
icon: const Icon(AppIcons.add),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
minLines: 1,
|
||||
maxLines: 1,
|
||||
style: AppTheme.composerTextStyle(context),
|
||||
cursorHeight: AppTheme.composerCursorHeight(context),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: AppTheme.composerInputDecoration.copyWith(
|
||||
hintText: 'Message Agent…',
|
||||
hintStyle: AppTheme.composerHintStyle(context),
|
||||
isDense: true,
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppControlSize.headerButton,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
vertical: AppSpacing.tiny,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
style: _controlStyle(),
|
||||
onPressed: () {},
|
||||
icon: const Icon(AppIcons.model),
|
||||
),
|
||||
IconButton.filled(
|
||||
style: AppTheme.accentIconButtonStyle(context)
|
||||
.merge(_controlStyle()),
|
||||
onPressed: () {},
|
||||
icon: const Icon(AppIcons.arrowUp),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ButtonStyle _controlStyle() => IconButton.styleFrom(
|
||||
minimumSize: const Size.square(AppControlSize.headerButton),
|
||||
maximumSize: const Size.square(AppControlSize.headerButton),
|
||||
fixedSize: const Size.square(AppControlSize.headerButton),
|
||||
iconSize: AppIconSize.header,
|
||||
padding: EdgeInsets.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
);
|
||||
@@ -2,10 +2,12 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/menu_metrics.dart';
|
||||
import 'native_context_menu.dart';
|
||||
import 'app_combobox.dart';
|
||||
import 'menu_trigger_focus.dart';
|
||||
|
||||
part 'app_menu.freezed.dart';
|
||||
|
||||
@@ -203,7 +205,7 @@ class _AppMenuItemState extends State<AppMenuItem> {
|
||||
? null
|
||||
: SizedBox.square(
|
||||
dimension: AppMenuMetrics.iconSize,
|
||||
child: widget.selected! ? const Icon(Icons.check) : null,
|
||||
child: widget.selected! ? const Icon(AppIcons.check) : null,
|
||||
),
|
||||
child: widget.selectOption
|
||||
? Row(
|
||||
@@ -219,7 +221,7 @@ class _AppMenuItemState extends State<AppMenuItem> {
|
||||
SizedBox.square(
|
||||
dimension: 16,
|
||||
child: widget.selected == true
|
||||
? const Icon(Icons.check, size: 16)
|
||||
? const Icon(AppIcons.check, size: 16)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
@@ -261,7 +263,7 @@ class AppMenuSeparator extends StatelessWidget {
|
||||
horizontal: AppMenuMetrics.iconGap,
|
||||
vertical: AppMenuMetrics.separatorVerticalPadding,
|
||||
),
|
||||
child: Divider(height: 1, thickness: 1),
|
||||
child: Divider(height: 1),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -335,53 +337,67 @@ class AppDropdownMenu extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AppDropdownMenuState extends State<AppDropdownMenu> {
|
||||
final _focus = FocusNode();
|
||||
final _controller = MenuController();
|
||||
late final _triggerFocus = MenuTriggerFocus(controller: _controller);
|
||||
FocusNode get _focus => _triggerFocus.node;
|
||||
final _entryKey = GlobalKey();
|
||||
// MenuAnchor owns a scroll view. Do not let its offset read or overwrite
|
||||
// an enclosing inspector's expansion state or scroll position.
|
||||
final _menuStorage = PageStorageBucket();
|
||||
@override
|
||||
void dispose() {
|
||||
_focus.dispose();
|
||||
_triggerFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => MenuAnchor(
|
||||
controller: _controller,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: true,
|
||||
crossAxisUnconstrained: widget.crossAxisUnconstrained,
|
||||
alignmentOffset: widget.alignmentOffset,
|
||||
style:
|
||||
(widget.menuStyle ??
|
||||
AppMenuStyle.panel(context, minWidth: widget.minWidth))
|
||||
.copyWith(
|
||||
maximumSize: widget.maxHeight == null
|
||||
? null
|
||||
: WidgetStatePropertyAll(
|
||||
Size(double.infinity, widget.maxHeight!),
|
||||
),
|
||||
),
|
||||
onClose: widget.onClose,
|
||||
onOpen: () => _focusMenu(_entryKey),
|
||||
menuChildren: [
|
||||
for (var i = 0; i < widget.items.length; i++)
|
||||
if (i == 0)
|
||||
Builder(key: _entryKey, builder: (_) => widget.items[i])
|
||||
else
|
||||
widget.items[i],
|
||||
],
|
||||
builder: (context, controller, _) => Shortcuts(
|
||||
shortcuts: const {
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown): ActivateIntent(),
|
||||
Widget build(BuildContext context) => PageStorage(
|
||||
bucket: _menuStorage,
|
||||
child: MenuAnchor(
|
||||
controller: _controller,
|
||||
childFocusNode: _focus,
|
||||
// Close on outside clicks without swallowing the target control's action.
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: widget.crossAxisUnconstrained,
|
||||
alignmentOffset: widget.alignmentOffset,
|
||||
style:
|
||||
(widget.menuStyle ??
|
||||
AppMenuStyle.panel(context, minWidth: widget.minWidth))
|
||||
.copyWith(
|
||||
maximumSize: widget.maxHeight == null
|
||||
? null
|
||||
: WidgetStatePropertyAll(
|
||||
Size(double.infinity, widget.maxHeight!),
|
||||
),
|
||||
),
|
||||
onClose: () {
|
||||
_triggerFocus.onClose();
|
||||
widget.onClose?.call();
|
||||
},
|
||||
child: widget.builder(
|
||||
context,
|
||||
!widget.enabled
|
||||
? null
|
||||
: () {
|
||||
controller.isOpen ? controller.close() : controller.open();
|
||||
},
|
||||
_focus,
|
||||
onOpen: () {
|
||||
_triggerFocus.onOpen();
|
||||
_focusMenu(_entryKey);
|
||||
},
|
||||
menuChildren: [
|
||||
for (var i = 0; i < widget.items.length; i++)
|
||||
if (i == 0)
|
||||
Builder(key: _entryKey, builder: (_) => widget.items[i])
|
||||
else
|
||||
widget.items[i],
|
||||
],
|
||||
builder: (context, controller, _) => Shortcuts(
|
||||
shortcuts: const {
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown): ActivateIntent(),
|
||||
},
|
||||
child: widget.builder(
|
||||
context,
|
||||
!widget.enabled
|
||||
? null
|
||||
: () {
|
||||
controller.isOpen ? controller.close() : controller.open();
|
||||
},
|
||||
_focus,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -495,9 +511,18 @@ class AppSelect<T> extends StatelessWidget {
|
||||
: Size.fromHeight(controlHeight!),
|
||||
minimumSize: Size(
|
||||
0,
|
||||
outlined
|
||||
? AppControlSize.input
|
||||
: AppControlSize.small,
|
||||
controlHeight ??
|
||||
(AppTheme.isDesktop(context)
|
||||
? outlined
|
||||
? theme
|
||||
.inputDecorationTheme
|
||||
.constraints
|
||||
?.minHeight ??
|
||||
AppDesktopMetrics.input
|
||||
: AppDesktopMetrics.iconButton
|
||||
: outlined
|
||||
? AppControlSize.input
|
||||
: AppControlSize.small),
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -530,7 +555,7 @@ class AppSelect<T> extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
Icon(
|
||||
Icons.expand_more,
|
||||
AppIcons.expandMore,
|
||||
size: 16,
|
||||
color: colors.onSurfaceVariant.withValues(
|
||||
alpha: .5,
|
||||
@@ -563,6 +588,7 @@ class _AppContextMenuState extends State<AppContextMenu> {
|
||||
final _controller = MenuController();
|
||||
final _focus = FocusNode();
|
||||
final _entryKey = GlobalKey();
|
||||
final _menuStorage = PageStorageBucket();
|
||||
Offset _anchorPosition = Offset.zero;
|
||||
bool _focusFirstItem = false;
|
||||
bool _opening = false;
|
||||
@@ -640,17 +666,22 @@ class _AppContextMenuState extends State<AppContextMenu> {
|
||||
Positioned(
|
||||
left: _anchorPosition.dx,
|
||||
top: _anchorPosition.dy,
|
||||
child: MenuAnchor(
|
||||
controller: _controller,
|
||||
childFocusNode: _focus,
|
||||
consumeOutsideTap: true,
|
||||
crossAxisUnconstrained: false,
|
||||
style: AppMenuStyle.panel(context),
|
||||
onOpen: () {
|
||||
if (_focusFirstItem) _focusMenu(_entryKey);
|
||||
},
|
||||
menuChildren: _items(context),
|
||||
child: const IgnorePointer(child: SizedBox.square(dimension: 1)),
|
||||
child: PageStorage(
|
||||
bucket: _menuStorage,
|
||||
child: MenuAnchor(
|
||||
controller: _controller,
|
||||
childFocusNode: _focus,
|
||||
// Nested anchors share their parent's open state. Consuming an
|
||||
// outside tap here would also block clicks outside that parent.
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
style: AppMenuStyle.panel(context),
|
||||
onOpen: () {
|
||||
if (_focusFirstItem) _focusMenu(_entryKey);
|
||||
},
|
||||
menuChildren: _items(context),
|
||||
child: const IgnorePointer(child: SizedBox.square(dimension: 1)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/menu_metrics.dart';
|
||||
import 'menu_trigger_focus.dart';
|
||||
|
||||
/// Anchored shadcn-style surface, dismissed outside or with Escape.
|
||||
class AppPopover extends StatefulWidget {
|
||||
@@ -39,6 +40,18 @@ class AppPopover extends StatefulWidget {
|
||||
|
||||
class _AppPopoverState extends State<AppPopover> {
|
||||
final _menu = MenuController();
|
||||
final _triggerScope = FocusScopeNode();
|
||||
late final _triggerFocus = MenuTriggerFocus(
|
||||
controller: _menu,
|
||||
node: _triggerScope,
|
||||
);
|
||||
final _menuStorage = PageStorageBucket();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_triggerFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _toggle() {
|
||||
if (!widget.enabled) return;
|
||||
@@ -65,90 +78,100 @@ class _AppPopoverState extends State<AppPopover> {
|
||||
);
|
||||
final endAligned = widget.alignment == AlignmentDirectional.bottomEnd;
|
||||
final direction = Directionality.of(context);
|
||||
return MenuAnchor(
|
||||
controller: _menu,
|
||||
alignmentOffset: Offset(
|
||||
endAligned
|
||||
? (direction == TextDirection.ltr ? -surfaceWidth : surfaceWidth)
|
||||
: 0,
|
||||
4,
|
||||
),
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
clipBehavior: Clip.none,
|
||||
style: MenuStyle(
|
||||
alignment: widget.alignment,
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
backgroundColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shadowColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
// The inner surface owns the border; do not inherit MenuTheme's stroke.
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
return PageStorage(
|
||||
bucket: _menuStorage,
|
||||
child: MenuAnchor(
|
||||
controller: _menu,
|
||||
childFocusNode: _triggerScope,
|
||||
onOpen: _triggerFocus.onOpen,
|
||||
onClose: _triggerFocus.onClose,
|
||||
alignmentOffset: Offset(
|
||||
endAligned
|
||||
? (direction == TextDirection.ltr ? -surfaceWidth : surfaceWidth)
|
||||
: 0,
|
||||
4,
|
||||
),
|
||||
consumeOutsideTap: false,
|
||||
crossAxisUnconstrained: false,
|
||||
clipBehavior: Clip.none,
|
||||
style: MenuStyle(
|
||||
alignment: widget.alignment,
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
|
||||
backgroundColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shadowColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
// The inner surface owns the border; do not inherit MenuTheme's stroke.
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
menuChildren: [
|
||||
SizedBox(
|
||||
key: widget.surfaceKey,
|
||||
width: surfaceWidth,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
widget.backgroundColor ?? AppTheme.popoverBackground(context),
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
border: Border.all(
|
||||
color: colors.outlineVariant,
|
||||
width: AppMenuMetrics.borderWidth,
|
||||
menuChildren: [
|
||||
SizedBox(
|
||||
key: widget.surfaceKey,
|
||||
width: surfaceWidth,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
widget.backgroundColor ??
|
||||
AppTheme.popoverBackground(context),
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
border: Border.all(
|
||||
color: colors.outlineVariant,
|
||||
width: AppMenuMetrics.borderWidth,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 4),
|
||||
blurRadius: 6,
|
||||
spreadRadius: -1,
|
||||
),
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 2),
|
||||
blurRadius: 4,
|
||||
spreadRadius: -2,
|
||||
),
|
||||
],
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 4),
|
||||
blurRadius: 6,
|
||||
spreadRadius: -1,
|
||||
),
|
||||
BoxShadow(
|
||||
color: colors.shadow.withValues(alpha: .1),
|
||||
offset: const Offset(0, 2),
|
||||
blurRadius: 4,
|
||||
spreadRadius: -2,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: math.max(
|
||||
0,
|
||||
math.min(widget.maxHeight, viewport.height - 96),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: math.max(
|
||||
0,
|
||||
math.min(widget.maxHeight, viewport.height - 96),
|
||||
),
|
||||
),
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: (_, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
_menu.close();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: (_, event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
_menu.close();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
builder: (context, _, _) => FocusScope(
|
||||
node: _triggerScope,
|
||||
child: widget.builder(context, _toggle),
|
||||
),
|
||||
],
|
||||
builder: (context, _, _) => widget.builder(context, _toggle),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// An inspector property title, its actions, and the controls below it.
|
||||
class AppPropertyGroup extends StatelessWidget {
|
||||
const AppPropertyGroup({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.child,
|
||||
this.labelWidget,
|
||||
this.actions = const [],
|
||||
});
|
||||
|
||||
final String label;
|
||||
final Widget? labelWidget;
|
||||
final List<Widget> actions;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: AppTheme.isDesktop(context)
|
||||
? AppInspectorMetrics.action
|
||||
: AppControlSize.propertyControl,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child:
|
||||
labelWidget ??
|
||||
Text(
|
||||
label,
|
||||
style: AppTheme.propertySectionTitleStyle(context),
|
||||
),
|
||||
),
|
||||
for (final action in actions) ...[
|
||||
SizedBox(width: AppTheme.propertyRowGap(context)),
|
||||
action,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: AppTheme.propertyRowGap(context)),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'app_property_group.dart';
|
||||
import 'app_text_field.dart';
|
||||
|
||||
@Preview(
|
||||
name: 'Property groups — light',
|
||||
group: 'Desktop inspector',
|
||||
size: Size(280, 240),
|
||||
)
|
||||
Widget propertyGroupsLightPreview() => _preview(Brightness.light);
|
||||
|
||||
@Preview(
|
||||
name: 'Property groups — dark',
|
||||
group: 'Desktop inspector',
|
||||
size: Size(280, 240),
|
||||
)
|
||||
@Preview(
|
||||
name: 'Narrow property groups',
|
||||
group: 'Desktop inspector',
|
||||
size: Size(220, 240),
|
||||
)
|
||||
Widget propertyGroupsDarkPreview() => _preview(Brightness.dark);
|
||||
|
||||
Widget _preview(Brightness brightness) => MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
),
|
||||
home: const Scaffold(body: _PropertyGroupsPreview()),
|
||||
);
|
||||
|
||||
class _PropertyGroupsPreview extends StatefulWidget {
|
||||
const _PropertyGroupsPreview();
|
||||
@override
|
||||
State<_PropertyGroupsPreview> createState() => _PropertyGroupsPreviewState();
|
||||
}
|
||||
|
||||
class _PropertyGroupsPreviewState extends State<_PropertyGroupsPreview> {
|
||||
final _values = [
|
||||
TextEditingController(text: '0'),
|
||||
TextEditingController(text: '0'),
|
||||
TextEditingController(text: '100'),
|
||||
TextEditingController(text: '100'),
|
||||
TextEditingController(text: '0'),
|
||||
];
|
||||
bool _locked = true;
|
||||
final _keyed = <int>{};
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final value in _values) {
|
||||
value.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _keyframe(int channel) => IconButton(
|
||||
tooltip: 'Toggle keyframe',
|
||||
isSelected: _keyed.contains(channel),
|
||||
icon: const Icon(AppIcons.square, size: 12),
|
||||
onPressed: () => setState(() {
|
||||
if (!_keyed.add(channel)) _keyed.remove(channel);
|
||||
}),
|
||||
);
|
||||
|
||||
Widget _pair(String a, String b, int index, {String? unit}) => Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppTextField(label: a, unit: unit, controller: _values[index]),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: AppTextField(
|
||||
label: b,
|
||||
unit: unit,
|
||||
controller: _values[index + 1],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
for (final group in [
|
||||
AppPropertyGroup(
|
||||
label: '位置',
|
||||
actions: [_keyframe(0)],
|
||||
child: _pair('X', 'Y', 0),
|
||||
),
|
||||
AppPropertyGroup(
|
||||
label: '缩放',
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'Lock aspect ratio',
|
||||
isSelected: _locked,
|
||||
icon: const Icon(AppIcons.unlock),
|
||||
selectedIcon: const Icon(AppIcons.lockFilled),
|
||||
onPressed: () => setState(() => _locked = !_locked),
|
||||
),
|
||||
_keyframe(1),
|
||||
],
|
||||
child: _pair('W', 'H', 2, unit: '%'),
|
||||
),
|
||||
AppPropertyGroup(
|
||||
label: '旋转',
|
||||
actions: [_keyframe(2)],
|
||||
child: AppTextField(
|
||||
label: '旋转',
|
||||
leading: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Icon(AppIcons.angle, size: 14),
|
||||
),
|
||||
unit: '°',
|
||||
controller: _values[4],
|
||||
),
|
||||
),
|
||||
])
|
||||
Padding(
|
||||
padding: AppTheme.propertySectionPadding(context),
|
||||
child: group,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -15,9 +15,17 @@ class AppScrubLabel extends StatefulWidget {
|
||||
required this.onUpdate,
|
||||
required this.onEnd,
|
||||
required this.onCancel,
|
||||
this.padding = const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
this.alignment = Alignment.center,
|
||||
this.style,
|
||||
this.icon,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final AlignmentGeometry alignment;
|
||||
final TextStyle? style;
|
||||
final IconData? icon;
|
||||
final bool enabled;
|
||||
final bool Function() onStart;
|
||||
final ValueChanged<double> onUpdate;
|
||||
@@ -104,16 +112,27 @@ class _AppScrubLabelState extends State<AppScrubLabel> {
|
||||
},
|
||||
onHorizontalDragCancel: _cancel,
|
||||
child: Align(
|
||||
alignment: widget.alignment,
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
child: Text(
|
||||
widget.label,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
padding: widget.padding,
|
||||
child: widget.icon == null
|
||||
? Text(
|
||||
widget.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
widget.style ?? AppTheme.propertyLabelStyle(context),
|
||||
)
|
||||
: Icon(
|
||||
widget.icon,
|
||||
size: 14,
|
||||
color:
|
||||
(widget.style ?? AppTheme.propertyLabelStyle(context))
|
||||
.color,
|
||||
semanticLabel: widget.label,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -34,7 +34,11 @@ class AppSlider extends StatelessWidget {
|
||||
final colors = theme.colorScheme;
|
||||
final accent = colors.primary;
|
||||
return SizedBox(
|
||||
height: AppControlSize.standard,
|
||||
height: AppTheme.isCompactInspector(context)
|
||||
? AppInspectorMetrics.input
|
||||
: AppTheme.isDesktop(context)
|
||||
? AppDesktopMetrics.input
|
||||
: AppControlSize.standard,
|
||||
child: SliderTheme(
|
||||
data: SliderTheme.of(context).copyWith(
|
||||
trackHeight: 4,
|
||||
|
||||
@@ -2,14 +2,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
import 'app_property_group.dart';
|
||||
|
||||
/// Shared inline-labelled input built on Flutter's native text editing.
|
||||
/// Native input with inline prefixes and optional property group titles.
|
||||
class AppTextField extends StatefulWidget {
|
||||
const AppTextField({
|
||||
super.key,
|
||||
this.controller,
|
||||
this.focusNode,
|
||||
this.label,
|
||||
this.labelAbove = false,
|
||||
this.labelActions = const [],
|
||||
this.leading,
|
||||
this.unit,
|
||||
this.hintText,
|
||||
@@ -31,6 +34,8 @@ class AppTextField extends StatefulWidget {
|
||||
final TextEditingController? controller;
|
||||
final FocusNode? focusNode;
|
||||
final String? label;
|
||||
final bool labelAbove;
|
||||
final List<Widget> labelActions;
|
||||
final Widget? leading;
|
||||
final String? unit;
|
||||
final String? hintText;
|
||||
@@ -66,132 +71,143 @@ class _AppTextFieldState extends State<AppTextField> {
|
||||
final focusColor = colors.primary;
|
||||
final borderless =
|
||||
theme.inputDecorationTheme.enabledBorder?.borderSide == BorderSide.none;
|
||||
final style = theme.textTheme.bodyMedium!.copyWith(
|
||||
color: foreground,
|
||||
letterSpacing: 0,
|
||||
);
|
||||
final style = AppTheme.inputTextStyle(context)
|
||||
.copyWith(color: foreground, letterSpacing: 0);
|
||||
OutlineInputBorder border(Color color) => OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
borderSide: BorderSide(color: color),
|
||||
);
|
||||
|
||||
final labelAbove =
|
||||
widget.labelAbove && (widget.label != null || widget.leading != null);
|
||||
final input = TextField(
|
||||
controller: widget.controller,
|
||||
focusNode: widget.focusNode,
|
||||
enabled: widget.enabled,
|
||||
readOnly: widget.readOnly,
|
||||
canRequestFocus: widget.canRequestFocus,
|
||||
keyboardType: widget.keyboardType,
|
||||
inputFormatters: widget.inputFormatters,
|
||||
minLines: widget.minLines,
|
||||
maxLines: widget.maxLines,
|
||||
textInputAction: widget.textInputAction,
|
||||
style: style,
|
||||
cursorColor: focusColor,
|
||||
cursorHeight: AppTheme.inputCursorHeight(context),
|
||||
cursorWidth: 1,
|
||||
textAlignVertical: widget.maxLines == 1
|
||||
? TextAlignVertical.center
|
||||
: TextAlignVertical.top,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: theme.inputDecorationTheme.fillColor,
|
||||
hoverColor: Colors.transparent,
|
||||
hintText: widget.hintText,
|
||||
hintStyle: AppTheme.inputHintStyle(context, style: style),
|
||||
errorText: widget.errorText,
|
||||
errorMaxLines: 2,
|
||||
contentPadding:
|
||||
theme.inputDecorationTheme.contentPadding ??
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.controlHorizontal,
|
||||
vertical: AppSpacing.inputVertical,
|
||||
),
|
||||
prefixIcon: labelAbove
|
||||
? null
|
||||
: widget.leading ??
|
||||
(widget.label == null
|
||||
? null
|
||||
: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
widget.label!,
|
||||
style: AppTheme.propertyLabelStyle(context)
|
||||
.copyWith(
|
||||
color: widget.enabled
|
||||
? colors.onSurfaceVariant
|
||||
: foreground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
prefixIconConstraints: const BoxConstraints(
|
||||
minWidth: AppControlSize.standard,
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
suffixIcon: widget.unit == null
|
||||
? null
|
||||
: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
widget.unit!,
|
||||
style: style.copyWith(
|
||||
color: widget.enabled
|
||||
? colors.onSurfaceVariant
|
||||
: foreground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
suffixIconConstraints: const BoxConstraints(
|
||||
minWidth: AppControlSize.compact,
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
border: theme.inputDecorationTheme.border,
|
||||
enabledBorder: borderless
|
||||
? theme.inputDecorationTheme.enabledBorder
|
||||
: border(
|
||||
_hovered
|
||||
? colors.outline
|
||||
: theme
|
||||
.inputDecorationTheme
|
||||
.enabledBorder
|
||||
?.borderSide
|
||||
.color ??
|
||||
colors.outlineVariant,
|
||||
),
|
||||
disabledBorder: theme.inputDecorationTheme.disabledBorder,
|
||||
focusedBorder: theme.inputDecorationTheme.focusedBorder,
|
||||
errorBorder: borderless
|
||||
? theme.inputDecorationTheme.errorBorder
|
||||
: border(colors.error),
|
||||
focusedErrorBorder: borderless
|
||||
? theme.inputDecorationTheme.focusedErrorBorder
|
||||
: border(colors.error),
|
||||
),
|
||||
onChanged: widget.onChanged,
|
||||
onEditingComplete: widget.onEditingComplete,
|
||||
onSubmitted: widget.onSubmitted,
|
||||
onTapOutside: widget.onTapOutside,
|
||||
);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: Semantics(
|
||||
label: [widget.label, widget.unit].whereType<String>().join(' '),
|
||||
child: TextField(
|
||||
controller: widget.controller,
|
||||
focusNode: widget.focusNode,
|
||||
enabled: widget.enabled,
|
||||
readOnly: widget.readOnly,
|
||||
canRequestFocus: widget.canRequestFocus,
|
||||
keyboardType: widget.keyboardType,
|
||||
inputFormatters: widget.inputFormatters,
|
||||
minLines: widget.minLines,
|
||||
maxLines: widget.maxLines,
|
||||
textInputAction: widget.textInputAction,
|
||||
style: style,
|
||||
cursorColor: focusColor,
|
||||
cursorHeight: AppTheme.inputCursorHeight(context),
|
||||
cursorWidth: 1,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: theme.inputDecorationTheme.fillColor,
|
||||
hoverColor: Colors.transparent,
|
||||
hintText: widget.hintText,
|
||||
hintStyle:
|
||||
theme.inputDecorationTheme.hintStyle ??
|
||||
style.copyWith(color: colors.onSurfaceVariant),
|
||||
errorText: widget.errorText,
|
||||
errorMaxLines: 2,
|
||||
contentPadding:
|
||||
theme.inputDecorationTheme.contentPadding ??
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.controlHorizontal,
|
||||
vertical: AppSpacing.inputVertical,
|
||||
),
|
||||
prefixIcon:
|
||||
widget.leading ??
|
||||
(widget.label == null
|
||||
? null
|
||||
: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
widget.label!,
|
||||
style: style.copyWith(
|
||||
color: widget.enabled
|
||||
? colors.onSurfaceVariant
|
||||
: foreground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
prefixIconConstraints: const BoxConstraints(
|
||||
minWidth: AppControlSize.standard,
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
suffixIcon: widget.unit == null
|
||||
? null
|
||||
: Align(
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.small,
|
||||
),
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
widget.unit!,
|
||||
style: style.copyWith(
|
||||
color: widget.enabled
|
||||
? colors.onSurfaceVariant
|
||||
: foreground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
suffixIconConstraints: const BoxConstraints(
|
||||
minWidth: AppControlSize.compact,
|
||||
minHeight: AppControlSize.input,
|
||||
),
|
||||
border: theme.inputDecorationTheme.border,
|
||||
enabledBorder: borderless
|
||||
? theme.inputDecorationTheme.enabledBorder
|
||||
: border(
|
||||
_hovered
|
||||
? colors.outline
|
||||
: theme
|
||||
.inputDecorationTheme
|
||||
.enabledBorder
|
||||
?.borderSide
|
||||
.color ??
|
||||
colors.outlineVariant,
|
||||
),
|
||||
disabledBorder: theme.inputDecorationTheme.disabledBorder,
|
||||
focusedBorder: theme.inputDecorationTheme.focusedBorder,
|
||||
errorBorder: borderless
|
||||
? theme.inputDecorationTheme.errorBorder
|
||||
: border(colors.error),
|
||||
focusedErrorBorder: borderless
|
||||
? theme.inputDecorationTheme.focusedErrorBorder
|
||||
: border(colors.error),
|
||||
),
|
||||
onChanged: widget.onChanged,
|
||||
onEditingComplete: widget.onEditingComplete,
|
||||
onSubmitted: widget.onSubmitted,
|
||||
onTapOutside: widget.onTapOutside,
|
||||
),
|
||||
child: labelAbove
|
||||
? AppPropertyGroup(
|
||||
label: widget.label ?? '',
|
||||
labelWidget: widget.leading,
|
||||
actions: widget.labelActions,
|
||||
child: input,
|
||||
)
|
||||
: input,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,15 @@ class CompactPanelTabs<T> extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SizedBox(
|
||||
height: height,
|
||||
height: AppTheme.isDesktop(context)
|
||||
? AppDesktopMetrics.panelHeader
|
||||
: height,
|
||||
child: Padding(
|
||||
padding: padding,
|
||||
padding:
|
||||
AppTheme.isDesktop(context) &&
|
||||
padding == const EdgeInsets.all(AppSpacing.gap)
|
||||
? const EdgeInsets.symmetric(horizontal: 8, vertical: 4)
|
||||
: padding,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Keeps keyboard focus while releasing a pointer-operated menu's highlight.
|
||||
class MenuTriggerFocus {
|
||||
MenuTriggerFocus({required this.controller, FocusNode? node})
|
||||
: node = node ?? FocusNode();
|
||||
|
||||
final MenuController controller;
|
||||
final FocusNode node;
|
||||
bool _keyboardClose = false;
|
||||
bool _disposed = false;
|
||||
bool _listening = false;
|
||||
|
||||
void onOpen() {
|
||||
_keyboardClose =
|
||||
LogicalKeyboardKey.collapseSynonyms(
|
||||
HardwareKeyboard.instance.logicalKeysPressed,
|
||||
).difference({
|
||||
LogicalKeyboardKey.alt,
|
||||
LogicalKeyboardKey.control,
|
||||
LogicalKeyboardKey.meta,
|
||||
LogicalKeyboardKey.shift,
|
||||
}).isNotEmpty;
|
||||
if (_listening) return;
|
||||
_listening = true;
|
||||
GestureBinding.instance.pointerRouter.addGlobalRoute(_onPointer);
|
||||
HardwareKeyboard.instance.addHandler(_onKey);
|
||||
}
|
||||
|
||||
void _onPointer(PointerEvent event) {
|
||||
if (event is PointerDownEvent) _keyboardClose = false;
|
||||
}
|
||||
|
||||
bool _onKey(KeyEvent event) {
|
||||
if (event is KeyDownEvent) _keyboardClose = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void _stopListening() {
|
||||
if (!_listening) return;
|
||||
_listening = false;
|
||||
GestureBinding.instance.pointerRouter.removeGlobalRoute(_onPointer);
|
||||
HardwareKeyboard.instance.removeHandler(_onKey);
|
||||
}
|
||||
|
||||
void onClose() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// Menu disposal restores focus at the end of the frame. Let that update
|
||||
// and the closing input event finish before clearing pointer focus.
|
||||
scheduleMicrotask(() {
|
||||
if (_disposed || controller.isOpen) return;
|
||||
_stopListening();
|
||||
if (!_keyboardClose && node.hasFocus) node.unfocus();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_stopListening();
|
||||
node.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../icons/app_icons.dart';
|
||||
import '../theme/app_palette.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'app_command_toolbar.dart';
|
||||
|
||||
@Preview(
|
||||
name: 'Rounded timeline tabs — light',
|
||||
group: 'Desktop workspace',
|
||||
size: Size(480, 68),
|
||||
)
|
||||
Widget roundedTimelineControlsLightPreview() => _preview(Brightness.light);
|
||||
|
||||
@Preview(
|
||||
name: 'Rounded timeline tabs — dark',
|
||||
group: 'Desktop workspace',
|
||||
size: Size(480, 68),
|
||||
)
|
||||
@Preview(
|
||||
name: 'Rounded timeline tabs — narrow',
|
||||
group: 'Desktop workspace',
|
||||
size: Size(240, 68),
|
||||
)
|
||||
Widget roundedTimelineControlsDarkPreview() => _preview(Brightness.dark);
|
||||
|
||||
Widget _preview(Brightness brightness) => MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
home: const Scaffold(body: _TimelineControlsPreview()),
|
||||
);
|
||||
|
||||
class _TimelineControlsPreview extends StatefulWidget {
|
||||
const _TimelineControlsPreview();
|
||||
|
||||
@override
|
||||
State<_TimelineControlsPreview> createState() =>
|
||||
_TimelineControlsPreviewState();
|
||||
}
|
||||
|
||||
class _TimelineControlsPreviewState extends State<_TimelineControlsPreview> {
|
||||
final _timelines = ['Main edit', 'Portrait', 'Outtakes'];
|
||||
String _selected = 'Main edit';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
children: [
|
||||
ColoredBox(
|
||||
color: AppTheme.timelineTabsBackground(context),
|
||||
child: SizedBox(
|
||||
height: AppDesktopMetrics.timelineTabs,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.tiny),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (final name in _timelines)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
end: AppSpacing.hairline,
|
||||
),
|
||||
child: Semantics(
|
||||
selected: name == _selected,
|
||||
child: TextButton(
|
||||
style: AppTheme.timelineTabStyle(
|
||||
context,
|
||||
selected: name == _selected,
|
||||
),
|
||||
onPressed: () =>
|
||||
setState(() => _selected = name),
|
||||
child: Text(name),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'New timeline',
|
||||
style: AppTheme.timelineTabActionStyle,
|
||||
onPressed: () => setState(() {
|
||||
final name = 'Timeline ${_timelines.length + 1}';
|
||||
_timelines.add(name);
|
||||
_selected = name;
|
||||
}),
|
||||
icon: const Icon(AppIcons.add, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'All timelines',
|
||||
style: AppTheme.timelineTabActionStyle,
|
||||
onPressed: () {},
|
||||
icon: const Icon(AppIcons.more, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: AppDesktopMetrics.timelineToolbar,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
child: AppCommandToolbar(
|
||||
groups: [
|
||||
[
|
||||
AppToolbarCommand(
|
||||
label: 'Undo',
|
||||
icon: AppIcons.undo,
|
||||
onPressed: () {},
|
||||
),
|
||||
const AppToolbarCommand(
|
||||
label: 'Redo',
|
||||
icon: AppIcons.redo,
|
||||
onPressed: null,
|
||||
),
|
||||
],
|
||||
[
|
||||
for (final command in [
|
||||
('Split', AppIcons.cut),
|
||||
('Trim left', AppIcons.alignLeft),
|
||||
('Trim right', AppIcons.alignRight),
|
||||
('Delete', AppIcons.delete),
|
||||
])
|
||||
AppToolbarCommand(
|
||||
label: command.$1,
|
||||
icon: command.$2,
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
],
|
||||
trailing: [
|
||||
AppToolbarCommand(
|
||||
label: 'Fit timeline',
|
||||
icon: AppIcons.fitContent,
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class WorkspacePanel extends StatelessWidget {
|
||||
required this.child,
|
||||
this.trailing,
|
||||
this.controls,
|
||||
this.headerHeight = AppControlSize.panelHeader,
|
||||
this.headerHeight,
|
||||
this.headerPadding = const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.compact,
|
||||
),
|
||||
@@ -23,7 +23,7 @@ class WorkspacePanel extends StatelessWidget {
|
||||
final Widget child;
|
||||
final Widget? trailing;
|
||||
final Widget? controls;
|
||||
final double headerHeight;
|
||||
final double? headerHeight;
|
||||
final EdgeInsetsGeometry headerPadding;
|
||||
final bool showHeaderDivider;
|
||||
final bool paintBackground;
|
||||
@@ -34,7 +34,11 @@ class WorkspacePanel extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: headerHeight,
|
||||
height:
|
||||
headerHeight ??
|
||||
(AppTheme.isDesktop(context)
|
||||
? AppDesktopMetrics.panelHeader
|
||||
: AppControlSize.panelHeader),
|
||||
child: Padding(
|
||||
padding: headerPadding,
|
||||
child: Row(
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export 'src/theme/app_palette.dart';
|
||||
export 'src/theme/app_theme.dart';
|
||||
export 'src/theme/menu_metrics.dart';
|
||||
@@ -2,6 +2,7 @@ export 'src/widgets/app_button_group.dart';
|
||||
export 'src/widgets/app_combobox.dart';
|
||||
export 'src/widgets/app_dialog.dart';
|
||||
export 'src/widgets/app_field.dart';
|
||||
export 'src/widgets/app_floating_dialog.dart';
|
||||
export 'src/widgets/app_item.dart';
|
||||
export 'src/widgets/app_menu.dart';
|
||||
export 'src/widgets/app_popover.dart';
|
||||
@@ -17,3 +18,5 @@ export 'src/widgets/native_context_menu.dart';
|
||||
export 'src/widgets/scroll_edge_fade.dart';
|
||||
export 'src/widgets/workspace_panel.dart';
|
||||
export 'src/widgets/resource_download_progress.dart';
|
||||
export 'src/widgets/app_command_toolbar.dart';
|
||||
export 'src/widgets/app_property_group.dart';
|
||||
@@ -16,3 +16,13 @@ dev_dependencies:
|
||||
flutter_lints: ^6.0.0
|
||||
build_runner: ^2.16.1
|
||||
freezed: ^4.0.2
|
||||
flutter:
|
||||
fonts:
|
||||
- family: PhosphorRegular
|
||||
fonts:
|
||||
- asset: assets/fonts/PhosphorRegular.ttf
|
||||
- family: PhosphorFill
|
||||
fonts:
|
||||
- asset: assets/fonts/PhosphorFill.ttf
|
||||
assets:
|
||||
- assets/fonts/PHOSPHOR_LICENSE.txt
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('overflow keeps view controls visible and runs hidden commands', (
|
||||
tester,
|
||||
) async {
|
||||
var deleted = 0;
|
||||
var fitted = 0;
|
||||
final commands = [
|
||||
const AppToolbarCommand(
|
||||
label: 'Undo',
|
||||
icon: AppIcons.undo,
|
||||
onPressed: null,
|
||||
),
|
||||
AppToolbarCommand(label: 'Redo', icon: AppIcons.redo, onPressed: () {}),
|
||||
AppToolbarCommand(label: 'Split', icon: AppIcons.cut, onPressed: () {}),
|
||||
AppToolbarCommand(
|
||||
label: 'Trim left',
|
||||
icon: AppIcons.alignLeft,
|
||||
onPressed: () {},
|
||||
),
|
||||
AppToolbarCommand(
|
||||
label: 'Trim right',
|
||||
icon: AppIcons.alignRight,
|
||||
onPressed: () {},
|
||||
),
|
||||
AppToolbarCommand(
|
||||
label: 'Delete',
|
||||
icon: AppIcons.delete,
|
||||
onPressed: () => deleted++,
|
||||
),
|
||||
];
|
||||
Widget toolbar(double width) => MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, Brightness.dark),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: 36,
|
||||
child: AppCommandToolbar(
|
||||
groups: [commands.take(2).toList(), commands.skip(2).toList()],
|
||||
trailing: [
|
||||
AppToolbarCommand(
|
||||
label: 'Fit',
|
||||
icon: AppIcons.fitContent,
|
||||
onPressed: () => fitted++,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
for (final width in [128.0, 180.0, 200.0, 240.0, 480.0]) {
|
||||
await tester.pumpWidget(toolbar(width));
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
find.widgetWithIcon(IconButton, AppIcons.fitContent),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(find.byKey(const Key('toolbar-overflow')), findsNothing);
|
||||
await tester.pumpWidget(toolbar(180));
|
||||
await tester.tap(find.widgetWithIcon(IconButton, AppIcons.fitContent));
|
||||
expect(fitted, 1);
|
||||
await tester.tap(find.byKey(const Key('toolbar-overflow')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Delete'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(deleted, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex_ui/cutdex_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUpAll(() async {
|
||||
for (final family in ['PhosphorRegular', 'PhosphorFill']) {
|
||||
final loader = FontLoader('packages/cutdex_ui/$family')
|
||||
..addFont(
|
||||
rootBundle.load('packages/cutdex_ui/assets/fonts/$family.ttf'),
|
||||
);
|
||||
await loader.load();
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('bundled fonts render distinct glyphs and filled shapes', (
|
||||
tester,
|
||||
) async {
|
||||
final close = await renderIcon(tester, AppIcons.close);
|
||||
final check = await renderIcon(tester, AppIcons.check);
|
||||
final star = await renderIcon(tester, AppIcons.star);
|
||||
final filledStar = await renderIcon(tester, AppIcons.starFilled);
|
||||
|
||||
// Missing fonts would render identical fallback boxes for these codepoints.
|
||||
expect(close, isNot(orderedEquals(check)));
|
||||
expect(paintedPixels(close), greaterThan(0));
|
||||
expect(paintedPixels(star), greaterThan(0));
|
||||
expect(paintedPixels(filledStar), greaterThan(paintedPixels(star)));
|
||||
});
|
||||
|
||||
testWidgets('IconData works in WorkspacePanel and inherits IconTheme', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: IconTheme(
|
||||
data: IconThemeData(color: Colors.purple),
|
||||
child: WorkspacePanel(
|
||||
title: 'Media',
|
||||
icon: AppIcons.video,
|
||||
child: SizedBox(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final icon = find.byIcon(AppIcons.video);
|
||||
expect(icon, findsOneWidget);
|
||||
final text = tester.widget<RichText>(
|
||||
find.descendant(of: icon, matching: find.byType(RichText)),
|
||||
);
|
||||
expect(text.text.style!.color, Colors.purple);
|
||||
expect(text.text.style!.fontFamily, 'packages/cutdex_ui/PhosphorRegular');
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('RTL mirrors navigation while preserving playback direction', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: Row(children: [Icon(AppIcons.arrowBack), Icon(AppIcons.play)]),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byIcon(AppIcons.arrowBack),
|
||||
matching: find.byType(Transform),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byIcon(AppIcons.play),
|
||||
matching: find.byType(Transform),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('workspace themes replace implicit Material action icons', (
|
||||
tester,
|
||||
) async {
|
||||
var backPressed = 0;
|
||||
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
BackButton(onPressed: () => backPressed++),
|
||||
CloseButton(onPressed: () {}),
|
||||
const DrawerButton(),
|
||||
const EndDrawerButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.byIcon(AppIcons.arrowBack), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.close), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.menu), findsNWidgets(2));
|
||||
expect(find.byTooltip('Back'), findsOneWidget);
|
||||
await tester.tap(find.byIcon(AppIcons.arrowBack));
|
||||
}
|
||||
expect(backPressed, 2);
|
||||
});
|
||||
}
|
||||
|
||||
Future<Uint8List> renderIcon(WidgetTester tester, IconData icon) async {
|
||||
final key = GlobalKey();
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: SizedBox.square(
|
||||
dimension: 48,
|
||||
child: Icon(icon, size: 48, color: Colors.black),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final boundary =
|
||||
key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
|
||||
final pixels = await tester.runAsync(() async {
|
||||
final image = await boundary.toImage();
|
||||
try {
|
||||
final data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
||||
return Uint8List.fromList(data!.buffer.asUint8List());
|
||||
} finally {
|
||||
image.dispose();
|
||||
}
|
||||
});
|
||||
return pixels!;
|
||||
}
|
||||
|
||||
int paintedPixels(Uint8List rgba) {
|
||||
var result = 0;
|
||||
for (var index = 3; index < rgba.length; index += 4) {
|
||||
if (rgba[index] != 0) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
@@ -7,6 +8,294 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final dismissal in ['trigger', 'selection', 'outside']) {
|
||||
testWidgets(
|
||||
'pointer $dismissal dismissal releases menu trigger highlight',
|
||||
(tester) async {
|
||||
late FocusNode triggerFocus;
|
||||
final states = WidgetStatesController();
|
||||
addTearDown(states.dispose);
|
||||
var closed = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: AppDropdownMenu(
|
||||
onClose: () => closed++,
|
||||
items: [AppMenuItem(label: 'Action', onPressed: () {})],
|
||||
builder: (_, toggle, focus) {
|
||||
triggerFocus = focus;
|
||||
return TextButton(
|
||||
focusNode: focus,
|
||||
statesController: states,
|
||||
onPressed: toggle,
|
||||
child: const Text('Open'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(400, 400));
|
||||
Future<void> click(Offset point) async {
|
||||
await mouse.moveTo(point);
|
||||
await mouse.down(point);
|
||||
await mouse.up();
|
||||
}
|
||||
|
||||
await click(tester.getCenter(find.text('Open')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Action'), findsOneWidget);
|
||||
switch (dismissal) {
|
||||
case 'trigger':
|
||||
await click(tester.getCenter(find.text('Open')));
|
||||
case 'selection':
|
||||
await click(tester.getCenter(find.text('Action')));
|
||||
case 'outside':
|
||||
await click(const Offset(400, 400));
|
||||
}
|
||||
await mouse.moveTo(const Offset(450, 450));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Action'), findsNothing);
|
||||
expect(closed, 1);
|
||||
expect(triggerFocus.hasFocus, isFalse);
|
||||
expect(states.value, isNot(contains(WidgetState.focused)));
|
||||
expect(states.value, isNot(contains(WidgetState.hovered)));
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (final kind in [PointerDeviceKind.mouse, PointerDeviceKind.touch]) {
|
||||
testWidgets('dropdown outside $kind click activates buttons and inputs', (
|
||||
tester,
|
||||
) async {
|
||||
var outsideClicks = 0;
|
||||
var menuActions = 0;
|
||||
final inputFocus = FocusNode();
|
||||
addTearDown(inputFocus.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppDropdownMenu(
|
||||
items: [
|
||||
AppMenuItem(
|
||||
label: 'Menu action',
|
||||
onPressed: () => menuActions++,
|
||||
),
|
||||
],
|
||||
builder: (_, toggle, focus) => TextButton(
|
||||
focusNode: focus,
|
||||
onPressed: toggle,
|
||||
child: const Text('Open menu'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 200),
|
||||
TextButton(
|
||||
onPressed: () => outsideClicks++,
|
||||
child: const Text('Outside button'),
|
||||
),
|
||||
SizedBox(width: 240, child: TextField(focusNode: inputFocus)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open menu'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Menu action'), findsOneWidget);
|
||||
await tester.tap(find.text('Outside button'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Menu action'), findsNothing);
|
||||
expect(outsideClicks, 1);
|
||||
|
||||
await tester.tap(find.text('Open menu'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(TextField), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Menu action'), findsNothing);
|
||||
expect(inputFocus.hasFocus, isTrue);
|
||||
expect(menuActions, 0);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('dropdowns and selects switch on the first $kind click', (
|
||||
tester,
|
||||
) async {
|
||||
var selected = 0;
|
||||
var actions = 0;
|
||||
Widget dropdown(String name) => AppDropdownMenu(
|
||||
items: [AppMenuItem(label: '$name action', onPressed: () => actions++)],
|
||||
builder: (_, toggle, focus) =>
|
||||
TextButton(focusNode: focus, onPressed: toggle, child: Text(name)),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
dropdown('First'),
|
||||
dropdown('Second'),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: AppSelect<int>(
|
||||
value: selected,
|
||||
options: const [
|
||||
AppSelectOption(0, 'Automatic'),
|
||||
AppSelectOption(1, 'Manual'),
|
||||
],
|
||||
onChanged: (next) => selected = next,
|
||||
label: 'Mode',
|
||||
emptyLabel: 'No options',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('First'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First action'), findsOneWidget);
|
||||
await tester.tap(find.text('Second'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First action'), findsNothing);
|
||||
expect(find.text('Second action'), findsOneWidget);
|
||||
// Clicking the open menu's own trigger still closes it.
|
||||
await tester.tap(find.text('Second'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Second action'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('First'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
find.widgetWithText(TextButton, 'Automatic'),
|
||||
kind: kind,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('First action'), findsNothing);
|
||||
expect(find.widgetWithText(MenuItemButton, 'Manual'), findsOneWidget);
|
||||
await tester.tap(find.text('First'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.widgetWithText(MenuItemButton, 'Manual'), findsNothing);
|
||||
expect(find.text('First action'), findsOneWidget);
|
||||
expect(selected, 0);
|
||||
|
||||
await tester.tap(find.text('First action'), kind: kind);
|
||||
await tester.pumpAndSettle();
|
||||
expect(actions, 1);
|
||||
expect(find.text('First action'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Flutter context menu outside click also activates its target', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.windows;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
var outsideClicks = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppContextMenu(
|
||||
itemsBuilder: (_) => [
|
||||
AppMenuItem(label: 'Context action', onPressed: () {}),
|
||||
],
|
||||
child: const SizedBox(width: 100, height: 100),
|
||||
),
|
||||
const SizedBox(height: 200),
|
||||
TextButton(
|
||||
onPressed: () => outsideClicks++,
|
||||
child: const Text('Outside button'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(
|
||||
find.byType(AppContextMenu),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
buttons: kSecondaryMouseButton,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Context action'), findsOneWidget);
|
||||
await tester.tap(
|
||||
find.text('Outside button'),
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Context action'), findsNothing);
|
||||
expect(outsideClicks, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('dropdown offsets do not inherit or overwrite expansion state', (
|
||||
tester,
|
||||
) async {
|
||||
final bucket = PageStorageBucket();
|
||||
const ancestorKey = PageStorageKey('expanded-property');
|
||||
int? selected;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: PageStorage(
|
||||
bucket: bucket,
|
||||
child: Builder(
|
||||
key: ancestorKey,
|
||||
builder: (context) {
|
||||
bucket.writeState(context, true);
|
||||
return SizedBox(
|
||||
width: 220,
|
||||
child: AppSelect<int>(
|
||||
label: 'Color space',
|
||||
emptyLabel: 'No options',
|
||||
value: 0,
|
||||
options: const [
|
||||
AppSelectOption(0, 'Automatic'),
|
||||
AppSelectOption(1, 'Manual'),
|
||||
],
|
||||
onChanged: (value) => selected = value,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (var i = 0; i < 2; i++) {
|
||||
await tester.tap(find.text('Automatic'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.text('Manual'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(selected, 1);
|
||||
expect(bucket.readState(tester.element(find.byKey(ancestorKey))), isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'native menu waits for right-button release and dismissal keeps left clicks working',
|
||||
(tester) async {
|
||||
@@ -248,7 +537,7 @@ void main() {
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byIcon(Icons.check), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.check), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.widgetWithText(MenuItemButton, 'Dark')).height,
|
||||
28,
|
||||
|
||||
@@ -1,10 +1,70 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('popover clears pointer focus and retains keyboard focus', (
|
||||
tester,
|
||||
) async {
|
||||
final focus = FocusNode();
|
||||
final states = WidgetStatesController();
|
||||
addTearDown(focus.dispose);
|
||||
addTearDown(states.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: AppPopover(
|
||||
builder: (_, toggle) => TextButton(
|
||||
focusNode: focus,
|
||||
statesController: states,
|
||||
onPressed: toggle,
|
||||
child: const Text('Open'),
|
||||
),
|
||||
child: const Text('Content'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: const Offset(400, 400));
|
||||
for (final outside in [false, true]) {
|
||||
final trigger = tester.getCenter(find.text('Open'));
|
||||
await mouse.moveTo(trigger);
|
||||
await mouse.down(trigger);
|
||||
await mouse.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Content'), findsOneWidget);
|
||||
final closingPoint = outside ? const Offset(400, 400) : trigger;
|
||||
await mouse.moveTo(closingPoint);
|
||||
await mouse.down(closingPoint);
|
||||
await mouse.up();
|
||||
await mouse.moveTo(const Offset(450, 450));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Content'), findsNothing);
|
||||
expect(focus.hasFocus, isFalse);
|
||||
expect(states.value, isNot(contains(WidgetState.focused)));
|
||||
expect(states.value, isNot(contains(WidgetState.hovered)));
|
||||
}
|
||||
await mouse.removePointer();
|
||||
focus.requestFocus();
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Content'), findsOneWidget);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Content'), findsNothing);
|
||||
expect(focus.hasFocus, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'popover anchors below its trigger and dismisses outside and with Escape',
|
||||
(tester) async {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('titles and actions leave the full width for paired fields', (
|
||||
tester,
|
||||
) async {
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.propertiesPanelTheme(
|
||||
AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(palette, brightness),
|
||||
),
|
||||
),
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
width: 220,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: AppPropertyGroup(
|
||||
label: 'Position',
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.diamond_outlined),
|
||||
),
|
||||
],
|
||||
child: const Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppTextField(
|
||||
label: 'X',
|
||||
errorText: 'Invalid value',
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Expanded(child: AppTextField(label: 'Y')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final first = find.byType(TextField).first;
|
||||
final second = find.byType(TextField).last;
|
||||
expect(tester.getRect(first).width, 96);
|
||||
expect(tester.getRect(second).right, 208);
|
||||
expect(tester.getRect(first).top, tester.getRect(second).top);
|
||||
expect(
|
||||
tester.getRect(first).height,
|
||||
greaterThan(tester.getRect(second).height),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byType(IconButton)).bottom,
|
||||
tester.getRect(first).top - 4,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextField>(first).decoration!.prefixIcon,
|
||||
isNotNull,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
@@ -7,6 +7,167 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('slider density follows inspector and desktop contexts', (
|
||||
tester,
|
||||
) async {
|
||||
final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark);
|
||||
for (final (theme, height) in [
|
||||
(AppTheme.propertiesPanelTheme(desktop), 28.0),
|
||||
(desktop, 36.0),
|
||||
(
|
||||
AppTheme.propertiesPanelTheme(AppTheme.penDark),
|
||||
AppControlSize.standard,
|
||||
),
|
||||
]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 220,
|
||||
child: AppSlider(value: .5, onChanged: (_) {}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(find.byType(AppSlider)).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'inspector density leaves general desktop and touch inputs unchanged',
|
||||
() {
|
||||
final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark);
|
||||
final inspector = AppTheme.propertiesPanelTheme(desktop);
|
||||
expect(desktop.inputDecorationTheme.constraints!.minHeight, 36);
|
||||
expect(inspector.inputDecorationTheme.constraints!.minHeight, 28);
|
||||
expect(inspector.textTheme.bodyMedium!.fontSize, 13);
|
||||
expect(inspector.textTheme.bodySmall!.fontSize, 12);
|
||||
expect(
|
||||
inspector.iconButtonTheme.style!.fixedSize!.resolve({}),
|
||||
const Size.square(24),
|
||||
);
|
||||
expect(desktop.extension<InspectorControlDensity>(), isNull);
|
||||
expect(inspector.extension<InspectorControlDensity>(), isNotNull);
|
||||
final dialog = AppTheme.dialogContentTheme(inspector);
|
||||
expect(dialog.extension<InspectorControlDensity>(), isNull);
|
||||
expect(dialog.inputDecorationTheme.constraints!.minHeight, 36);
|
||||
expect(dialog.textTheme.bodyMedium!.fontSize, 14);
|
||||
final touch = AppTheme.propertiesPanelTheme(AppTheme.penDark);
|
||||
expect(touch.extension<InspectorControlDensity>(), isNull);
|
||||
expect(
|
||||
touch.iconButtonTheme.style!.fixedSize!.resolve({}),
|
||||
const Size.square(28),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('multiline input keeps its first line near the top', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = TextEditingController(text: 'First\nSecond');
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
height: 100,
|
||||
child: AppTextField(
|
||||
controller: controller,
|
||||
minLines: 3,
|
||||
maxLines: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final editable = tester
|
||||
.state<EditableTextState>(find.byType(EditableText))
|
||||
.renderEditable;
|
||||
final caret = editable.getLocalRectForCaret(const TextPosition(offset: 0));
|
||||
expect(
|
||||
editable.localToGlobal(caret.center).dy -
|
||||
tester.getTopLeft(find.byType(TextField)).dy,
|
||||
lessThan(25),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('labelled single-line inputs keep text and caret centered', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = TextEditingController(text: '125');
|
||||
addTearDown(controller.dispose);
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final desktop in [false, true]) {
|
||||
final base = AppTheme.forPalette(AppPalette.graphite, brightness);
|
||||
final theme = AppTheme.propertiesPanelTheme(
|
||||
desktop ? AppTheme.desktopWorkspaceTheme(base) : base,
|
||||
);
|
||||
final height = desktop
|
||||
? AppInspectorMetrics.input
|
||||
: AppControlSize.propertyControl;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
height: height,
|
||||
child: AppTextField(
|
||||
controller: controller,
|
||||
label: 'W',
|
||||
unit: '%',
|
||||
hintText: 'Value',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final field = find.byType(TextField);
|
||||
final label = find.text('W');
|
||||
expect(
|
||||
tester.getRect(label).center.dy,
|
||||
tester.getRect(field).center.dy,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextField>(field).decoration!.prefixIcon,
|
||||
isNotNull,
|
||||
);
|
||||
for (final text in ['', '125', '项目']) {
|
||||
await tester.enterText(field, text);
|
||||
await tester.pump();
|
||||
final editable = tester
|
||||
.state<EditableTextState>(find.byType(EditableText))
|
||||
.renderEditable;
|
||||
final caret = editable.getLocalRectForCaret(
|
||||
TextPosition(offset: text.length),
|
||||
);
|
||||
expect(
|
||||
editable.localToGlobal(caret.center).dy,
|
||||
closeTo(tester.getCenter(field).dy, 1),
|
||||
);
|
||||
expect(tester.getSize(field).height, height);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('Icon button states use translucent ink without stacking selection', () {
|
||||
final style = AppTheme.penDark.iconButtonTheme.style!;
|
||||
const ink = Color(0xFFFCFCFC);
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final kind in ['searchable', 'popover', 'context']) {
|
||||
for (final stored in <Object>[true, 120.0]) {
|
||||
testWidgets('$kind popup isolates ancestor state $stored', (
|
||||
tester,
|
||||
) async {
|
||||
final bucket = PageStorageBucket();
|
||||
const ancestorKey = PageStorageKey('parent-state');
|
||||
Widget popup() => switch (kind) {
|
||||
'searchable' => AppSelect<int>(
|
||||
value: 0,
|
||||
label: 'Select',
|
||||
emptyLabel: 'Empty',
|
||||
searchable: true,
|
||||
searchHint: 'Search',
|
||||
onChanged: (_) {},
|
||||
options: [
|
||||
for (var i = 0; i < 40; i++) AppSelectOption(i, 'Choice $i'),
|
||||
],
|
||||
),
|
||||
'popover' => AppPopover(
|
||||
builder: (_, toggle) => TextButton(
|
||||
key: const Key('trigger'),
|
||||
onPressed: toggle,
|
||||
child: const Text('Open'),
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
child: ListView(
|
||||
primary: false,
|
||||
children: [
|
||||
for (var i = 0; i < 40; i++)
|
||||
SizedBox(height: 32, child: Text('Choice $i')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_ => AppContextMenu(
|
||||
itemsBuilder: (_) => [
|
||||
for (var i = 0; i < 40; i++)
|
||||
AppMenuItem(label: 'Choice $i', onPressed: () {}),
|
||||
],
|
||||
child: const SizedBox(
|
||||
key: Key('trigger'),
|
||||
width: 200,
|
||||
height: 100,
|
||||
child: ColoredBox(color: Colors.transparent),
|
||||
),
|
||||
),
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 240,
|
||||
child: PageStorage(
|
||||
bucket: bucket,
|
||||
child: Builder(
|
||||
key: ancestorKey,
|
||||
builder: (context) {
|
||||
bucket.writeState(context, stored);
|
||||
return popup();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(
|
||||
kind == 'searchable'
|
||||
? find.byType(TextField)
|
||||
: find.byKey(const Key('trigger')),
|
||||
buttons: kind == 'context'
|
||||
? kSecondaryMouseButton
|
||||
: kPrimaryMouseButton,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final positions = tester
|
||||
.stateList<ScrollableState>(
|
||||
find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Scrollable &&
|
||||
axisDirectionToAxis(widget.axisDirection) == Axis.vertical,
|
||||
),
|
||||
)
|
||||
.map((state) => state.position)
|
||||
.toList();
|
||||
expect(positions, isNotEmpty);
|
||||
for (final position in positions) {
|
||||
expect(
|
||||
position.pixels,
|
||||
0,
|
||||
reason: 'Popup must not restore its parent offset',
|
||||
);
|
||||
}
|
||||
positions
|
||||
.firstWhere((position) => position.maxScrollExtent > 50)
|
||||
.jumpTo(25);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
bucket.readState(tester.element(find.byKey(ancestorKey))),
|
||||
stored,
|
||||
);
|
||||
await tester.tapAt(const Offset(790, 590));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Choice 3'), findsNothing);
|
||||
expect(
|
||||
bucket.readState(tester.element(find.byKey(ancestorKey))),
|
||||
stored,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate Flutter icon constants from a pinned Phosphor font catalog."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
SOURCE = ROOT / 'tool/phosphor/catalog.json'
|
||||
OUTPUT = ROOT / 'lib/src/icons/phosphor_icons.g.dart'
|
||||
STYLES = {
|
||||
'regular': ('Phosphor.ttf', 'PhosphorRegular', 'PhosphorIconsRegular'),
|
||||
'fill': ('Phosphor-Fill.ttf', 'PhosphorFill', 'PhosphorIconsFill'),
|
||||
}
|
||||
# Mirror navigation only, keeping playback, undo/redo, and logos unchanged.
|
||||
MIRRORED = {'arrow-left', 'arrow-right', 'caret-left', 'caret-right',
|
||||
'caret-double-left', 'caret-double-right'}
|
||||
|
||||
|
||||
def read_upstream(revision, path):
|
||||
url = f'https://raw.githubusercontent.com/phosphor-icons/web/{revision}/{path}'
|
||||
with urlopen(url, timeout=30) as response:
|
||||
return response.read()
|
||||
|
||||
|
||||
def update_catalog(revision):
|
||||
if not re.fullmatch(r'[0-9a-f]{40}', revision):
|
||||
raise ValueError('--update requires a full Git commit SHA')
|
||||
version = json.loads(read_upstream(revision, 'package.json'))['version']
|
||||
catalog = {
|
||||
'repository': 'https://github.com/phosphor-icons/web',
|
||||
'revision': revision,
|
||||
'version': version,
|
||||
'styles': {},
|
||||
}
|
||||
# Fetch and validate everything before writing the local snapshot.
|
||||
assets = {}
|
||||
for style, (filename, family, _) in STYLES.items():
|
||||
selection_path = f'src/{style}/selection.json'
|
||||
selection = read_upstream(revision, selection_path)
|
||||
icons = {}
|
||||
for item in json.loads(selection)['icons']:
|
||||
properties = item['properties']
|
||||
for alias in properties['name'].split(','):
|
||||
name = alias.strip()
|
||||
if style == 'fill':
|
||||
if not name.endswith('-fill'):
|
||||
raise ValueError(f'Missing fill suffix: {name}')
|
||||
name = name[:-5]
|
||||
if name in icons:
|
||||
raise ValueError(f'Duplicate icon: {name}')
|
||||
icons[name] = properties['code']
|
||||
font_path = f'src/{style}/{filename}'
|
||||
font = read_upstream(revision, font_path)
|
||||
local_path = f'assets/fonts/{family}.ttf'
|
||||
assets[local_path] = font
|
||||
catalog['styles'][style] = {
|
||||
'font': local_path,
|
||||
'fontSource': font_path,
|
||||
'fontSha256': hashlib.sha256(font).hexdigest(),
|
||||
'catalogSource': selection_path,
|
||||
'catalogSha256': hashlib.sha256(selection).hexdigest(),
|
||||
'icons': dict(sorted(icons.items())),
|
||||
}
|
||||
if catalog['styles']['regular']['icons'] != catalog['styles']['fill']['icons']:
|
||||
raise ValueError('Regular and Fill catalogs do not match')
|
||||
assets['assets/fonts/PHOSPHOR_LICENSE.txt'] = read_upstream(revision, 'LICENSE')
|
||||
for path, data in assets.items():
|
||||
target = ROOT / path
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
SOURCE.parent.mkdir(parents=True, exist_ok=True)
|
||||
SOURCE.write_text(json.dumps(catalog, indent=2) + '\n', encoding='utf-8')
|
||||
|
||||
|
||||
def dart_name(name):
|
||||
if not re.fullmatch(r'[a-z][a-z0-9]*(?:-[a-z0-9]+)*', name):
|
||||
raise ValueError(f'Invalid icon name: {name}')
|
||||
first, *rest = name.split('-')
|
||||
result = first + ''.join(part[0].upper() + part[1:] for part in rest)
|
||||
# Preserve Dart keywords as usable field names.
|
||||
if result in {'as', 'assert', 'break', 'case', 'catch', 'class', 'const',
|
||||
'continue', 'default', 'do', 'else', 'enum', 'extends', 'false',
|
||||
'final', 'finally', 'for', 'if', 'in', 'is', 'new', 'null',
|
||||
'rethrow', 'return', 'super', 'switch', 'this', 'throw', 'true',
|
||||
'try', 'var', 'void', 'while', 'with'}:
|
||||
result += 'Icon'
|
||||
return result
|
||||
|
||||
|
||||
def generate(catalog):
|
||||
lines = [
|
||||
'// GENERATED CODE - DO NOT MODIFY BY HAND.',
|
||||
'// Run: python3 tool/generate_icons.py (from packages/cutdex_ui).',
|
||||
f"// Phosphor web {catalog['version']} @ {catalog['revision']}",
|
||||
"import 'package:flutter/widgets.dart';",
|
||||
]
|
||||
for style, (_, family, class_name) in STYLES.items():
|
||||
source = catalog['styles'][style]
|
||||
font = (ROOT / source['font']).read_bytes()
|
||||
if hashlib.sha256(font).hexdigest() != source['fontSha256']:
|
||||
raise ValueError(f'Font checksum mismatch: {source["font"]}')
|
||||
lines.extend(['', f'/// Phosphor {style.title()} icons from the pinned font catalog.',
|
||||
'@staticIconProvider', f'abstract final class {class_name} {{'])
|
||||
identifiers = set()
|
||||
for name, codepoint in sorted(source['icons'].items()):
|
||||
identifier = dart_name(name)
|
||||
if identifier in identifiers:
|
||||
raise ValueError(f'Duplicate Dart identifier: {identifier}')
|
||||
identifiers.add(identifier)
|
||||
if type(codepoint) is not int or not 0xe000 <= codepoint <= 0xf8ff:
|
||||
raise ValueError(f'Invalid private-use codepoint: {name}')
|
||||
lines.extend([
|
||||
f' static const IconData {identifier} = IconData(',
|
||||
f' 0x{codepoint:04x},',
|
||||
f" fontFamily: '{family}',",
|
||||
" fontPackage: 'cutdex_ui',",
|
||||
])
|
||||
if name in MIRRORED:
|
||||
lines.append(' matchTextDirection: true,')
|
||||
lines.append(' );')
|
||||
lines.append('}')
|
||||
return '\n'.join(lines) + '\n'
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
actions = parser.add_mutually_exclusive_group()
|
||||
actions.add_argument('--update', metavar='COMMIT_SHA', help='refresh official font resources')
|
||||
actions.add_argument('--check', action='store_true', help='verify resources and generated output')
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
if args.update:
|
||||
update_catalog(args.update)
|
||||
output = generate(json.loads(SOURCE.read_text(encoding='utf-8')))
|
||||
if args.check:
|
||||
if not OUTPUT.exists() or OUTPUT.read_text(encoding='utf-8') != output:
|
||||
print('Generated icons are stale. Run tool/generate_icons.py.', file=sys.stderr)
|
||||
return 1
|
||||
print('Phosphor font checksums and generated icons are current.')
|
||||
else:
|
||||
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
|
||||
OUTPUT.write_text(output, encoding='utf-8')
|
||||
print(f'Generated {OUTPUT.relative_to(ROOT)}')
|
||||
return 0
|
||||
except (OSError, ValueError, KeyError) as error:
|
||||
print(str(error), file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user