// // FrameView.cs: Frame control // // Authors: // Miguel de Icaza (miguel@gnome.org) // using System; using System.Collections; using System.Collections.Generic; using NStack; namespace Terminal.Gui { /// /// The FrameView is a container frame that draws a frame around the contents. It is similar to /// a GroupBox in Windows. /// public class FrameView : View { View contentView; ustring title; /// /// The title to be displayed for this . /// /// The title. public ustring Title { get => title; set { title = value; SetNeedsDisplay (); } } class ContentView : View { public ContentView (Rect frame) : base (frame) { } public ContentView () : base () { } } /// /// Initializes a new instance of the class with /// an absolute position and a title. /// /// Frame. /// Title. public FrameView (Rect frame, ustring title) : base (frame) { var cFrame = new Rect (1, 1 , frame.Width - 2, frame.Height - 2); this.title = title; contentView = new ContentView (cFrame); Initialize (); } /// /// Initializes a new instance of the class with /// an absolute position, a title and s. /// /// Frame. /// Title. /// /// Views. public FrameView (Rect frame, ustring title, View[] views) : this (frame, title) { foreach (var view in views) { contentView.Add (view); } Initialize (); } /// /// Initializes a new instance of the class with /// a title and the result is suitable to have its X, Y, Width and Height properties computed. /// /// Title. public FrameView (ustring title) { this.title = title; contentView = new ContentView () { X = 1, Y = 1, Width = Dim.Fill (1), Height = Dim.Fill (1) }; Initialize (); } void Initialize () { base.Add (contentView); } void DrawFrame () { DrawFrame (new Rect (0, 0, Frame.Width, Frame.Height), 0, fill: true); } /// /// Add the specified to this container. /// /// to add to this container public override void Add (View view) { contentView.Add (view); if (view.CanFocus) CanFocus = true; } /// /// Removes a from this container. /// /// /// public override void Remove (View view) { if (view == null) return; SetNeedsDisplay (); var touched = view.Frame; contentView.Remove (view); if (contentView.InternalSubviews.Count < 1) this.CanFocus = false; } /// /// Removes all s from this container. /// /// /// public override void RemoveAll() { contentView.RemoveAll(); } /// public override void Redraw (Rect bounds) { var padding = 0; Application.CurrentView = this; var scrRect = RectToScreen (new Rect (0, 0, Frame.Width, Frame.Height)); if (NeedDisplay != null && !NeedDisplay.IsEmpty) { Driver.SetAttribute (ColorScheme.Normal); Driver.DrawFrame (scrRect, padding, true); } if (Driver.Clip.IsEmpty || Driver.Clip.Contains (contentView.RectToScreen (contentView.Frame))) { var savedClip = ClipToBounds (); contentView.Redraw (contentView.Bounds); Driver.Clip = savedClip; } else { contentView.Redraw (contentView.Bounds); } ClearNeedsDisplay (); Driver.SetAttribute (ColorScheme.Normal); Driver.DrawFrame (scrRect, padding, false); if (HasFocus) Driver.SetAttribute (ColorScheme.HotNormal); Driver.DrawWindowTitle (scrRect, Title, padding, padding, padding, padding); Driver.SetAttribute (ColorScheme.Normal); } } }