Skip to content

Commit

Permalink
Container widget
Browse files Browse the repository at this point in the history
  • Loading branch information
xezno committed Nov 2, 2022
1 parent 4b8bb91 commit 166d0e3
Showing 5 changed files with 131 additions and 6 deletions.
17 changes: 11 additions & 6 deletions code/Page.cs
Original file line number Diff line number Diff line change
@@ -65,15 +65,20 @@ private void AddManifestWidgets( LocalProject project )
var desc = Layout.Add( new Label( $"{Manifest.Description}" ) );
desc.WordWrap = true;

Layout.AddSpacingCell( 8f );
Layout.AddStretchCell();

Layout.Add( new Heading( "Update Available" ) );
LatestReleaseName = Layout.Add( new Subheading( $"Loading..." ) );
LatestReleaseBody = Layout.Add( new Label( $"Loading..." ) );
var group = new Container( this );
group.SetLayout( LayoutMode.TopToBottom );
group.Layout.Margin = 10;
Layout.Add( group );

Layout.AddStretchCell();
group.Layout.Add( new Heading( "Update Available" ) );
LatestReleaseName = group.Layout.Add( new Subheading( $"Loading..." ) );
LatestReleaseBody = group.Layout.Add( new Label( $"Loading..." ) );

group.Layout.AddSpacingCell( 8f );

Layout.Add( new Button( "Download Update", "download" ) );
group.Layout.Add( new Button( "Download Update", "download" ) );
}

private void ToggleAutoUpdates( Option option )
46 changes: 46 additions & 0 deletions code/Utils/Template.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Tools;

/// <summary>
/// Shitty simple template format parser
/// </summary>
public class Template
{
private string TemplateContents { get; set; }

public Template( string templatePath )
{
var dirName = Path.GetDirectoryName( templatePath );
var fileName = Path.GetFileName( templatePath );

templatePath = Path.Join( FindBasePath(), dirName, fileName );
TemplateContents = File.ReadAllText( templatePath );
}

private string FindBasePath()
{
var addon = Utility.Projects.GetAll().FirstOrDefault( x => x.Config.Ident == "vtextool" );
return addon.GetCodePath();
}

public string Parse( Dictionary<string, string> values )
{
//
// example template:
// "Blah<#= value #>blah"
//
// called with Parse( new[]{ ( "value", "Hello!" ) } ):
// "BlahHello!blah"
//

var str = TemplateContents;
foreach ( var pair in values )
{
str = str.Replace( $"<#= {pair.Key} #>", pair.Value );
}

return str;
}
}
26 changes: 26 additions & 0 deletions code/Utils/WidgetExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.IO;
using System.Linq;
using Tools;

public static class WidgetExtensions
{
public static void SetStylesheet( this Widget widget, string path )
{
var basePath = Utility.Projects.GetAll().FirstOrDefault( x => x.Config.Ident == "tools_manager" ).GetCodePath();
var combinedPath = basePath + path;

void ReadAndSet()
{
var stylesheetText = File.ReadAllText( combinedPath );
widget.SetStyles( stylesheetText );
}

ReadAndSet();

/* var watcher = new System.IO.FileSystemWatcher();
watcher.Path = Path.GetDirectoryName( combinedPath );
watcher.Filter = Path.GetFileName( combinedPath );
watcher.Changed += (_, _) => ReadAndSet();
watcher.EnableRaisingEvents = true; */
}
}
9 changes: 9 additions & 0 deletions code/Widgets/Container.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Tools;

public class Container : Widget
{
public Container( Widget parent ) : base( parent )
{
this.SetStylesheet( "/styles/container.css" );
}
}
39 changes: 39 additions & 0 deletions code/styles/container.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Container {
background-color: #38393c;
border: 1px solid #ffffff22;
padding: 25px;
border-radius: 4px;
}

Container LineEdit, Container TextEdit {
background-color: #201f21;
border: 0px;
min-height: 22px;
border-radius: 3px;
padding: 0px 5px;
border: 1px solid #201f21;
color: #bbb;
}

Container LineEdit:focus, Container TextEdit:focus {
border: 1px solid #3472E6;
color: #ddd;
}

Container ListView {
background-color: transparent;
border: 0px;
}

Container Button {
min-width: 70px;
}

Container Separator {
background-color: #222;
}

Container ComboBox {
background-color: #201f21;
}

0 comments on commit 166d0e3

Please sign in to comment.