Skip to content

Commit

Permalink
make scrollbar actually update as we add lines, use physical scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Nov 24, 2018
1 parent 6ec4f9c commit 0a49254
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/condo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d"
Title="MainWindow" SizeToContent="WidthAndHeight">
<Grid Background="Black">
<ScrollViewer Name="scrollViewer" CanContentScroll="true">
<ScrollViewer Name="scrollViewer" CanContentScroll="false">
<local:Screen x:Name="screen" />
</ScrollViewer>
</Grid>
Expand Down
26 changes: 16 additions & 10 deletions src/condo/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public Screen(ConsoleBuffer.Buffer buffer)
{
args.MouseDevice.OverrideCursor = Cursors.IBeam;
};
this.MouseLeave += (sender, args) =>
{
args.MouseDevice.OverrideCursor = Cursors.Arrow;
};

this.Resize();
}
Expand All @@ -74,14 +78,16 @@ private void RenderFrame(object sender, EventArgs e)
{
if (this.redrawWatch.Elapsed >= MaxRedrawFrequency && this.shouldRedraw != 0)
{
var startLine = this.VerticalOffset / this.cellHeight;
var startLine = this.VerticalOffset;
this.shouldRedraw = 0;
this.Buffer.RenderFromLine(this, (int)startLine);
this.Redraw();
this.ScrollOwner?.UpdateLayout();
this.ScrollOwner.ScrollToVerticalOffset(this.VerticalOffset);
this.redrawWatch.Restart();
}

if (this.Buffer.CursorVisible)
if (this.Buffer.CursorVisible && this.VerticalOffset == this.ExtentHeight - this.ViewportHeight)
{
if (this.cursorBlinkWatch.Elapsed >= BlinkFrequency)
{
Expand Down Expand Up @@ -189,13 +195,13 @@ private void Redraw()
public bool CanVerticallyScroll { get; set; }
public bool CanHorizontallyScroll { get; set; }

public double ExtentWidth => this.Buffer.Width * this.cellWidth;
public double ExtentWidth => this.Buffer.Width;

public double ExtentHeight => this.consoleBufferSize * this.cellHeight;
public double ExtentHeight => this.consoleBufferSize;

public double ViewportWidth => this.Buffer.Width * this.cellWidth;
public double ViewportWidth => this.Buffer.Width;

public double ViewportHeight => this.Buffer.Height * this.cellHeight;
public double ViewportHeight => this.Buffer.Height;

public double HorizontalOffset => 0.0;

Expand Down Expand Up @@ -235,12 +241,12 @@ public void LineRight() { }

public void PageUp()
{
this.VerticalOffset -= this.Buffer.Height * this.cellHeight;
this.VerticalOffset -= this.Buffer.Height;
}

public void PageDown()
{
this.VerticalOffset += this.Buffer.Height * this.cellHeight;
this.VerticalOffset += this.Buffer.Height;
}

public void PageLeft() { }
Expand All @@ -249,12 +255,12 @@ public void PageRight() { }

public void MouseWheelUp()
{
this.VerticalOffset -= 3 * this.cellHeight;
this.VerticalOffset -= 3;
}

public void MouseWheelDown()
{
this.VerticalOffset += 3 * this.cellHeight;
this.VerticalOffset += 3;
}

public void MouseWheelLeft() { }
Expand Down

0 comments on commit 0a49254

Please sign in to comment.