Skip to content

Commit e02dce6

Browse files
committed
Add FontAwesome and color extensions
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 82d998e commit e02dce6

6 files changed

Lines changed: 1744 additions & 13 deletions

File tree

src/Raylib.NET.ImGui.Example/Program.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using RaylibNET;
22
using static RaylibNET.Raylib;
33
using Hexa.NET.ImGui;
4+
using System.Numerics;
45

6+
7+
SetConfigFlags(
8+
(int)(ConfigFlags.FLAG_WINDOW_HIGHDPI)
9+
);
510
InitWindow(800, 600, "Raylib.NET.ImGui - Example");
611
SetTargetFPS(60);
712

8-
RaylibNET.RlImGui.Setup();
13+
RlImGui.Setup();
914

1015
int counter = 0;
1116
bool showDemo = true;
@@ -18,14 +23,47 @@
1823
// Start ImGui frame
1924
RlImGui.Begin();
2025

21-
if (ImGui.Button("Increment Counter"))
26+
// Demonstrate FontAwesome icons
27+
// Test icon-only display (matching C++ rlImGui example)
28+
ImGui.TextUnformatted(FontAwesome.Jedi);
29+
ImGui.SameLine();
30+
ImGui.Text($"{FontAwesome.Rocket} Welcome to Raylib.NET.ImGui!");
31+
ImGui.Separator();
32+
33+
// Button with icon
34+
if (ImGui.Button($"{FontAwesome.Plus} Increment Counter"))
2235
{
2336
counter++;
2437
}
2538
ImGui.SameLine();
26-
ImGui.Text($"Counter: {counter}");
39+
ImGui.Text($"{FontAwesome.Hashtag} Counter: {counter}");
40+
41+
ImGui.Spacing();
42+
43+
// More icon examples
44+
ImGui.Text($"{FontAwesome.House} Home");
45+
ImGui.SameLine();
46+
ImGui.Text($"{FontAwesome.Gear} Settings");
47+
ImGui.SameLine();
48+
ImGui.Text($"{FontAwesome.Heart} Favorite");
49+
ImGui.SameLine();
50+
ImGui.Text($"{FontAwesome.Star} Rating");
51+
52+
ImGui.Spacing();
53+
54+
// Demonstrate color extensions
55+
var raylibColor = Color.RAYWHITE;
56+
var imguiColor = raylibColor.ToImGui();
57+
ImGui.TextColored(imguiColor, "This text uses Raylib.RAYWHITE converted to ImGui color!");
58+
59+
var customImGuiColor = new Vector4(0.2f, 0.8f, 0.4f, 1.0f);
60+
var convertedBack = customImGuiColor.ToRaylib();
61+
ImGui.Text($"Custom color RGB: {convertedBack.R}, {convertedBack.G}, {convertedBack.B}");
62+
63+
ImGui.Spacing();
64+
ImGui.Separator();
2765

28-
ImGui.Checkbox("Show ImGui Demo Window", ref showDemo);
66+
ImGui.Checkbox($"{FontAwesome.WindowMaximize} Show ImGui Demo Window", ref showDemo);
2967
if (showDemo)
3068
{
3169
ImGui.ShowDemoWindow(ref showDemo);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Numerics;
2+
namespace RaylibNET;
3+
4+
/// <summary>
5+
/// Extension methods for converting between Raylib Color and ImGui Vector4 color formats.
6+
/// </summary>
7+
public static class ColorExtensions
8+
{
9+
/// <summary>
10+
/// Convert a Raylib Color to ImGui Vector4 format (normalized 0.0-1.0 floats).
11+
/// </summary>
12+
/// <param name="color">The Raylib color to convert</param>
13+
/// <returns>A Vector4 with RGBA components normalized to 0.0-1.0 range</returns>
14+
public static Vector4 ToImGui(this Color color)
15+
{
16+
return new Vector4(
17+
color.R / 255f,
18+
color.G / 255f,
19+
color.B / 255f,
20+
color.A / 255f
21+
);
22+
}
23+
24+
/// <summary>
25+
/// Convert an ImGui Vector4 color to Raylib Color format (0-255 byte values).
26+
/// </summary>
27+
/// <param name="color">The ImGui color to convert</param>
28+
/// <returns>A Raylib Color with RGBA components in 0-255 range</returns>
29+
public static Color ToRaylib(this Vector4 color)
30+
{
31+
return new Color(
32+
(byte)(color.X * 255f),
33+
(byte)(color.Y * 255f),
34+
(byte)(color.Z * 255f),
35+
(byte)(color.W * 255f)
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)