コンテンツにスキップ

ConsoleLayer

ConsoleLayer は、コマンドラインウィンドウの表示形式に似た、シンプルなテキスト表示機能です。画面上の左上にテキストを表示します。ウィンドウサイズやフォントに応じて自動的に表示行数を調整します。

デバッグ用のログ表示や、簡単なUIの実装などに利用できます

基本的な使い方

ConsoleLayer は PrometeApp のプラグインとして登録し、シーンのコンストラクタで依存性注入を利用して受け取ります。

// プラグイン登録例(Program.cs)
var app = PrometeApp.Create()
.Use<ConsoleLayer>()
.BuildWithOpenGLDesktop();
return app.Run<MainScene>();
// シーンでの利用例
public class MainScene(ConsoleLayer console) : Scene
{
public override void OnStart()
{
console.Print("Hello, world!");
console.Print("Press [ESC] to exit");
}
}

主なメソッド・プロパティ

  • Print(object? obj)
    テキストを1行出力します。改行を含む文字列も複数行として出力されます。
  • Clear()
    画面のテキストをすべて消去します。
  • Cursor
    現在のカーソル位置(VectorInt型)。Print実行時に自動で次の行に移動します。
  • Font
    表示に使うフォントを取得・設定できます。
  • TextColor
    文字色を取得・設定できます。

サンプル:ファイルリストの表示

public override void OnUpdate()
{
console.Clear();
console.Print("Promete Demo\n");
console.Print($"現在のディレクトリ: /{CurrentFolder.GetFullPath()}\n");
for (var i = 0; i < CurrentFolder.Files.Count; i++)
{
var item = CurrentFolder.Files[i];
var label = item is SceneFile file ? $"{file.Name} - {file.Description}" : item.Name;
console.Print($"{(i == CurrentIndex ? ">" : " ")} {label}");
}
console.Print($"{(CurrentIndex == CurrentFolder.Files.Count ? ">" : " ")} もどる");
}

ノート

  • Print で出力できる行数はウィンドウサイズとフォントサイズにより自動で決まります。
  • 画面サイズ変更時は自動で再計算されます。
  • テキストはバッファとして保持され、最新の行が常に表示されます。