| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #nullable enable
- using System;
- namespace UICatalog.Scenarios;
- /// <summary>
- /// Provides an editor UI for the Margin, Border, and Padding of a View.
- /// </summary>
- public class AdornmentsEditor : EditorBase
- {
- public AdornmentsEditor ()
- {
- Title = "AdornmentsEditor";
- TabStop = TabBehavior.TabGroup;
- ExpanderButton!.Orientation = Orientation.Horizontal;
- Initialized += AdornmentsEditor_Initialized;
- SchemeName = "Dialog";
- }
- public MarginEditor? MarginEditor { get; set; }
- public BorderEditor? BorderEditor { get; private set; }
- public PaddingEditor? PaddingEditor { get; private set; }
- /// <inheritdoc/>
- protected override void OnViewToEditChanged ()
- {
- //Enabled = ViewToEdit is not Adornment;
- if (MarginEditor is { })
- {
- MarginEditor.AdornmentToEdit = ViewToEdit?.Margin ?? null;
- }
- if (BorderEditor is { })
- {
- BorderEditor.AdornmentToEdit = ViewToEdit?.Border ?? null;
- }
- if (PaddingEditor is { })
- {
- PaddingEditor.AdornmentToEdit = ViewToEdit?.Padding ?? null;
- }
- if (Padding is { })
- {
- Padding.Text = $"View: {GetIdentifyingString (ViewToEdit)}";
- }
- }
- private string GetIdentifyingString (View? view)
- {
- if (view is null)
- {
- return "null";
- }
- if (!string.IsNullOrEmpty (view.Id))
- {
- return view.Id;
- }
- if (!string.IsNullOrEmpty (view.Title))
- {
- return view.Title;
- }
- if (!string.IsNullOrEmpty (view.Text))
- {
- return view.Text;
- }
- return view.GetType ().Name;
- }
- public bool ShowViewIdentifier
- {
- get => Padding is { } && Padding.Thickness != Thickness.Empty;
- set
- {
- if (Padding is null)
- {
- return;
- }
- Padding.Thickness = value ? new (0, 2, 0, 0) : Thickness.Empty;
- }
- }
- private void AdornmentsEditor_Initialized (object? sender, EventArgs e)
- {
- MarginEditor = new ()
- {
- X = -1,
- Y = 0,
- SuperViewRendersLineCanvas = true,
- BorderStyle = LineStyle.Single
- };
- MarginEditor.Border!.Thickness = MarginEditor.Border.Thickness with { Bottom = 0 };
- Add (MarginEditor);
- BorderEditor = new ()
- {
- X = Pos.Left (MarginEditor),
- Y = Pos.Bottom (MarginEditor),
- SuperViewRendersLineCanvas = true,
- BorderStyle = LineStyle.Single
- };
- BorderEditor.Border!.Thickness = BorderEditor.Border.Thickness with { Bottom = 0 };
- Add (BorderEditor);
- PaddingEditor = new ()
- {
- X = Pos.Left (BorderEditor),
- Y = Pos.Bottom (BorderEditor),
- SuperViewRendersLineCanvas = true,
- BorderStyle = LineStyle.Single
- };
- PaddingEditor.Border!.Thickness = PaddingEditor.Border.Thickness with { Bottom = 0 };
- Add (PaddingEditor);
- Width = Dim.Auto (maximumContentDim: Dim.Func (_ => MarginEditor.Frame.Width - 2));
- MarginEditor.ExpanderButton!.Collapsed = true;
- BorderEditor.ExpanderButton!.Collapsed = true;
- PaddingEditor.ExpanderButton!.Collapsed = true;
- MarginEditor.AdornmentToEdit = ViewToEdit?.Margin ?? null;
- BorderEditor.AdornmentToEdit = ViewToEdit?.Border ?? null;
- PaddingEditor.AdornmentToEdit = ViewToEdit?.Padding ?? null;
- }
- }
|