Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupi007 committed Oct 4, 2022
1 parent 8fd12d5 commit 5665a00
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 44 deletions.
45 changes: 2 additions & 43 deletions lib/src/pages/layouts/yaru_compact_layout.dart
Expand Up @@ -61,9 +61,6 @@ class _YaruCompactLayoutState extends State<YaruCompactLayout> {

@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(
Expand All @@ -80,35 +77,11 @@ class _YaruCompactLayoutState extends State<YaruCompactLayout> {
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) {
Expand All @@ -118,21 +91,7 @@ class _YaruCompactLayoutState extends State<YaruCompactLayout> {
_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,
),
),
),
Expand Down
95 changes: 95 additions & 0 deletions 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<YaruPageItem> destinations;
final int selectedIndex;
final ValueChanged<int> onDestinationSelected;
final bool showLabels;
final bool extended;

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
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<int> 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),
]
],
),
),
),
),
),
);
}
}
7 changes: 6 additions & 1 deletion lib/src/pages/layouts/yaru_page_item_title.dart
Expand Up @@ -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,
);
}
}
3 changes: 3 additions & 0 deletions lib/yaru_widgets.dart
Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions linux/flutter/ephemeral/.plugin_symlinks/yaru
15 changes: 15 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
@@ -0,0 +1,15 @@
//
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"

#include <yaru/yaru_plugin.h>

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);
}
15 changes: 15 additions & 0 deletions 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 <flutter_linux/flutter_linux.h>

// Registers Flutter plugins.
void fl_register_plugins(FlPluginRegistry* registry);

#endif // GENERATED_PLUGIN_REGISTRANT_
24 changes: 24 additions & 0 deletions 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 $<TARGET_FILE:${plugin}_plugin>)
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)

0 comments on commit 5665a00

Please sign in to comment.