Skip to content

Commit

Permalink
Fix ChoicesDialog
Browse files Browse the repository at this point in the history
- Remove TGD shadow drawing code now that it is part of main codebase
- Regenerate ChoicesDialog (load/save)
- Change to Dim.Auto for button Widths
- Fix bug in RecursivelyIgnoreAllNonDesignableSubviews when used during loading processes that incorrectly flagged sub views as 'non designable'
  • Loading branch information
tznind committed Feb 18, 2025
1 parent 50aac86 commit 88584d2
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 166 deletions.
5 changes: 1 addition & 4 deletions src/UI/MouseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MouseManager
public Rectangle? SelectionBox => RectExtensions.FromBetweenPoints(this.selectionStart, this.selectionEnd);

/// <summary>
/// Responds to <see cref="Application.RootMouseEvent"/>(by changing a 'drag a box' selection area
/// Responds to <see cref="Application.MouseEvent"/>(by changing a 'drag a box' selection area
/// or starting a resize etc).
/// </summary>
/// <param name="m">The <see cref="MouseEventArgs"/> reported by <see cref="Application.RootMouseEvent"/>.</param>
Expand Down Expand Up @@ -123,9 +123,6 @@ public void HandleMouse(MouseEventArgs m, Design viewBeingEdited)
// move selection box to new mouse position
this.selectionEnd = m.Position;
viewBeingEdited.View.SetNeedsDraw();

// BUG: Method is gone, will this functionality work still without it?
// Application.DoEvents();
return;
}

Expand Down
238 changes: 128 additions & 110 deletions src/UI/Windows/ChoicesDialog.Designer.cs

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

53 changes: 2 additions & 51 deletions src/UI/Windows/ChoicesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,17 @@ public ChoicesDialog(string title, string message, params string[] options) {
{
// add space for right hand side shadow
buttons[i].Text = options[i] + " ";

// TODO think it depends if it is default if we have to do this hack
buttons[i].Width = Dim.Auto();


var i2 = i;

buttons[i].Accepting += (s,e) => {
Result = i2;
Application.RequestStop();
};

buttons[i].DrawComplete += (s,r) =>
ChoicesDialog.PaintShadow(buttons[i2], ColorScheme);
}

buttonPanel.LayoutSubviews();

// hide other buttons
for(int i=options.Length;i<buttons.Length;i++)
{
Expand Down Expand Up @@ -133,50 +128,6 @@ internal static int Query(string title, string message, params string[] options)
Application.Run(dlg);
return dlg.Result;
}

internal static void PaintShadow(Button btn, ColorScheme backgroundScheme)
{
var bounds = btn.GetContentSize();

Attribute buttonColor = btn.HasFocus ?
new Terminal.Gui.Attribute(btn.ColorScheme.Focus.Foreground, btn.ColorScheme.Focus.Background):
new Terminal.Gui.Attribute(btn.ColorScheme.Normal.Foreground, btn.ColorScheme.Normal.Background);

Driver.SetAttribute(buttonColor);

if (btn.IsDefault)
{
var rightDefault = Driver != null ? ConfigurationManager.Glyphs.RightDefaultIndicator : new Rune('>');

// draw the 'end' button symbol one in
btn.AddRune(bounds.Width - 3, 0, rightDefault);
}

btn.AddRune(bounds.Width - 2, 0, new System.Text.Rune(']'));
btn.AddRune(0, 0, new System.Text.Rune('['));

var backgroundColor = backgroundScheme.Normal.Background;

// shadow color
Driver.SetAttribute(new Terminal.Gui.Attribute(Color.Black, backgroundColor));

// end shadow (right)
btn.AddRune(bounds.Width - 1, 0, new System.Text.Rune('▄'));

// leave whitespace in lower left in parent/default background color
Driver.SetAttribute(new Terminal.Gui.Attribute(Color.Black, backgroundColor));
btn.AddRune(0, 1, new System.Text.Rune(' '));

// The color for rendering shadow is 'black' + parent/default background color
Driver.SetAttribute(new Terminal.Gui.Attribute(backgroundColor, Color.Black));

// underline shadow
for (int x = 1; x < bounds.Width; x++)
{
btn.AddRune(x, 1, new System.Text.Rune('▄'));
}
}

internal static bool Confirm(string title, string message, string okText = "Yes", string cancelText = "No")
{
var dlg = new ChoicesDialog(title, message, okText, cancelText);
Expand Down
6 changes: 5 additions & 1 deletion src/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,15 @@ private static void RecursivelyIgnoreAllNonDesignableSubviews(View view, List<Vi
{
foreach (var sub in view.Subviews)
{
if (sub.Data is not Design)
// If Data is string then it is likely a View that is going to
// end up having a Design but we haven't gotten to it yet (i.e. method is being called mid-load)
if (sub.Data is not Design and not string)
{
alsoIgnore.Add(sub);
}



RecursivelyIgnoreAllNonDesignableSubviews(sub, alsoIgnore);
}
}
Expand Down

0 comments on commit 88584d2

Please sign in to comment.