Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImgGui.Button() function is not rendering in my program (.NET 7, ImGui.net ver 1.90.0.1, Veldrid.ImGui ver 5.72.0, ClickableTransparentOverlay ver 9.1.0, SixLabors.ImageSharp ver 3.0.2, Vortice.Mathematics ver 1.7.2) #450

Open
DucksterBoo123 opened this issue Nov 21, 2023 · 2 comments

Comments

@DucksterBoo123
Copy link

DucksterBoo123 commented Nov 21, 2023

Depending on where I place it, a debug panel is instanced with nothing inside it, or nothing happens and the code executes as if the button isn't there.

if (ImGui.Button("Button"))
{
    slide = 100; //this is assigning a number to an integer variable that is shared by a slider.
}
Screenshot 2023-11-21 at 13 03 51

The button should be below the check box and above the "You chose: person1" text output. This version of the code does not instance the debug panel and just runs was if the function was never there.

@zaafar
Copy link
Collaborator

zaafar commented Nov 21, 2023

sorry, I can not reproduce the issue locally.
Looks like something wrong on your side.

@blackholeearth
Copy link

blackholeearth commented Nov 26, 2024

to run on windows..
here is get started Project.. --- FAQable -README. able

  1. make net8 console app . install this versions.
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="ClickableTransparentOverlay" Version="9.1.0" />
    <PackageReference Include="ImGui.NET" Version="1.91.0.1" />
    <PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
	<PackageReference Include="Veldrid.ImGui" Version="5.72.0" />
	 <PackageReference Include="Vortice.Mathematics" Version="1.9.3" />
  </ItemGroup>
</Project>
  1. here the minimal code,

Note: You can Remove RunOnce_() function its just windows LookAndFell style.

program.cs - paste this.


using System.Runtime.InteropServices;
using console_Imgui;
class Program
{

    [DllImport("kernel32.dll")]
    static extern IntPtr GetConsoleWindow();
    
    static int SW_Hide = 0;
    static int SW_Show = 5;
    static int SW_ShowMinimize = 2;
    static int SW_Minimize = 6;

    [DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow);


     static void Main(string[] args)
    {
       //hide/minimize consoleWindow on Windows OS
        IntPtr handle = GetConsoleWindow();
        ShowWindow(handle, SW_Minimize );

        Console.WriteLine("Welcome To **ImGuiNET  ** ");
        var v1 = new myView1();
        v1.Start().Wait();
    }

}

  1. create new cs file give that name below.

myview1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ImGuiNET;
using ClickableTransparentOverlay;
using System.Numerics;
using Veldrid.MetalBindings;
using Veldrid;
using SixLabors.ImageSharp;
using System.Runtime.CompilerServices;

namespace console_Imgui
{

    public static class Ext 
    {
        public static Vector4 ToVector4(this Color color) => (Vector4)color;

    }

    internal class myView1 : Overlay
    {
        bool Exit = false;

        bool ranOnce = false;
        string FontPath = @"C:\Windows\Fonts\arial.ttf";
        Color Color_gray232 = Color.FromRgb(232, 232, 232);
        Color Color_activeTitleBar_gray243 = Color.FromRgb(243, 243, 243);
        Color Color_Button_gray243 = Color.FromRgb(243, 243, 243);
        Color Color_Button_Hover_gray222 = Color.FromRgb(222, 222, 222);
        Color Color_Button_Active_gray199 = Color.FromRgb(199, 199, 199);

        Color Color_red = Color.FromRgb(222 , 0, 0 );
        Color Color_gray222 = Color.FromRgb(222 , 222, 222 );
        Color Color_gray33 = Color.FromRgb(33 , 33, 33 );
        Color Color_gray122 = Color.FromRgb(122 , 122, 122 );
        Color Color_gray99 = Color.FromRgb(99 , 99, 99);
        Color Color_gray144 = Color.FromRgb(144 , 144, 144);
        void RunOnce__Winforms_ColorTheme() 
        {
            if (ranOnce)
                return;

            //win11 style - roundCorners
            var stl1 = ImGui.GetStyle();
            stl1.WindowRounding = 8f;
            stl1.FrameRounding = 6f;
            stl1.Alpha = 1.5f; // 1.0f still makes it transparent.
            //stl1.Colors[(int)ImGuiCol.Border] = Color_red.ToVector4();
            //stl1.Colors[(int)ImGuiCol.WindowBg] = Color_gray232.ToVector4();
            stl1.Colors[(int)ImGuiCol.Text] =  Color_gray33.ToVector4();

          

            //window
            stl1.Colors[(int)ImGuiCol.Border] = Color_gray122.ToVector4();
            stl1.Colors[(int)ImGuiCol.WindowBg] = Color_gray232.ToVector4();
            //titleBar
            stl1.Colors[(int)ImGuiCol.TitleBgActive] = Color_activeTitleBar_gray243.ToVector4();
            stl1.Colors[(int)ImGuiCol.TitleBg] = Color_gray122.ToVector4();
            stl1.Colors[(int)ImGuiCol.TitleBgCollapsed] = Color_gray122.ToVector4();

            //button
            stl1.Colors[(int)ImGuiCol.Button] = Color_Button_gray243.ToVector4();
            stl1.Colors[(int)ImGuiCol.ButtonHovered] = Color_Button_Hover_gray222.ToVector4();
            stl1.Colors[(int)ImGuiCol.ButtonActive] = Color_Button_Active_gray199.ToVector4(); //clicked



            //set Size and Pos - of Next Window
            var wsize = new Vector2((int)(Size.Width * 0.4), (int)(Size.Height * 0.4));
            ImGui.SetNextWindowSize(wsize);
            ImGui.SetNextWindowPos(new Vector2(Size.Width - wsize.X, (int)(Size.Height*0.5 -wsize.Y*0.5) ));
            ImGui.SetNextWindowBgAlpha(1f);


            ranOnce = true;
        }

        string username="" ; 

        protected override void Render()
        {
            Thread.Sleep(25);//40fps max
            ReplaceFont(FontPath, 22, FontGlyphRangeType.English);

            //Console.WriteLine($"ImGui.WindpiScale:{dpiScale}");
            //ImGui.SetWindowFontScale(1.7f); //opens new window??
            RunOnce__Winforms_ColorTheme();
            ImGui.Begin("imguiNET", ImGuiWindowFlags.NoCollapse);
            { 

                ImGui.SetCursorPosX((int)ImGui.GetWindowSize().X - 100);
                var btclicked = ImGui.Button("Exit", new Vector2(100, 30));
                if (btclicked)
                {
                    Environment.Exit(0);
                }

                RepeatAction(2, () => { ImGui.NewLine(); });
                ImGui.Text("hello Imgui. ");
                
                ImGui.NewLine();
                ImGui.Text("1) i want to put border around textEdit.  How can i do it?");
                ImGui.Text("2) i can't type into TextEdit (blue thing).. no chars show up. how to fix it??");
                
                RepeatAction(2, () => { ImGui.NewLine(); });
                ImGui.InputText("##username:" , ref username,(uint)30);
                ImGui.Text($"buf:{username}");

            }
            ImGui.End();

        }

        public static void RepeatAction(int repeatCount, Action action)
        {
            for (int i = 0; i < repeatCount; i++)
                action();
        }




    }


}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants