Skip to content

Commit

Permalink
refactor: panes layout can be modified to switch between adaptive sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
squidrye committed Oct 24, 2023
1 parent 0093e3a commit b6558b9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:appflowy/workspace/application/panes/panes_cubit/panes_cubit.dar
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/navigation.dart';
import 'package:appflowy/workspace/presentation/home/panes/flowy_pane_group.dart';
import 'package:appflowy/workspace/presentation/home/panes/panes_layout.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
Expand Down Expand Up @@ -49,13 +50,20 @@ class HomeStack extends StatelessWidget {
builder: (context, state) {
return BlocBuilder<HomeSettingBloc, HomeSettingState>(
builder: (context, homeState) {
return FlowyPaneGroup(
groupHeight: layout.homePageHeight,
groupWidth: layout.homePageWidth,
node: state.root,
layout: layout,
delegate: delegate,
allowPaneDrag: state.allowPaneDrag,
return LayoutBuilder(
builder: (context, constraints) {
return FlowyPaneGroup(
node: state.root,
layout: layout,
delegate: delegate,
allowPaneDrag: state.allowPaneDrag,
paneLayout: PaneLayout.initial(
homeLayout: layout,
parentConstraints: constraints,
root: state.root,
),
);
},
);
},
);
Expand Down Expand Up @@ -344,6 +352,9 @@ class _HomeBodyState extends State<HomeBody> {
builder: (_, value, __) => Stack(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {},
onTapDown: (d) {},
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerPanZoomUpdate: (event) {
Expand Down Expand Up @@ -374,12 +385,9 @@ class _HomeBodyState extends State<HomeBody> {
});
}
},
child: IgnorePointer(
ignoring: value,
child: Opacity(
opacity: 0.5,
child: _buildWidgetStack(onDeleted: widget.onDeleted),
),
child: Opacity(
opacity: 0.5,
child: _buildWidgetStack(onDeleted: widget.onDeleted),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ import 'flowy_pane.dart';

class FlowyPaneGroup extends StatelessWidget {
final PaneNode node;
final double groupWidth;
final double groupHeight;
final PaneLayout paneLayout;
final HomeLayout layout;
final HomeStackDelegate delegate;
final bool allowPaneDrag;

const FlowyPaneGroup({
super.key,
required this.node,
required this.groupWidth,
required this.groupHeight,
required this.paneLayout,
required this.layout,
required this.delegate,
required this.allowPaneDrag,
Expand All @@ -43,7 +41,7 @@ class FlowyPaneGroup extends StatelessWidget {
delegate: delegate,
layout: layout,
paneContext: context,
size: Size(groupWidth, groupHeight),
paneLayout: paneLayout,
),
);
}
Expand All @@ -52,7 +50,9 @@ class FlowyPaneGroup extends StatelessWidget {
key: ValueKey(node.paneId),
create: (context) => PaneNodeCubit(
node.children.length,
node.axis == Axis.horizontal ? groupHeight : groupWidth,
node.axis == Axis.horizontal
? paneLayout.childPaneHeight
: paneLayout.childPaneWidth,
),
child: BlocBuilder<PaneNodeCubit, PaneNodeState>(
builder: (context, state) {
Expand All @@ -63,6 +63,7 @@ class FlowyPaneGroup extends StatelessWidget {
children: [
...node.children.indexed.map((indexNode) {
final paneLayout = PaneLayout(
homeLayout: layout,
childPane: indexNode,
parentPane: node,
flex: state.flex,
Expand Down Expand Up @@ -103,14 +104,18 @@ class FlowyPaneGroup extends StatelessWidget {
child: GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onHorizontalDragUpdate: (details) {
context
.read<PaneNodeCubit>()
.paneResized(indexNode.$1, details.delta.dx, groupWidth);
context.read<PaneNodeCubit>().paneResized(
indexNode.$1,
details.delta.dx,
paneLayout.childPaneWidth,
);
},
onVerticalDragUpdate: (details) {
context
.read<PaneNodeCubit>()
.paneResized(indexNode.$1, details.delta.dy, groupHeight);
context.read<PaneNodeCubit>().paneResized(
indexNode.$1,
details.delta.dy,
paneLayout.childPaneHeight,
);
},
onHorizontalDragStart: (_) =>
context.read<PaneNodeCubit>().resizeStart(),
Expand Down Expand Up @@ -142,8 +147,7 @@ class FlowyPaneGroup extends StatelessWidget {
top: paneLayout.childPaneTPosition,
child: FlowyPaneGroup(
node: indexNode.$2,
groupWidth: paneLayout.childPaneWidth,
groupHeight: paneLayout.childPaneHeight,
paneLayout: paneLayout,
delegate: delegate,
layout: layout,
allowPaneDrag: allowPaneDrag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/workspace/application/panes/panes.dart';
import 'package:appflowy/workspace/presentation/home/home_layout.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -13,13 +15,16 @@ class PaneLayout {
late double? resizerPosition;
late double resizerWidth;
late double resizerHeight;
late double homePageWidth;
late double homePageHeight;
late SystemMouseCursor resizeCursorType;
final (int, PaneNode) childPane;
final PaneNode parentPane;
final List<double> flex;

PaneLayout({
required BoxConstraints parentPaneConstraints,
required HomeLayout homeLayout,
required this.flex,
required this.childPane,
required this.parentPane,
Expand All @@ -32,6 +37,17 @@ class PaneLayout {
? parentPaneConstraints.maxHeight * flex[childPane.$1]
: parentPaneConstraints.maxHeight;

final bool adaptiveContent = adaptivePlugins.contains(
childPane.$2.tabs.currentPageManager.notifier.plugin.pluginType,
);

if (adaptiveContent) {
homePageHeight = childPaneHeight;
homePageWidth = childPaneWidth;
} else {
homePageHeight = homeLayout.homePageHeight;
homePageWidth = homeLayout.homePageWidth;
}
double accumulatedWidth = 0;
double accumulatedHeight = 0;
for (int i = 0; i < childPane.$1; i++) {
Expand All @@ -57,4 +73,20 @@ class PaneLayout {
? SystemMouseCursors.resizeLeftRight
: SystemMouseCursors.resizeUpDown;
}

factory PaneLayout.initial(
{required BoxConstraints parentConstraints,
required PaneNode root,
required HomeLayout homeLayout}) =>
PaneLayout(
homeLayout: homeLayout,
parentPaneConstraints: parentConstraints,
flex: [],
childPane: (0, root),
parentPane: PaneNode.initial(),
);

///PluginType added here will adapt to size of pane
///rather than being stacked over
final List<PluginType> adaptivePlugins = [];
}

0 comments on commit b6558b9

Please sign in to comment.