Skip to content

Commit

Permalink
Add scroll bars
Browse files Browse the repository at this point in the history
  • Loading branch information
Twometer committed May 28, 2021
1 parent 20d8f8c commit 4eaa0f7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
18 changes: 9 additions & 9 deletions NoFences/FenceWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 40 additions & 3 deletions NoFences/FenceWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public partial class FenceWindow : Form
private bool isMinified;
private int prevHeight;

private int scrollHeight;
private int scrollOffset;

private ThrottledExecution throttledMove = new ThrottledExecution(TimeSpan.FromSeconds(4));
private ThrottledExecution throttledResize = new ThrottledExecution(TimeSpan.FromSeconds(4));

Expand All @@ -56,9 +59,10 @@ public FenceWindow(FenceInfo fenceInfo)
DropShadow.ApplyShadows(this);
BlurUtil.EnableBlur(Handle);
WindowUtil.HideFromAltTab(Handle);
DesktopUtil.GlueToDesktop(Handle);
DesktopUtil.PreventMinimize(Handle);
//DesktopUtil.GlueToDesktop(Handle);
//DesktopUtil.PreventMinimize(Handle);
this.titleHeight = fenceInfo.TitleHeight;
this.MouseWheel += FenceWindow_MouseWheel;
if (titleHeight < 16 || titleHeight > 100)
titleHeight = 35;

Expand Down Expand Up @@ -256,6 +260,7 @@ private void FenceWindow_DoubleClick(object sender, EventArgs e)

private void FenceWindow_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clip = new Region(ClientRectangle);
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

Expand All @@ -269,11 +274,18 @@ private void FenceWindow_Paint(object sender, PaintEventArgs e)
// Items
var x = itemPadding;
var y = itemPadding;
scrollHeight = 0;
e.Graphics.Clip = new Region(new Rectangle(0, titleHeight, Width, Height - titleHeight));
foreach (var file in fenceInfo.Files)
{
if (!File.Exists(file))
continue;
RenderFile(e.Graphics, file, x, y + titleHeight);
RenderFile(e.Graphics, file, x, y + titleHeight - scrollOffset);

var itemBottom = y + itemHeight;
if (itemBottom > scrollHeight)
scrollHeight = itemBottom;

x += itemWidth + itemPadding;
if (x + itemWidth > Width)
{
Expand All @@ -282,6 +294,17 @@ private void FenceWindow_Paint(object sender, PaintEventArgs e)
}
}

scrollHeight -= (ClientRectangle.Height - titleHeight);

// Scroll bars
if (scrollHeight > 0)
{
var contentHeight = Height - titleHeight;
var scrollbarHeight = contentHeight - scrollHeight;
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.Black)), new Rectangle(Width - 5, titleHeight + scrollOffset, 5, scrollbarHeight));
}

// Click handlers
if (shouldUpdateSelection && !hasSelectionUpdated)
selectedItem = null;

Expand Down Expand Up @@ -453,6 +476,20 @@ private void FenceWindow_MouseClick(object sender, MouseEventArgs e)
appContextMenu.Show(this, e.Location);
}
}

private void FenceWindow_MouseWheel(object sender, MouseEventArgs e)
{
if (scrollHeight < 1)
return;

scrollOffset -= Math.Sign(e.Delta) * 10;
if (scrollOffset < 0)
scrollOffset = 0;
if (scrollOffset > scrollHeight)
scrollOffset = scrollHeight;

Invalidate();
}
}

}
Expand Down

0 comments on commit 4eaa0f7

Please sign in to comment.