diff --git a/lib/src/pages/layouts/yaru_compact_layout.dart b/lib/src/pages/layouts/yaru_compact_layout.dart index a15fe26ab..6debc217e 100644 --- a/lib/src/pages/layouts/yaru_compact_layout.dart +++ b/lib/src/pages/layouts/yaru_compact_layout.dart @@ -61,9 +61,6 @@ class _YaruCompactLayoutState extends State { @override Widget build(BuildContext context) { - final unselectedTextColor = - Theme.of(context).colorScheme.onSurface.withOpacity(0.8); - final selectedTextColor = Theme.of(context).colorScheme.onSurface; return LayoutBuilder( builder: (context, constraint) { return SafeArea( @@ -80,35 +77,11 @@ class _YaruCompactLayoutState extends State { constraints: BoxConstraints(minHeight: constraint.maxHeight), child: IntrinsicHeight( - child: NavigationRail( + child: YaruNavigationRail( extended: widget.labelType == NavigationRailLabelType.none ? widget.extendNavigationRail : false, - unselectedIconTheme: IconThemeData( - color: unselectedTextColor, - ), - indicatorColor: Theme.of(context) - .colorScheme - .onSurface - .withOpacity(0.1), - selectedIconTheme: IconThemeData( - color: selectedTextColor, - ), - selectedLabelTextStyle: TextStyle( - overflow: TextOverflow.ellipsis, - color: selectedTextColor, - fontSize: 13, - fontWeight: FontWeight.w500, - ), - unselectedLabelTextStyle: TextStyle( - color: unselectedTextColor, - overflow: TextOverflow.ellipsis, - fontSize: 13, - fontWeight: FontWeight.w500, - ), - backgroundColor: widget.backgroundColor ?? - Theme.of(context).colorScheme.background, selectedIndex: _index, onDestinationSelected: (index) { if (widget.pageItems[index].onTap != null) { @@ -118,21 +91,7 @@ class _YaruCompactLayoutState extends State { _index = index; }); }, - labelType: widget.labelType, - destinations: widget.pageItems - .map( - (pageItem) => NavigationRailDestination( - icon: pageItem.itemWidget ?? - Icon(pageItem.iconData), - selectedIcon: pageItem.selectedItemWidget ?? - pageItem.itemWidget ?? - (pageItem.selectedIconData != null - ? Icon(pageItem.selectedIconData) - : Icon(pageItem.iconData)), - label: pageItem.titleBuilder(context), - ), - ) - .toList(), + destinations: widget.pageItems, ), ), ), diff --git a/lib/src/pages/layouts/yaru_navigation_rail.dart b/lib/src/pages/layouts/yaru_navigation_rail.dart new file mode 100644 index 000000000..85846fb64 --- /dev/null +++ b/lib/src/pages/layouts/yaru_navigation_rail.dart @@ -0,0 +1,95 @@ +import 'package:flutter/material.dart'; +import 'package:yaru_widgets/src/pages/layouts/yaru_page_item.dart'; + +class YaruNavigationRail extends StatelessWidget { + const YaruNavigationRail({ + super.key, + required this.destinations, + required this.selectedIndex, + required this.onDestinationSelected, + this.showLabels = false, + this.extended = false, + }); + + final List destinations; + final int selectedIndex; + final ValueChanged onDestinationSelected; + final bool showLabels; + final bool extended; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + for (int i = 0; i < destinations.length; i += 1) + _YaruNavigationRailItem( + i, + i == selectedIndex, + destinations[i], + onDestinationSelected, + showLabels, + ) + ], + ); + } +} + +class _YaruNavigationRailItem extends StatelessWidget { + const _YaruNavigationRailItem( + this.index, + this.selected, + this.destination, + this.onSelected, + this.showLabel, + ); + + final int index; + final bool selected; + final YaruPageItem destination; + final ValueChanged onSelected; + final bool showLabel; + + @override + Widget build(BuildContext context) { + return SizedBox( + width: showLabel ? 85 : 60, + child: Material( + child: InkWell( + onTap: () => onSelected(index), + child: Center( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 7, horizontal: 5), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(100), + color: selected + ? Theme.of(context) + .colorScheme + .onSurface + .withOpacity(.1) + : null, + ), + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 2, + horizontal: 10, + ), + child: Icon(destination.iconData), + ), + ), + if (showLabel) ...[ + const SizedBox(height: 2), + destination.titleBuilder(context), + ] + ], + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/src/pages/layouts/yaru_page_item_title.dart b/lib/src/pages/layouts/yaru_page_item_title.dart index dd8d7201f..0eaa6d159 100644 --- a/lib/src/pages/layouts/yaru_page_item_title.dart +++ b/lib/src/pages/layouts/yaru_page_item_title.dart @@ -15,8 +15,13 @@ class YaruPageItemTitle extends StatelessWidget { Widget build(BuildContext context) { return DefaultTextStyle.merge( child: child, - maxLines: 1, + // TODO: we should pass which kind of rail is used + // maxLines: 1, + // overflow: TextOverflow.ellipsis, + style: const TextStyle(fontSize: 11), overflow: TextOverflow.ellipsis, + textAlign: TextAlign.center, + maxLines: 3, ); } } diff --git a/lib/yaru_widgets.dart b/lib/yaru_widgets.dart index 87b141cc8..f767dfbd9 100644 --- a/lib/yaru_widgets.dart +++ b/lib/yaru_widgets.dart @@ -23,6 +23,9 @@ export 'src/pages/yaru_tabbed_page.dart'; // Pages layouts export 'src/pages/layouts/yaru_compact_layout.dart'; export 'src/pages/layouts/yaru_master_detail_page.dart'; +export 'src/pages/layouts/yaru_navigation_rail.dart'; +export 'src/controls/yaru_option_button.dart'; +export 'src/pages/yaru_page.dart'; export 'src/pages/layouts/yaru_page_item.dart'; export 'src/pages/layouts/yaru_page_item_title.dart'; diff --git a/linux/flutter/ephemeral/.plugin_symlinks/yaru b/linux/flutter/ephemeral/.plugin_symlinks/yaru new file mode 120000 index 000000000..d18ff4fec --- /dev/null +++ b/linux/flutter/ephemeral/.plugin_symlinks/yaru @@ -0,0 +1 @@ +/home/jupiter007/.pub-cache/hosted/pub.dartlang.org/yaru-0.4.1/ \ No newline at end of file diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 000000000..6cdf9ac90 --- /dev/null +++ b/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + +#include + +void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) yaru_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "YaruPlugin"); + yaru_plugin_register_with_registrar(yaru_registrar); +} diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 000000000..e0f0a47bc --- /dev/null +++ b/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake new file mode 100644 index 000000000..4710751e9 --- /dev/null +++ b/linux/flutter/generated_plugins.cmake @@ -0,0 +1,24 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST + yaru +) + +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin)