Просмотр исходного кода

Adds Padding option to TerminalView

devmil 4 лет назад
Родитель
Сommit
d744945bea
1 измененных файлов с 39 добавлено и 27 удалено
  1. 39 27
      lib/frontend/terminal_view.dart

+ 39 - 27
lib/frontend/terminal_view.dart

@@ -29,6 +29,7 @@ class TerminalView extends StatefulWidget {
     this.autofocus = false,
     ScrollController? scrollController,
     InputBehavior? inputBehavior,
+    this.padding = 0.0,
   })  : focusNode = focusNode ?? FocusNode(),
         scrollController = scrollController ?? ScrollController(),
         inputBehavior = inputBehavior ?? InputBehaviors.platform,
@@ -42,6 +43,8 @@ class TerminalView extends StatefulWidget {
   final TerminalStyle style;
   final double opacity;
 
+  final double padding;
+
   final InputBehavior inputBehavior;
 
   // get the dimensions of a rendered character
@@ -165,7 +168,9 @@ class _TerminalViewState extends State<TerminalView> {
       child: MouseRegion(
         cursor: SystemMouseCursors.text,
         child: LayoutBuilder(builder: (context, constraints) {
-          onWidgetSize(constraints.maxWidth, constraints.maxHeight);
+          onWidgetSize(constraints.maxWidth - widget.padding * 2,
+              constraints.maxHeight - widget.padding * 2);
+
           // use flutter's Scrollable to manage scrolling to better integrate
           // with widgets such as Scrollbar.
           return NotificationListener<ScrollNotification>(
@@ -186,16 +191,20 @@ class _TerminalViewState extends State<TerminalView> {
                   );
                 }
 
+                final viewPortHeight =
+                    constraints.maxHeight - widget.padding * 2;
+
                 // set viewport height.
-                offset.applyViewportDimension(constraints.maxHeight);
+                offset.applyViewportDimension(viewPortHeight);
 
                 if (widget.terminal.isReady) {
                   final minScrollExtent = 0.0;
 
                   final maxScrollExtent = math.max(
                       0.0,
-                      _cellSize.cellHeight * widget.terminal.bufferHeight -
-                          constraints.maxHeight);
+                      _cellSize.cellHeight *
+                          (widget.terminal.bufferHeight -
+                              widget.terminal.terminalHeight));
 
                   // set how much the terminal can scroll
                   offset.applyContentDimensions(
@@ -260,29 +269,32 @@ class _TerminalViewState extends State<TerminalView> {
       },
       child: Container(
         constraints: BoxConstraints.expand(),
-        child: Stack(
-          children: <Widget>[
-            CustomPaint(
-              painter: TerminalPainter(
-                terminal: widget.terminal,
-                style: widget.style,
-                charSize: _cellSize,
-                textLayoutCache: textLayoutCache,
+        child: Padding(
+          padding: EdgeInsets.all(widget.padding),
+          child: Stack(
+            children: <Widget>[
+              CustomPaint(
+                painter: TerminalPainter(
+                  terminal: widget.terminal,
+                  style: widget.style,
+                  charSize: _cellSize,
+                  textLayoutCache: textLayoutCache,
+                ),
               ),
-            ),
-            Positioned(
-              child: CursorView(
-                terminal: widget.terminal,
-                cellSize: _cellSize,
-                focusNode: widget.focusNode,
-                blinkOscillator: blinkOscillator,
+              Positioned(
+                child: CursorView(
+                  terminal: widget.terminal,
+                  cellSize: _cellSize,
+                  focusNode: widget.focusNode,
+                  blinkOscillator: blinkOscillator,
+                ),
+                width: _cellSize.cellWidth,
+                height: _cellSize.cellHeight,
+                left: _getCursorOffset().dx,
+                top: _getCursorOffset().dy,
               ),
-              width: _cellSize.cellWidth,
-              height: _cellSize.cellHeight,
-              left: _getCursorOffset().dx,
-              top: _getCursorOffset().dy,
-            ),
-          ],
+            ],
+          ),
         ),
         color: Color(widget.terminal.backgroundColor).withOpacity(
           widget.opacity,
@@ -301,8 +313,8 @@ class _TerminalViewState extends State<TerminalView> {
 
   /// Get global cell position from mouse position.
   Position getMouseOffset(double px, double py) {
-    final col = (px / _cellSize.cellWidth).floor();
-    final row = (py / _cellSize.cellHeight).floor();
+    final col = ((px - widget.padding) / _cellSize.cellWidth).floor();
+    final row = ((py - widget.padding) / _cellSize.cellHeight).floor();
 
     final x = col;
     final y = widget.terminal.convertViewLineToRawLine(row) -