Bugfix: ScrollBar Issue (#1428)

* Bugfix: ScrollBar Issue
Scrollbars not working with Mouse Drag
https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/issues/1406

* Format Update
added rule for line endings: lf
windows default is: cr+lf
reformat from crlf to lf

* Update code style

* Update ThemedVScrollIndicator.cs

---------

Co-authored-by: sebastian-dev <sebastian-dev>
Co-authored-by: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com>
This commit is contained in:
sebastian-dev
2024-08-16 23:45:19 +02:00
committed by GitHub
co-authored by sebastian-dev <sebastian-dev> PhyxionNL
parent 1118fde17d
commit 5476ac16c9
3 changed files with 107 additions and 4 deletions
+5 -4
View File
@@ -11,6 +11,7 @@ insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
end_of_line = lf
[project.json]
indent_size = 2
@@ -54,15 +55,15 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# static fields should have s_ prefix
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
@@ -72,7 +73,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case
# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
@@ -6,6 +6,9 @@ namespace LibreHardwareMonitor.UI.Themes
public class ThemedHScrollIndicator : Control
{
private readonly HScrollBar _scrollbar;
private int _startValue = 0;
private int _startPos = 0;
private bool _isScrolling = false;
public static void AddToControl(Control control)
{
@@ -39,6 +42,54 @@ namespace LibreHardwareMonitor.UI.Themes
scrollBar.ValueChanged += (s, e) => Invalidate();
scrollBar.Height = 0;
this.MouseDown += OnMouseDown;
}
private void OnMouseDown(object sender, MouseEventArgs e)
{
if (_isScrolling)
return;
_isScrolling = true;
//note: this.Capture is true when the control is clicked, no need to handle this
_startPos = e.X;
_startValue = _scrollbar.Value;
this.MouseUp += OnMouseUp;
this.MouseMove += OnMouseMove;
}
private void OnMouseUp(object sender, MouseEventArgs e)
{
_isScrolling = false;
this.MouseUp -= OnMouseUp;
this.MouseMove -= OnMouseMove;
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (!_isScrolling)
return;
//pixel to range scaling:
double totalRange = _scrollbar.Maximum - _scrollbar.Minimum;
if (totalRange <= 0)
return;
double scaleToPercent = totalRange / Bounds.Width;
double scrollValue = _startValue + (e.X - _startPos) * scaleToPercent;
if (scrollValue < _scrollbar.Minimum)
scrollValue = _scrollbar.Minimum;
if (scrollValue > (_scrollbar.Maximum - _scrollbar.LargeChange))
scrollValue = _scrollbar.Maximum - _scrollbar.LargeChange;
_scrollbar.Value = (int)scrollValue;
Refresh();
}
protected override void OnPaint(PaintEventArgs e)
@@ -6,6 +6,9 @@ namespace LibreHardwareMonitor.UI.Themes
public class ThemedVScrollIndicator : Control
{
private readonly VScrollBar _scrollbar;
private int _startValue = 0;
private int _startPos = 0;
private bool _isScrolling = false;
public static void AddToControl(Control control)
{
@@ -39,6 +42,54 @@ namespace LibreHardwareMonitor.UI.Themes
scrollBar.ValueChanged += (s, e) => Invalidate();
scrollBar.Width = 0;
this.MouseDown += OnMouseDown;
}
private void OnMouseDown(object sender, MouseEventArgs e)
{
if (_isScrolling)
return;
_isScrolling = true;
//note: this.Capture is true when the control is clicked, no need to handle this
_startPos = e.Y;
_startValue = _scrollbar.Value;
this.MouseUp += OnMouseUp;
this.MouseMove += OnMouseMove;
}
private void OnMouseUp(object sender, MouseEventArgs e)
{
_isScrolling = false;
this.MouseUp -= OnMouseUp;
this.MouseMove -= OnMouseMove;
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (!_isScrolling)
return;
//pixel to range scaling:
double totalRange = _scrollbar.Maximum - _scrollbar.Minimum;
if (totalRange <= 0)
return;
double scaleToPercent = totalRange / Bounds.Height;
double scrollValue = _startValue + (e.Y - _startPos) * scaleToPercent;
if (scrollValue < _scrollbar.Minimum)
scrollValue = _scrollbar.Minimum;
if (scrollValue > (_scrollbar.Maximum - _scrollbar.LargeChange))
scrollValue = _scrollbar.Maximum - _scrollbar.LargeChange;
_scrollbar.Value = (int)scrollValue;
Refresh();
}
protected override void OnPaint(PaintEventArgs e)