Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6402f3a
Remove continous press code from Application
tznind Jun 3, 2025
a7a5d1a
WIP prototype code to handle continuous press as subcomponent of View
tznind Jun 3, 2025
8f43909
Prototype with Button
tznind Jun 3, 2025
cbb20ff
Implement CWP
tznind Jun 3, 2025
b91a9ca
Move to seperate classes and prevent double entry to Start
tznind Jun 4, 2025
a19145a
Fix repeat clicking when moving mouse by removing phantom click code …
tznind Jun 4, 2025
d8335c4
Remove initial tick because it results in double activation e.g. butt…
tznind Jun 4, 2025
98947ba
Refactor DatePicker lamdas
tznind Jun 14, 2025
e946638
Merge branch 'v2_develop' into 4101_continuous_press
tznind Jun 14, 2025
550ef03
WIP investigate subcomponents instead of statics
tznind Jun 14, 2025
a28cc6c
Add IMouseGrabHandler to IApplication
tznind Jun 14, 2025
6d794f2
Make mouse grabbing non static activity
tznind Jun 14, 2025
ee7ea86
Make MouseHeldDown suppress when null fields e.g. app not initialized…
tznind Jun 14, 2025
887631d
Update test and remove dependency on Application
tznind Jun 14, 2025
0d75ef0
Fix other mouse click and hold tests
tznind Jun 14, 2025
c3c6c70
Code cleanup
tznind Jun 14, 2025
f717be5
Update class diagram
tznind Jun 14, 2025
32d747a
Fix bad xml doc references
tznind Jun 14, 2025
e9a33cb
Fix timed events not getting passed through in v2 applications
tznind Jun 14, 2025
48e80f3
Make timed events nullable for tests that dont create an Application
tznind Jun 14, 2025
06e45e1
Remove strange blocking test
tznind Jun 15, 2025
c106ff0
WIP remove all idles and replace with zero timeouts
tznind Jun 19, 2025
6f11fd6
Fix build of tests
tznind Jun 19, 2025
c597454
Fix unit tests
tznind Jun 20, 2025
aba2e43
Add wakeup call back in
tznind Jun 20, 2025
2dfe6b3
Comment out incredibly complicated test and fix others
tznind Jun 20, 2025
f18b752
Fix test
tznind Jun 20, 2025
34bc316
test fix
tznind Jun 20, 2025
0016a18
Make Post execute immediately if already on UI thread
tznind Jun 20, 2025
e85cccd
Re enable test and simplify Invoke to just execute if in UI thread (u…
tznind Jun 20, 2025
e4c7f0f
Remove xml doc references to idles
tznind Jun 21, 2025
e13ed63
Remove more references to idles
tznind Jun 21, 2025
c588e04
Make Screen initialization threadsafe
tznind Jun 21, 2025
c2390ad
merge 4101_continuous_press into branch
tznind Jun 21, 2025
49dc897
Add more exciting timeouts
tznind Jun 21, 2025
394794a
WIP add tests
tznind Jun 21, 2025
308b26f
fix log
tznind Jun 21, 2025
e20b489
fix test
tznind Jun 21, 2025
78c5d0d
make continuous key press use smoth acceleration
tznind Jun 21, 2025
966178e
Rename _lock to _lockScreen
tznind Jun 21, 2025
8721ea3
Remove section on idles, they are not a thing anymore - and they kind…
tznind Jun 21, 2025
53de140
Add nullable enable
tznind Jun 21, 2025
7fb15fa
Add xml comment
tznind Jun 21, 2025
889e071
Fix namings and cleanup code
tznind Jun 21, 2025
77e8675
Merge branch 'v2_develop' into logarithmic-timeout
tig Jun 24, 2025
144b027
Merge branch 'v2_develop' into logarithmic-timeout
tig Jun 27, 2025
de953f7
Merge branch 'v2_develop' into logarithmic-timeout
tznind Jul 5, 2025
f6b9fe7
xmldoc fix
tznind Jul 5, 2025
65207ad
Rename LockAndRunTimers to just RunTimers
tznind Jul 5, 2025
079a4c5
Rename AddTimeout and RemoveTimeout (and event) to just Add/Remove
tznind Jul 5, 2025
768e5bd
Update description of MainLoop
tznind Jul 5, 2025
fb19bfa
Merge branch 'v2_develop' into logarithmic-timeout
tig Jul 7, 2025
87fe518
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Jul 7, 2025
62fd462
Merge branch 'v2_develop' of tig:tig/Terminal.Gui into v2_develop
tig Jul 7, 2025
1efaf49
Merge branch 'v2_develop' into logarithmic-timeout
tig Jul 7, 2025
837298a
Merge branch 'logarithmic-timeout' of github.com:tznind/gui.cs into t…
tig Jul 7, 2025
a1ea545
Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver
tig Jul 7, 2025
8abb13c
Again? Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_…
tig Jul 7, 2025
6515d88
Revert Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_…
tig Jul 7, 2025
a938fc1
When mouse is released from MouseHeldDown reset host MouseState
tznind Jul 9, 2025
ad8248a
Fix namespaces in class diagram
tznind Jul 10, 2025
ee22ef8
Apply @BDisp suggested fix
tznind Jul 10, 2025
d47defc
Fix class diagrams
tznind Jul 10, 2025
c477cce
Add lock
tznind Jul 10, 2025
28787e8
Make TimeSpan.Zero definetly run
tznind Jul 10, 2025
5fc2e48
Fix duplicate entry in package props
tznind Jul 10, 2025
47aa0cd
Code cleanup and better API docs
tig Jul 10, 2025
6894b58
Merge pull request #178 from tig/tznind-logarithmic-timeout
tznind Jul 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more exciting timeouts
  • Loading branch information
tznind committed Jun 21, 2025
commit 49dc89768d8c9b2bfc19a3babe95c88036b1e17a
88 changes: 88 additions & 0 deletions Examples/UICatalog/Scenarios/Threading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public class Threading : Scenario
private ListView _logJob;
private Action _sync;

private LogarithmicTimeout _logarithmicTimeout;
private NumericUpDown _numberLog;
private Button _btnLogarithmic;
private object _timeoutObj;

private SmoothAcceleratingTimeout _smoothTimeout;
private NumericUpDown _numberSmooth;
private Button _btnSmooth;
private object _timeoutObjSmooth;

public override void Main ()
{
Application.Init ();
Expand Down Expand Up @@ -82,6 +92,35 @@ public override void Main ()

var text = new TextField { X = 1, Y = 3, Width = 100, Text = "Type anything after press the button" };

_btnLogarithmic = new Button ()
{
X = 50,
Y = 4,
Text = "Start Log Counter"
};
_btnLogarithmic.Accepting += StartStopLogTimeout;

_numberLog = new NumericUpDown ()
{
X = Pos.Right (_btnLogarithmic),
Y = 4,
};

_btnSmooth = new Button ()
{
X = Pos.Right (_numberLog),
Y = 4,
Text = "Start Smooth Counter"
};
_btnSmooth.Accepting += StartStopSmoothTimeout;

_numberSmooth = new NumericUpDown ()
{
X = Pos.Right (_btnSmooth),
Y = 4,
};


var btnAction = new Button { X = 80, Y = 10, Text = "Load Data Action" };
btnAction.Accepting += (s, e) => _action.Invoke ();
var btnLambda = new Button { X = 80, Y = 12, Text = "Load Data Lambda" };
Expand All @@ -107,6 +146,10 @@ public override void Main ()
_btnActionCancel,
_logJob,
text,
_btnLogarithmic,
_numberLog,
_btnSmooth,
_numberSmooth,
btnAction,
btnLambda,
btnHandler,
Expand All @@ -129,6 +172,51 @@ void Win_Loaded (object sender, EventArgs args)
Application.Shutdown ();
}

private bool LogTimeout ()
{
_numberLog.Value++;
_logarithmicTimeout.AdvanceStage ();
return true;
}
private bool SmoothTimeout ()
{
_numberSmooth.Value++;
_smoothTimeout.AdvanceStage ();
return true;
}

private void StartStopLogTimeout (object sender, CommandEventArgs e)
{
if (_timeoutObj != null)
{
_btnLogarithmic.Text = "Start Log Counter";
Application.TimedEvents.RemoveTimeout (_timeoutObj);
_timeoutObj = null;
}
else
{
_btnLogarithmic.Text = "Stop Log Counter";
_logarithmicTimeout = new LogarithmicTimeout (TimeSpan.FromMilliseconds (500), LogTimeout);
_timeoutObj = Application.TimedEvents.AddTimeout (_logarithmicTimeout);
}
}

private void StartStopSmoothTimeout (object sender, CommandEventArgs e)
{
if (_timeoutObjSmooth != null)
{
_btnSmooth.Text = "Start Smooth Counter";
Application.TimedEvents.RemoveTimeout (_timeoutObjSmooth);
_timeoutObjSmooth = null;
}
else
{
_btnSmooth.Text = "Stop Smooth Counter";
_smoothTimeout = new SmoothAcceleratingTimeout (TimeSpan.FromMilliseconds (500), TimeSpan.FromMilliseconds (50), 0.5, SmoothTimeout);
_timeoutObjSmooth = Application.TimedEvents.AddTimeout (_smoothTimeout);
}
}

private async void CallLoadItemsAsync ()
{
_cancellationTokenSource = new CancellationTokenSource ();
Expand Down
3 changes: 3 additions & 0 deletions Terminal.Gui/App/ITimedEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface ITimedEvents
/// </remarks>
object AddTimeout (TimeSpan time, Func<bool> callback);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Timeout" in AddTimeout is superfluous, now right? This and RemoveTimeout can be just Add and Remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 079a4c5


/// <inheritdoc cref="AddTimeout(System.TimeSpan,System.Func{bool})"/>
object AddTimeout (Timeout timeout);

/// <summary>Removes a previously scheduled timeout</summary>
/// <remarks>The token parameter is the value returned by AddTimeout.</remarks>
/// <returns>
Expand Down
43 changes: 43 additions & 0 deletions Terminal.Gui/App/LogarithmicTimeout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Terminal.Gui.App;

/// <summary>Implements a logarithmic increasing timeout.</summary>
public class LogarithmicTimeout : Timeout
{
private int stage = 0;
private readonly TimeSpan baseDelay;

public LogarithmicTimeout (TimeSpan baseDelay, Func<bool> callback)
{
this.baseDelay = baseDelay;
this.Callback = callback;
}

/// <summary>Gets the current calculated Span based on the stage.</summary>
public override TimeSpan Span
{
get
{
// For stage 0, return base delay directly
if (stage == 0)
{
return baseDelay;
}

// Calculate logarithmic increase
double multiplier = Math.Log (stage + 1); // ln(stage + 1)
return TimeSpan.FromMilliseconds (baseDelay.TotalMilliseconds * multiplier);
}
}

/// <summary>Increments the stage to increase the timeout.</summary>
public void AdvanceStage ()
{
stage++;
}

/// <summary>Resets the stage back to zero.</summary>
public void Reset ()
{
stage = 0;
}
}
58 changes: 58 additions & 0 deletions Terminal.Gui/App/SmoothAcceleratingTimeout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace Terminal.Gui.App;

/// <summary>
/// Timeout which accelerates slowly at first then fast up to a maximum speed.
/// Use <see cref="AdvanceStage"/> to increment the stage of the timer (e.g. in
/// your timer callback code).
/// </summary>
public class SmoothAcceleratingTimeout : Timeout
{
private int stage = 0;
private readonly TimeSpan initialDelay;
private readonly TimeSpan minDelay;
private readonly double decayFactor;

/// <summary>
/// Creates a new instance of the smooth acceleration timeout.
/// </summary>
/// <param name="initialDelay">Delay before first tick, the longest it will ever take</param>
/// <param name="minDelay">The fastest the timer can get no matter how long it runs</param>
/// <param name="decayFactor">Controls how fast the timer accelerates</param>
/// <param name="callback">Method to call when timer ticks</param>
public SmoothAcceleratingTimeout (TimeSpan initialDelay, TimeSpan minDelay, double decayFactor, Func<bool> callback)
{
this.initialDelay = initialDelay;
this.minDelay = minDelay;
this.decayFactor = decayFactor;
this.Callback = callback;
}

/// <inheritdoc/>
public override TimeSpan Span
{
get
{
double initialMs = initialDelay.TotalMilliseconds;
double minMs = minDelay.TotalMilliseconds;
double delayMs = minMs + (initialMs - minMs) * Math.Pow (decayFactor, stage);
return TimeSpan.FromMilliseconds (delayMs);
}
}

/// <summary>
/// Advances the timer stage, this should be called from your timer callback or whenever
/// you want to advance the speed.
/// </summary>
public void AdvanceStage ()
{
stage++;
}

/// <summary>
/// Resets the timer to original speed.
/// </summary>
public void Reset ()
{
stage = 0;
}
}
7 changes: 7 additions & 0 deletions Terminal.Gui/App/TimedEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public object AddTimeout (TimeSpan time, Func<bool> callback)
return timeout;
}

/// <inheritdoc />
public object AddTimeout (Timeout timeout)
{
AddTimeout (timeout.Span, timeout);
return timeout;
}

/// <inheritdoc/>
public bool CheckTimers(out int waitTimeout)
{
Expand Down
7 changes: 4 additions & 3 deletions Terminal.Gui/App/Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

namespace Terminal.Gui.App;


/// <summary>Provides data for timers running manipulation.</summary>
public sealed class Timeout
public class Timeout
{
/// <summary>The function that will be invoked.</summary>
public Func<bool> Callback;

/// <summary>Time to wait before invoke the callback.</summary>
public TimeSpan Span;
}
public virtual TimeSpan Span { get; set; }
}