Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
79a2b36
Support for selecting and resizing 'View' basic class
Oct 13, 2022
693a04f
Move border rendering to `DrawContentComplete`
Oct 13, 2022
81b247b
Always show dotted border on Borderless views
Oct 13, 2022
60ee032
Tests for `IsContainerView` and `IsBorderlessContainerView`
Oct 13, 2022
c79c701
Tests for TabView IsBorderlessContainerView
Oct 13, 2022
360011c
Move Enter callback into DesignState
Oct 13, 2022
a29240a
Update Readme.md to mark that `View` is now usable
Oct 13, 2022
49d5d38
Allow designing `View` as a root level class
Oct 17, 2022
1f36b3d
Make TopLevel a designable root Type
Oct 17, 2022
47ee5ff
Avoid clearing custom ColorScheme when opening a View
Oct 17, 2022
3e6b41e
Switch to using `Clear` instead of `DrawFrame` for invalidating View …
Oct 17, 2022
3f98f3c
Give TopLevel and View both the default color scheme
Oct 17, 2022
fafd819
Add shortcut for toggling borders on/off (Ctrl+B)
Oct 17, 2022
ee9eb2b
Fix loosing color scheme during selection events for View and TopLeve…
Oct 17, 2022
7a01bc8
Change border so it does not draw over content
Oct 18, 2022
5d8452e
Fix not being able to drag out of subcontainers into root when root i…
Oct 18, 2022
dba1c75
Add note to remove DrawContent hack when https://github.com/gui-cs/Te…
Oct 18, 2022
f0afe1e
Merge branch 'main' into add-view
Oct 18, 2022
47fca63
Merge branch 'main' into add-view
Oct 18, 2022
2fdb776
Set color before clearing
Oct 18, 2022
87310b6
Suppress native context menus better and fix `Clear` when original co…
Oct 18, 2022
ba871ae
merge main into add-view
Oct 28, 2022
046fb1f
Merge main into add-view
Oct 28, 2022
fe5948d
Remove bad merge rename fix
Oct 28, 2022
1fec734
Fix TestColorScheme_RoundTrip
Oct 28, 2022
dcc3173
Added --experimental flag to CLI
Oct 28, 2022
f3bb325
Mouse drag fixes and improvements
Oct 29, 2022
6bcb51a
Allow -e for experimental and document in README.md
Oct 29, 2022
7db9942
ViewFactory no longer creates TextField with Text property set (now b…
Oct 29, 2022
4fa46b9
Fix unit tests to have Designs
Oct 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ You can create a menu separator by typing `---`
### Features
-------------------------------

The following feature list shows the current capabilities and the roadmap
The following feature list shows the current capabilities and the roadmap. Features in
italics are experimental and require passing the `-e` flag when starting application.

- [x] Design classes
- [x] Window
- [x] Dialog
- [ ] View
- [ ] Top level (with statusbar and or menu)
- [x] _View_
- [x] _Top level_
- [x] Configure root properties (e.g. Window.Width, Title etc)
- [x] Configure subview properties
- [x] (Name)
Expand Down Expand Up @@ -203,7 +204,7 @@ The following feature list shows the current capabilities and the roadmap
- [x] TextView
- [x] TimeField
- [x] TreeView
- [ ] View
- [x] View

### Class Diagram
-------------------------------
Expand Down
221 changes: 132 additions & 89 deletions src/Design.cs

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions src/DesignState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Terminal.Gui;
using TerminalGuiDesigner.UI;

namespace TerminalGuiDesigner;

/// <summary>
/// Describes state based changes and custom callbacks on a <see cref="Design"/>
/// e.g. <see cref="OriginalScheme"/>
/// </summary>
public class DesignState
{
public ColorScheme? OriginalScheme { get; set; }
public Design Design{ get; }

public DesignState(Design design)
{
Design = design;
OriginalScheme = Design.View.GetExplicitColorScheme();
Design.View.DrawContent += DrawContent;
Design.View.Enter += Enter;
}

private void Enter(View.FocusEventArgs obj)
{
SelectionManager.Instance.SetSelection(Design);
}

private void DrawContent(Rect r)
{
if(Design.View.IsBorderlessContainerView() && Editor.ShowBorders)
{
DrawBorderlessViewFrame(r);
}
}

private void DrawBorderlessViewFrame(Rect r)
{
bool isSelected = SelectionManager.Instance.Selected.Contains(Design);

var color = isSelected ?
SelectionManager.Instance.SelectedScheme.Normal :
Design.View.ColorScheme.Normal;

Application.Driver.SetAttribute(color);

var v = Design.View;

for (int x = 0; x < r.Width ; x++)
for (int y = 0; y < r.Height; y++)
{
if (y == 0 || y == r.Height - 1 || x == 0 || x == r.Width - 1)
{
var rune = (y == r.Height - 1 && x == r.Width - 1 && isSelected) ? '╬' : '.';
v.AddRune(x,y,rune);
}
}
}
}
1 change: 1 addition & 0 deletions src/Keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Delete: DeleteChar
ToggleDragging: F3
AddView: F2
ToggleShowFocused: L, CtrlMask
ToggleShowBorders: B, CtrlMask
RightClick: Button3Clicked
Copy: C, CtrlMask
Paste: V, CtrlMask
Expand Down
6 changes: 3 additions & 3 deletions src/Operations/DragOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ private class DragMemento
public Pos OriginalX {get;}
public Pos OriginalY {get;}

public View OriginalSuperView {get;}
public View? OriginalSuperView {get;}

public DragMemento(Design design)
{
Design = design;
OriginalX = design.View.X;
OriginalY = design.View.Y;
OriginalSuperView = design.View.SuperView;
OriginalSuperView = design.View.SuperView?.GetNearestDesign()?.View;
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ private bool Do(DragMemento mem)
// if changing to a new container
if (DropInto != mem.OriginalSuperView && mem.OriginalSuperView != null)
{
mem.OriginalSuperView.Remove(mem.Design.View);
mem.Design.View.SuperView.Remove(mem.Design.View);
DropInto.Add(mem.Design.View);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public class Options

[Option( HelpText = "Enables UseSystemConsole, an alternative console display driver")]
public bool Usc { get;set; }


[Option( 'e', HelpText = "Enables experimental features")]
public bool Experimental { get;set; }

#nullable enable warnings

[Usage(ApplicationAlias = "TerminalGuiDesigner")]
Expand Down
1 change: 1 addition & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static void Main(string[] args)
.WithParsed<Options>(o =>
{
Application.UseSystemConsole = o.Usc;
Editor.Experimental = o.Experimental;

Application.Init();
var editor = new Editor();
Expand Down
35 changes: 5 additions & 30 deletions src/SelectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class SelectionManager
/// </summary>
public IReadOnlyCollection<Design> Selected => selection.AsReadOnly();

Dictionary<Design, ColorScheme?> oldSchemes = new();

/// <summary>
/// Set to true to prevent changes to the current <see cref="Selected"/>
/// collection (e.g. if running a modal dialog / context menu).
Expand Down Expand Up @@ -57,16 +55,8 @@ public ColorScheme SelectedScheme


public static SelectionManager Instance = new();
private ColorScheme selectedScheme;


public ColorScheme? GetOriginalExplicitColorScheme(Design design)
{
if (oldSchemes.ContainsKey(design))
return oldSchemes[design];
private ColorScheme? selectedScheme;

return null;
}

/// <summary>
/// Changes the selection without respecting <see cref="LockSelection"/>
Expand Down Expand Up @@ -99,40 +89,25 @@ private void SetSelection(bool respectLock, Design[] designs)

foreach (var d in selection)
{
// record the old color scheme so we can get reset it
// later when it is no longer selected
oldSchemes.Add(d, d.View.GetExplicitColorScheme());

// since the view is selected mark it so
d.View.ColorScheme = SelectedScheme;
}
}

/// <summary>
/// Updates the cached known ColorScheme (prior to selection). Use this method
/// if you are making changes to the ColorScheme of an actively selected object
/// </summary>
public void UpdateKnownScheme(Design design, ColorScheme? colorScheme)
{
if(oldSchemes.ContainsKey(design))
{
oldSchemes[design] = colorScheme;
}
}

public void Clear(bool respectLock = true)
{
if (LockSelection && respectLock)
return;

var selected = selection.ToArray();

selection.Clear();

// reset old color schemes so views don't still look selected
foreach (var kvp in oldSchemes)
foreach (var d in selected)
{
kvp.Key.View.ColorScheme = kvp.Value;
d.View.ColorScheme = d.State.OriginalScheme;
}
oldSchemes.Clear();
}

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions src/ToCode/ColorSchemeProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public override CodeExpression GetRhs()
}
public override object? GetValue()
{
if (SelectionManager.Instance.Selected.Contains(Design))
return SelectionManager.Instance.GetOriginalExplicitColorScheme(Design);

return Design.View.GetExplicitColorScheme();
return Design.State.OriginalScheme ?? Design.View.GetExplicitColorScheme();
}
protected override string GetHumanReadableValue()
{
Expand All @@ -62,6 +59,6 @@ public override void SetValue(object? value)
{
base.SetValue(value);

SelectionManager.Instance.UpdateKnownScheme(Design,value as ColorScheme);
Design.State.OriginalScheme = value as ColorScheme;
}
}
11 changes: 7 additions & 4 deletions src/ToCode/ViewToCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,25 @@ public Design GenerateNewView(FileInfo csFilePath, string namespaceName,Type vie
var csharpCode = GetGenerateNewViewCode(className, namespaceName);
File.WriteAllText(sourceFile.CsFile.FullName, csharpCode);

var view = (View)(Activator.CreateInstance(viewType) ?? throw new Exception($"Could not create instance of Type '{viewType}' ('Activator.CreateInstance' returned null)"));
var prototype = (View)(Activator.CreateInstance(viewType) ?? throw new Exception($"Could not create instance of Type '{viewType}' ('Activator.CreateInstance' returned null)"));

// Unlike Window and Dialog the default constructor on
// View will be a size 0 view. Make it big so it can be
// edited
if(viewType == typeof(View))
{
view.Width = Dim.Fill();
view.Height = Dim.Fill();
prototype.Width = Dim.Fill();
prototype.Height = Dim.Fill();
}

var design = new Design(sourceFile, Design.RootDesignName, view);
// use the prototype to create a designer cs file
var design = new Design(sourceFile, Design.RootDesignName, prototype);
design.CreateSubControlDesigns();

GenerateDesignerCs(design, sourceFile,viewType);

// Reload the designer cs file to create a new instance (which is returned).
// NOTE: prototype is not the same instance that is returned;

var decompiler = new CodeToView(sourceFile);
return decompiler.CreateInstance();
Expand Down
Loading