ContentEmbed control to resolve #6

This commit is contained in:
JacobTech 2023-01-02 12:48:02 -05:00
parent b82677bb64
commit d617e84f4c
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
using System.Reflection;
using GraphicsManager;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using File = Luski.net.JsonTypes.File;
namespace Luski.GUI.MainScreen.UI;
public class ContentEmbed : UserControl
{
readonly File file;
long channel;
private Label fileNameLabel, fileSizeLabel;
private Rectangle downloadButton;
public ContentEmbed(File file, long channel)
{
this.channel = channel;
this.file = file;
string fst = "";
ulong size = file.Size;
if (size < 1000)
{
fst = size + " bytes";
} else if (size < 1000000)
{
fst= Math.Round((double)size / (double)1000, 2) + " KB";
} else if (size < 1000000000)
{
fst = Math.Round((double)size / (double)1000000, 2) + " MB";
} else if (size < 1000000000000)
{
fst = Math.Round((double)size / (double)1000000000, 2) + " GB";
}
Controls.Add(fileSizeLabel = new Label() {Text = fst, Location = new(64, 39)});
Controls.Add(fileNameLabel = new Label() {Text = file.Name, Location = new(64, 6)});
Controls.Add(new Rectangle(new Texture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Download.png"))) { Location = new(8, 6), Size = new(50, 50)});
int temp = fileNameLabel.Size.X + fileNameLabel.Location.X;
int temp2 = fileSizeLabel.Size.X + fileSizeLabel.Location.X; ;
if (temp >= temp2) Size = new(temp + 4, Size.Y);
else Size = new(temp2 + 4, Size.Y);
}
}