using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using Terminal.Gui; namespace UICatalog.Scenarios; [ScenarioMetadata ("ASCIICustomButtonTest", "ASCIICustomButton sample")] [ScenarioCategory ("Controls")] public class ASCIICustomButtonTest : Scenario { private static bool _smallerWindow; private MenuItem _miSmallerWindow; private ScrollViewTestWindow _scrollViewTestWindow; public override void Main () { _smallerWindow = false; Application.Init (); Toplevel top = new (); var menu = new MenuBar { Menus = [ new MenuBarItem ( "_Window Size", new [] { _miSmallerWindow = new MenuItem ( "Smaller Window", "", ChangeWindowSize ) { CheckType = MenuItemCheckStyle .Checked }, null, new MenuItem ( "Quit", "", () => Application.RequestStop (), null, null, (KeyCode)Application.QuitKey ) } ) ] }; _scrollViewTestWindow = new ScrollViewTestWindow (); top.Add (menu, _scrollViewTestWindow); Application.Run (top); top.Dispose (); Application.Shutdown (); return; void ChangeWindowSize () { _smallerWindow = (bool)(_miSmallerWindow.Checked = !_miSmallerWindow.Checked); top.Remove (_scrollViewTestWindow); _scrollViewTestWindow.Dispose (); _scrollViewTestWindow = new ScrollViewTestWindow (); top.Add (_scrollViewTestWindow); } } public class ASCIICustomButton : Button { private FrameView _border; private Label _fill; public string Description => $"Description of: {Id}"; public void CustomInitialize () { _border = new FrameView { Width = Width, Height = Height }; var fillText = new StringBuilder (); for (var i = 0; i < Viewport.Height; i++) { if (i > 0) { fillText.AppendLine (""); } for (var j = 0; j < Viewport.Width; j++) { fillText.Append ("█"); } } _fill = new Label { Visible = false, CanFocus = false, Text = fillText.ToString () }; var title = new Label { X = Pos.Center (), Y = Pos.Center (), Text = Text }; _border.MouseClick += This_MouseClick; _fill.MouseClick += This_MouseClick; title.MouseClick += This_MouseClick; Add (_border, _fill, title); } public override bool OnEnter (View view) { _border.Visible = false; _fill.Visible = true; PointerEnter.Invoke (this); view = this; return base.OnEnter (view); } public override bool OnLeave (View view) { _border.Visible = true; _fill.Visible = false; if (view == null) { view = this; } return base.OnLeave (view); } public event Action PointerEnter; private void This_MouseClick (object sender, MouseEventEventArgs obj) { NewMouseEvent (obj.MouseEvent); } } public class ScrollViewTestWindow : Window { private const int BUTTON_HEIGHT = 3; private const int BUTTON_WIDTH = 25; private const int BUTTONS_ON_PAGE = 7; private readonly List