using Mindmagma.Curses; namespace SCI.CursesWrapper.UiElements; public class FooterWindow : Window { private string leftText = ""; private string rightText = ""; private string titleText = ""; /// /// Class constructor /// /// Root NCurses screen ID /// Initial title to show 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); } /// /// Draw the footer window and insert the specified text /// /// /// /// 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) {}; } }