Skip to content

Commit d654542

Browse files
author
tznind
committed
Try to disable mouse events in color picker (WIP)
1 parent a612e83 commit d654542

6 files changed

Lines changed: 55 additions & 19 deletions

File tree

Showcase/Buttons.Designer.cs

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Showcase/Checkboxes.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Showcase/ColorPickers.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Design.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,25 @@ private void CreateSubControlDesigns(View view)
563563
}
564564
}
565565

566+
private void SuppressNativeClickEvents(ColorPicker cp)
567+
{
568+
569+
cp.MouseEvent += (s, e) => this.SuppressNativeClickEvents(s, e, true);
570+
cp.MouseEnter += (s, e) => e.Cancel = true;
571+
cp.MouseBindings.Clear();
572+
573+
foreach (var hue in cp.SubViews.OfType<ColorBar>())
574+
{
575+
// prevent control from responding to events
576+
hue.MouseEvent += (s, e) => this.SuppressNativeClickEvents(s, e, true);
577+
hue.MouseEnter += (s, e) => e.Cancel = true;
578+
hue.MouseBindings.Clear();
579+
580+
// Prevent the color picker bar from activating as the wiring for drag changing hue bar etc is tied to activate
581+
hue.RemoveCommand(Command.Activate);
582+
}
583+
}
584+
566585
private void SuppressNativeClickEvents(object? sender, Mouse obj, bool alsoSuppressClick = false)
567586
{
568587
if (alsoSuppressClick)
@@ -724,6 +743,8 @@ private IEnumerable<Property> LoadDesignableProperties()
724743
yield return this.CreateSubProperty(nameof(ColorPickerStyle.ColorModel),nameof(ColorPicker.Style),cp.Style);
725744
yield return this.CreateSubProperty(nameof(ColorPickerStyle.ShowColorName), nameof(ColorPicker.Style), cp.Style);
726745
yield return this.CreateSubProperty(nameof(ColorPickerStyle.ShowTextFields), nameof(ColorPicker.Style), cp.Style);
746+
747+
SuppressNativeClickEvents(cp);
727748
}
728749

729750
if (this.View is ListView lv)

src/TerminalGuiDesigner.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
</Content>
159159
</ItemGroup>
160160
<ItemGroup>
161-
<PackageReference Include="Terminal.Gui" Version="2.2.2" />
162161
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.7.7" />
163162
<PackageReference Include="CommandLineParser" Version="2.9.1" />
164163
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />

src/ViewExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Terminal.Gui.Input;
66
using Terminal.Gui.ViewBase;
77
using Terminal.Gui.Views;
8+
using static Terminal.Gui.ViewBase.View;
89

910
namespace TerminalGuiDesigner;
1011

@@ -470,4 +471,19 @@ public static bool AnySuperViewIs<T>(this View v) where T : View
470471

471472
return null;
472473
}
474+
475+
public static void RemoveCommand(this View v,Command c)
476+
{
477+
var commands = typeof(View).GetField("_commandImplementations", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(v)
478+
?? throw new Exception("Expected private field command implementations not found");
479+
480+
if(commands is Dictionary<Command, CommandImplementation> commandDict)
481+
{
482+
commandDict.Remove(c);
483+
}
484+
else
485+
{
486+
throw new Exception($"Expected _commandImplementations to be a Dictionary<Command, CommandImplementation> but it was {commands.GetType().Name}");
487+
}
488+
}
473489
}

0 commit comments

Comments
 (0)