打开文件可视化窗口+CodeStudio代码高亮

This commit is contained in:
2026-03-02 21:42:44 +08:00
parent 5c952e7861
commit 29a68b4ca9
8 changed files with 550 additions and 47 deletions

View File

@@ -0,0 +1,50 @@
using CMLeonOS.Gui.UILib;
using Cosmos.System.Graphics;
using System.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CMLeonOS.Gui.Apps.CodeStudio
{
internal class CodeEditor : TextBox
{
private bool enableSyntaxHighlighting = false;
private string fileExtension = "";
public CodeEditor(Window parent, int x, int y, int width, int height) : base(parent, x, y, width, height)
{
}
internal void SetSyntaxHighlighting(bool enable, string extension = "")
{
enableSyntaxHighlighting = enable;
fileExtension = extension.ToLower();
MarkAllLines();
Render();
}
internal override void RenderLine(int lineIndex, string lineText, int lineY, int xOffset)
{
if (enableSyntaxHighlighting && fileExtension == ".lua")
{
var tokens = LuaSyntaxHighlighter.HighlightLine(lineText);
int currentXOffset = xOffset;
foreach (var token in tokens)
{
if (currentXOffset + token.Text.Length * 8 > 0 && currentXOffset < Width)
{
DrawString(token.Text, token.Color, currentXOffset, lineY);
}
currentXOffset += token.Text.Length * 8;
}
}
else
{
base.RenderLine(lineIndex, lineText, lineY, xOffset);
}
}
}
}