You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
using Mindmagma.Curses;
|
|
|
|
namespace SCI.CursesWrapper.UiElements;
|
|
|
|
public class FooterWindow : Window {
|
|
private string leftText = "";
|
|
private string rightText = "";
|
|
private string titleText = "";
|
|
|
|
/// <summary>
|
|
/// Class constructor
|
|
/// </summary>
|
|
/// <param name="screen">Root NCurses screen ID</param>
|
|
/// <param name="defaultTitle">Initial title to show</param>
|
|
public FooterWindow (nint screen, string defaultTitle = "") :
|
|
base (0, CursesWrapper.GetHeight (screen) - 1, CursesWrapper.GetWidth (screen), 1)
|
|
{
|
|
var colorSchemeNormal = ColorSchemes.TopMenuNormal ();
|
|
BackgroundColorId = colorSchemeNormal;
|
|
NCurses.WindowAttributeOn (WindowId, colorSchemeNormal);
|
|
|
|
DrawFooter (defaultTitle);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Draw the footer window and insert the specified text
|
|
/// </summary>
|
|
/// <param name="title"></param>
|
|
/// <param name="left"></param>
|
|
/// <param name="right"></param>
|
|
public void DrawFooter (string? title = null, string? left = null, string? right = null) {
|
|
Clear ();
|
|
|
|
if (title is not null) titleText = title;
|
|
if (left is not null) leftText = left;
|
|
if (right is not null) rightText = right;
|
|
|
|
// TODO: Describe the last-character-in-window bug(fix) here
|
|
var pad =
|
|
(WindowSize.Width / 2) -
|
|
(titleText.Length / 2)
|
|
- 1;
|
|
|
|
var finalString =
|
|
" " + leftText.PadRight (pad) +
|
|
titleText +
|
|
(string.IsNullOrEmpty (rightText)?
|
|
"" :
|
|
rightText.PadLeft (pad)
|
|
);
|
|
|
|
// String too long, leave out left and right text
|
|
if (finalString.Length > WindowSize.Width - 1) {
|
|
finalString = " ".PadLeft (pad) + titleText;
|
|
}
|
|
|
|
// String still too long, leave out the padding and left align title
|
|
if (finalString.Length > WindowSize.Width - 1) {
|
|
finalString = " " + titleText;
|
|
}
|
|
|
|
// String still too long, cut to size
|
|
if (finalString.Length > WindowSize.Width - 1) {
|
|
finalString = titleText.Substring (0, WindowSize.Width - 1);
|
|
}
|
|
|
|
try {
|
|
NCurses.MoveWindowAddString (this, 0, 0, finalString);
|
|
Draw ();
|
|
} catch (Exception) {};
|
|
}
|
|
} |