Closed Stay1444 closed 2 years ago
Take a look at the demo code over in the main repo to get an example of how to use it. The misunderstanding here is that BeginMainMenuBar
should not be inside of a Begin
/End
call -- it makes it's own top-level block.
"Main menu" actually refers to the menu at the top of the application window. If you wanted the "testWindow" that you are creating to have a menu bar at the top of it, you would just use BeginMenuBar
+EndMenuBar
instead.
Hope that helps.
I don't understand this either I am doing this and it crashes the application...
public class Program : Game
{
static void Main(string[] args)
{
using (var program = new Program())
{
program.Run(100,100,800,600, "Test");
}
}
public override void OnDraw()
{
if (ImGui.BeginMainMenuBar())
{
if (ImGui.BeginMenu("File"))
{
if (ImGui.MenuItem("New"))
{
}
}
ImGui.EndMenu();
}
ImGui.EndMainMenuBar();
}
}
using System;
using System.Numerics;
using ImGuiNET;
using SharpDX.Text;
using Veldrid;
using Veldrid.Sdl2;
using Veldrid.SPIRV;
using Veldrid.StartupUtilities;
namespace GameSharp
{
public abstract class Game : IDisposable
{
public void Run(int x, int y, uint w, uint h, string title)
{
VeldridStartup.CreateWindowAndGraphicsDevice
(
new WindowCreateInfo(x, y, (int)w, (int)h, Veldrid.WindowState.Normal, title),
out var window,
out var gd
);
ImGuiRenderer imGuiRenderer = new ImGuiRenderer
(
gd,
gd.MainSwapchain.Framebuffer.OutputDescription,
(int)gd.MainSwapchain.Framebuffer.Width,
(int)gd.MainSwapchain.Framebuffer.Height
);
var cl = gd.ResourceFactory.CreateCommandList();
OnLoad();
while (window.Exists)
{
var input = window.PumpEvents();
if (!window.Exists) { break; }
imGuiRenderer.Update(1f / 60f, input); // Compute actual value for deltaSeconds.
// Draw stuff
OnStep();
OnDraw();
cl.Begin();
cl.SetFramebuffer(gd.MainSwapchain.Framebuffer);
cl.ClearColorTarget(0, RgbaFloat.Black);
imGuiRenderer.Render(gd, cl);
cl.End();
gd.SubmitCommands(cl);
gd.SwapBuffers(gd.MainSwapchain);
}
OnQuit();
}
public virtual void OnLoad()
{
}
public virtual void OnStep()
{
}
public virtual void OnDraw()
{
}
public virtual void OnQuit()
{
}
public void Dispose()
{
OnQuit();
}
}
}
I got around crashing in a nim application by making it only run EndMenu
if the BeginMenu
call returns true (basically moving EndMenu under the conditional instead of after).
Apparently the behavior is different from ImGui.Begin
/ImGui.End
.
Im new to Dear ImGUI so i searched how to make a Menu bar (File, save etc) I found and example in C++, and when using it in C# it doenst work.
What am i doing wrong?