Skip to content

Commit

Permalink
Merge pull request #19 from robiness/stage-size-and-position
Browse files Browse the repository at this point in the history
  • Loading branch information
robiness authored Aug 10, 2023
2 parents 7874d87 + 3e24dc4 commit 1db9d97
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/lib/stage_data/my_widget_stage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MyWidgetStageData extends WidgetStageData {
String get name => 'MyWidget';

@override
Size get stageSize => const Size(200, 200);
Size get stageSize => const Size(400, 200);

final ColorFieldConfiguratorNullable _color;
final ColorFieldConfiguratorNullable _borderColor;
Expand Down
5 changes: 4 additions & 1 deletion lib/src/stage_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StageController extends ChangeNotifier {
Color? backgroundColor,
}) : initialBackgroundColor = backgroundColor ?? const Color(0xFFE0E0E0),
_stagePosition = stagePosition ?? const Offset(50, 50),
_stageSize = stageSize ?? const Size(300, 400);
_stageSize = stageSize ?? const Size(400, 800);

Offset _stagePosition;

Expand Down Expand Up @@ -76,6 +76,9 @@ class StageController extends ChangeNotifier {
configurator.addListener(notifyListeners);
}
}
if (selectedWidget.stageSize != null) {
stageSize = selectedWidget.stageSize!;
}
notifyListeners();
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/widgets/stage_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class _StageAreaState extends State<StageArea> {
widget.stageController.addListener(() {
setState(() {
handleBallSize = widget.stageController.scale(widget.settings.handleBallSize);
widget.stageController.stagePosition = Offset(
(_currentConstraints!.maxWidth / 2) - (widget.stageController.stageSize.width / 2),
(_currentConstraints!.maxHeight / 2) - (widget.stageController.stageSize.height / 2),
);
});
});
// center the stage in the middle of the available space
Expand Down
10 changes: 6 additions & 4 deletions lib/src/widgets/stage_craft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ class StageCraft extends StatefulWidget {
super.key,
this.stageController,
this.configurationBarFooter,
Size? stageSize,
this.stageSize,
StageCraftSettings? settings,
this.stageData,
}) : stageSize = stageSize ?? const Size(600, 800),
settings = settings ??
}) : settings = settings ??
StageCraftSettings(
handleBallSize: 20,
handleBallColor: const Color(0xFF185DE3).withOpacity(0.8),
Expand All @@ -31,7 +30,7 @@ class StageCraft extends StatefulWidget {
final StageController? stageController;

/// The size of the stage.
final Size stageSize;
final Size? stageSize;

/// The size of the handle balls.
final StageCraftSettings settings;
Expand All @@ -52,6 +51,9 @@ class _StageCraftState extends State<StageCraft> {
@override
void initState() {
super.initState();
if (widget.stageSize != null) {
_stageController.stageSize = widget.stageSize!;
}
if (widget.stageData != null) {
_stageController.selectWidget(widget.stageData!);
}
Expand Down

0 comments on commit 1db9d97

Please sign in to comment.