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.
64 lines
1.7 KiB
64 lines
1.7 KiB
4 weeks ago
|
using Mindmagma.Curses;
|
||
|
|
||
|
namespace SCI.CursesWrapper.UiElements;
|
||
|
|
||
|
public class FooterWindow : Window {
|
||
|
/// <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, string left = "", string right = "") {
|
||
|
Clear ();
|
||
|
|
||
|
// TODO: Describe the last-character-in-window bug(fix) here
|
||
|
var pad =
|
||
|
(WindowSize.Width / 2) -
|
||
|
(title.Length / 2)
|
||
|
- 1;
|
||
|
|
||
|
var finalString =
|
||
|
" " + left.PadRight (pad) +
|
||
|
title +
|
||
|
(string.IsNullOrEmpty (right)?
|
||
|
"" :
|
||
|
right.PadLeft (pad)
|
||
|
);
|
||
|
|
||
|
// String too long, leave out left and right text
|
||
|
if (finalString.Length > WindowSize.Width - 1) {
|
||
|
finalString = " ".PadLeft (pad) + title;
|
||
|
}
|
||
|
|
||
|
// String still too long, leave out the padding and left align title
|
||
|
if (finalString.Length > WindowSize.Width - 1) {
|
||
|
finalString = " " + title;
|
||
|
}
|
||
|
|
||
|
// String still too long, cut to size
|
||
|
if (finalString.Length > WindowSize.Width - 1) {
|
||
|
finalString = title.Substring (0, WindowSize.Width - 1);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
NCurses.MoveWindowAddString (this, 0, 0, finalString);
|
||
|
Draw ();
|
||
|
} catch (Exception) {};
|
||
|
}
|
||
|
}
|