ubuntu / yaru.dart

Ubuntu Yaru Flutter widgets and themes for building desktop and web applications
https://ubuntu.github.io/yaru.dart/
Mozilla Public License 2.0
245 stars 38 forks source link

YaruWindowTitleBar widget doesn't centre title properly #610

Open whiskeyPeak opened 1 year ago

whiskeyPeak commented 1 year ago

Might be hard to see but there is a slightly larger gap at the top compared to at the bottom.

Screenshot from 2023-02-10 22-53-08

Repro code:

import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await windowManager.ensureInitialized();
  await YaruWindowTitleBar.ensureInitialized();

  windowManager.setPreventClose(false);

  runApp(
    const MyApp(),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      debugShowCheckedModeBanner: false,
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return YaruMasterDetailPage(
      appBar: const YaruWindowTitleBar(),
      layoutDelegate: const YaruMasterResizablePaneDelegate(
        initialPaneWidth: 300,
        minPageWidth: 200,
        minPaneWidth: 200,
      ),
      tileBuilder: (context, index, selected) => const YaruMasterTile(
        title: Text("title 1"),
      ),
      pageBuilder: (context, index) => YaruDetailPage(
        appBar: YaruWindowTitleBar(
          title: Center(
            child: Container(
              height: 40,
              color: Colors.grey[800],
            ),
          ),
        ),
      ),
      length: 1,
    );
  }
}
whiskeyPeak commented 1 year ago

Ahh, the default height of the appBar is 47px, so if the given height of the container is 40px, then we end up with an odd number of pixel that need to be split in half. Setting the container height to 41 solves this issue.

Though I'd expect flutter to render the position of the container on decimal points like it does everywhere else in the framework...