flutter: Reuse more code, move code into View_mixin
This commit is contained in:
@@ -21,13 +21,8 @@ class DockWidget_flutter extends KDDockWidgetBindings.DockWidget_flutter
|
||||
{int options = 0, int layoutSaverOptions = 0})
|
||||
: super(uniqueName,
|
||||
options: options, layoutSaverOptions: layoutSaverOptions) {
|
||||
m_color = Colors.pink;
|
||||
initMixin(this, color: Colors.pink, debugName: "DockWidget");
|
||||
m_fillsParent = true;
|
||||
kddwView = this;
|
||||
final ffi.Pointer<ffi.Void> ptr = thisCpp.cast<ffi.Void>();
|
||||
widgetKey = GlobalObjectKey(ptr.address);
|
||||
flutterWidget = PositionedWidget(this, key: widgetKey);
|
||||
debugName = "DockWidget";
|
||||
print("DockWidget_flutter CTOR");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,8 @@ class Group_flutter extends KDDockWidgetBindings.Group_flutter with View_mixin {
|
||||
Group_flutter(
|
||||
KDDockWidgetBindings.Group? group, KDDockWidgetBindings.View? parent)
|
||||
: super(group, parent: parent) {
|
||||
m_color = Colors.greenAccent;
|
||||
kddwView = this;
|
||||
final ffi.Pointer<ffi.Void> ptr = thisCpp.cast<ffi.Void>();
|
||||
widgetKey = GlobalObjectKey(ptr.address);
|
||||
flutterWidget = PositionedWidget(this, key: widgetKey);
|
||||
debugName = "group";
|
||||
initMixin(this, color: Colors.greenAccent, debugName: "Group");
|
||||
|
||||
print("Group_flutter CTOR");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,23 +20,11 @@ class View_flutter extends KDDockWidgetBindings.View_flutter with View_mixin {
|
||||
KDDockWidgetBindings.View? parent,
|
||||
{int windowFlags = 0})
|
||||
: super(controller, type, parent, windowFlags: windowFlags) {
|
||||
initMixin();
|
||||
initMixin(this);
|
||||
}
|
||||
|
||||
View_flutter.fromCppPointer(var cppPointer, [var needsAutoDelete = false])
|
||||
: super.fromCppPointer(cppPointer, needsAutoDelete) {
|
||||
initMixin();
|
||||
}
|
||||
|
||||
void initMixin() {
|
||||
// The key is the C++ KDDockWidget pointer, which is stable and unique
|
||||
final ffi.Pointer<ffi.Void> ptr = thisCpp.cast<ffi.Void>();
|
||||
widgetKey = GlobalObjectKey(ptr.address);
|
||||
kddwView = this;
|
||||
flutterWidget = createFlutterWidget();
|
||||
}
|
||||
|
||||
Widget createFlutterWidget() {
|
||||
return PositionedWidget(this, key: widgetKey);
|
||||
initMixin(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,11 @@
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
import 'dart:ffi' as ffi;
|
||||
import 'package:KDDockWidgets/PositionedWidget.dart';
|
||||
import 'package:KDDockWidgetsBindings/Bindings.dart' as KDDockWidgetBindings;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'Group_flutter.dart';
|
||||
import 'View_flutter.dart';
|
||||
|
||||
class View_mixin {
|
||||
late final Widget flutterWidget;
|
||||
late final GlobalObjectKey<PositionedWidgetState> widgetKey;
|
||||
@@ -35,6 +32,18 @@ class View_mixin {
|
||||
|
||||
var childWidgets = <Widget>[];
|
||||
|
||||
void initMixin(var kddwView, {var color = Colors.red, var debugName = ""}) {
|
||||
this.kddwView = kddwView;
|
||||
m_color = color;
|
||||
this.debugName = debugName;
|
||||
|
||||
// The key is the C++ View pointer, which is stable and unique
|
||||
final ffi.Pointer<ffi.Void> ptr = kddwView.thisCpp.cast<ffi.Void>();
|
||||
widgetKey = GlobalObjectKey(ptr.address);
|
||||
|
||||
flutterWidget = createFlutterWidget();
|
||||
}
|
||||
|
||||
setSize_2(int width, int height) {
|
||||
// print(
|
||||
// "View_mixin::setSize called ${width}x${height} ; old=${m_width}x${height}");
|
||||
@@ -128,4 +137,8 @@ class View_mixin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget createFlutterWidget() {
|
||||
return PositionedWidget(this, key: widgetKey);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user