Git Product home page Git Product logo

imgui's Introduction

Hello ImGui,

Hello ImGui is an immediate mode GUI library inspired by IMGUI of Unity3D and dear imgui.

It's still a work in progress.

code sample

Now it runs on Win10, Linux(Ubuntu 16.04) and Android. See platforms. Mac and iPhone are not supported because I don't have them.

Get Started

Windows and Linux

  1. Clone ImGui
git clone https://github.com/zwcloud/ImGui.git
  1. Create a .NET7 console project and reference ImGui.
mkdir MyImGuiApp

Create MyImGuiApp.csproj with following content:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include=".\ImGui\src\ImGui\ImGui.csproj" />
  </ItemGroup>
</Project>
  1. Add Program.cs to your project,

    using ImGui;
    var demo = new Demo();
    Application.Run(new Form(new Rect(320, 180, 1280, 720)), () =>
    {
        demo.OnGUI();
        ImGui.GUILayout.Label("Hello, ImGui!");
    });
  2. Build your project

  3. Run

    • run with Visual Studio 2022: Press F5
    • run on Windows/Linux:
      cd MyImGuiApp
      dotnet MyApp.dll
      
  4. Exit

    Press Esc or click the close button of the window.

Android

  1. Copy Android Templates project. Referenced shared project Demo can be removed if not needed.
  2. Add your GUI code in MainForm.OnGUI.
  3. Build and deploy it to your Android device.

Documentation

For now, please refer to the shared project Demo for how to use Hello ImGui.

Dependency

  • Xamarin.Android: Xamarin.Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#. It mainly provides C# runtime for ImGui.

Credits

ImGui doesn't depend on following projects, some code used by ImGui are taken from them.

  • BigGustave: Open, read and create PNG images in fully managed C#.
  • Typography: C# Font Reader (TrueType / OpenType / OpenFont) , Glyphs Layout and Rendering
  • OpenTK: low-level C# wrapper for OpenGL
  • CSharpGL: Object Oriented OpenGL in C#

Droid Sans and Terminus TTF fount, see fonts/ReadMe.

License

Hello ImGui is licensed under the AGPL License, see LICENSE for more information.

imgui's People

Contributors

zwcloud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgui's Issues

implement a stateful PathGeometry builder and expose to DrawContext

  • implement usable API that can stroke and fill figures correctly
  • support setting color for one single segment

This is another preparation for text-rendering unit-tests.

Currently, the only way to create a PathGeometry is adding segments one by one, adding figures one by one.

var h = boxRect.Height;
var tick = new PathGeometry();
var figure = new PathFigure();
figure.StartPoint = new Point(0.125f * h + boxRect.X, 0.50f * h + boxRect.Y);
figure.Segments.Add(new LineSegment(new Point(0.333f * h + boxRect.X, 0.75f * h + boxRect.Y), true));
figure.Segments.Add(new LineSegment(new Point(0.875f * h + boxRect.X, 0.25f * h + boxRect.Y), true));
figure.IsFilled = false;
tick.Figures.Add(figure);
dc.DrawGeometry(null, new Pen(tickColor, 2), tick);

ImGui shoud provide stateful APIs as a convenient alternative like the HTML's canvas 2D path APIs.

Single-Line Textbox issues

  • regular TextBox
    image

    • TextBoxes layouted vertically seems to shared a border, that's incorrect.
      fixed at 29d9c55
    • The left border of a TextBox isn't drawn.
      fixed at 29d9c55
      image
  • filtered TextBox
    image

    • filtered textboxes's size is incorrect until any characher has been entered
      fixed at 10aad6f
      image

Refactor StyleRuleSet: state consideration

Class Design

  • Remove state from StyleRuleSet or create a new stateless rule set class as its base class.
  • Use stateless rule sets to describe the style of a Primitive.
  • Make Visual.RuleSet stateless, state should be maintained at the Node level.

(2019-09-08) Update:
The StyleRuleSet is now directly connected to node's State: when a node's State changes, its RuleSet's state will also change.

Colored labels are not colored.

GUILayout.Label(new Color(1.0f, 0.0f, 1.0f, 1.0f), "Pink");
GUILayout.Label(new Color(1.0f, 1.0f, 0.0f, 1.0f), "Yellow");
GUILayout.LabelDisabled("Disabled");

image

Text color is not applied.

Switch to SixLabors/Fonts for font loading.

Typography's glyph APIs are quite chaotic and hard to understand later. I'm at a loss when trying to understand old code dependent on Typography's glyph.

A better alternative is SixLabors/Fonts. The APIs is well-organized and very similar to DirectWrite.

This issue blocks #39.

Use strong name instead of enum GUIStyleName.

For example,

class StyleName
{
    public static readonly StyleName HorizontalCellSpacing;
    int value;
    string name;//for debugging or serialization
}

Then use in code:

GUILayout.PushStyle(StyleName.HorizontalCellSpacing, 5);

Implement PathFigure, PathSegment for storing path data as subsection of a geometry.

Create adjustable primitive.

To update a primitive, especially a PathPrimitive, we need to re-create on and replace the original one. For example, a rectangle PathPrimitive, to change its size,

var original = node.Primitive;
//get top left point of the original rectangle
var x = ....;
var y = ....;
var rectPrimitive = new PathPrimitive();
rectPrimitive.PathRect(x, y, newSize);
node.Primitive = rectPrimitive;

We should be able to do this by introduce a new concrete primitive type RectPathPrimitive:

var primitive = node.Primitive as RectPathPrimitive;
primitive.Size = newSize;//this internally changes the path commands that construct this primitive

Rendering Pipeline TODOs

New Phase in Pipeline

Only update the geometrys when requested by by user input or animation.

Current:

  1. Create geometrys on the fly for controls
  2. Convert all geometrys to mesh, namely the vertex buffer, index buffer and draw commands, while walking through the render tree
  3. Send vertex buffer, index buffer to GPU and draw as what the draw commands tell.

New:

  1. Persist the shapes and text and updates them when requested by user input or animation on the fly. Initially, create the underlying geometry once.
  2. Update underlying geometries(DrawingContent) only when shapes and text changed.
  3. Convert all geometries(DrawingContent) to mesh, namely the vertex buffer, index buffer and draw commands, while walking through the render tree.
  4. Send vertex buffer, index buffer to GPU and draw as what the draw commands tell.

DrawingContent: a concept from WPF, as a field of Visual, it holds all rendering shape data like rectangles, curves, line-sengment paths, geometries and so on. It will later be converted to Geometry or directly to Mesh for rendering in GPU.


UPDATE(2019-10-09): This won't be done since conditional updating conflicts with immediate mode.

[suggestion]是否能支持vulkan后端

我最近也在寻找一个.net原生,支持多后端如vulkan的imgui.考虑替换掉vedrid图形库中imgui模块,想深入了解下此项目的roadmap.

Restore clipping.

  • Clip every layout group: implemented clipping for layout group at 936ead0
  • Clip TextMesh: implemented at d15f2df
  • Fix: ClientArea clipping rect's range is larger than expected or didn't work for buttons and listboxes inside it. implemented at 50d6480

When layouting box-models, border is not considered.

For example,

GUILayout.PushStyle(StylePropertyName.BorderTop, 10.0);
GUILayout.Button("Button1");
GUILayout.Button("Button2");
GUILayout.PopStyle();
GUILayout.Button("Button3");
GUILayout.Button("Button4");

First two buttons top border 10 is not considered when calculate layout:

image

A texture button's UV is not applied.

Full image is displayed on those image buttons with partial UV.

GUILayout.Text("Some textured buttons:");
GUILayout.BeginHorizontal("HGroup~1");
for (int i = 0; i < 8; i++)
{
    GUILayout.PushID(i);
    if (GUILayout.ImageButton("images/trees.jpg", new Size(32, 32), new Point(32.0f * i / 256, 0), new Point(32.0f * (i + 1) / 256, 32.0f / 256)))
        pressed_count += 1;
    GUILayout.PopID();
}
GUILayout.EndHorizontal();

image

Re-implement PushStyleVar/PopStyleVar APIs based on StyleRuleSet.

They are APIs that used to change controls style on the fly. They are once removed because the old style system, which is based on the static object GUIStyle.Basic, is not well considered.

See the history of deleted src/ImGui/GUILayout.Adjust.cs for more details.

Enhance Path API functionality.

Two aspect: path storage and rendering: PathPrimitive implements storage and BuiltinPrimitiveRenderer implements rendering.

  • PathArc: draw an arc accurately
  • PathQuadraticBezier: draw a quadratic bézier curve
  • PathCubicBezier: draw a cubic bézier curve
  • PathConic: draw a conical curve

ref:

Win32OpenGLRenderer is not pixel-perfect.

This is rendered by Win32OpenGLRenderer in 3cf93fc , but it is not pixel-perfect while the rectangles values (x, y, width and height) of the node are all integer.

TODO: add a minimal unit test for this.

Unified GlyphRun rendering.

DrawGlyphRun methods should be unified to a single one.

void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun);

Another overload void DrawGlyphRun(Brush foregroundBrush, GlyphRun glyphRun, Point origin, double maxTextWidth, double maxTextHeight);should be removed, and the text layout and hit-test algorithm should be extracted to a proper place.

Scalable text rendering library in Unity

Hello there! I recently found this repo. I wondered if is possible to implement this on Unity as a library. I am particularly interested in the text rendering system (came here from the Medium "Easy Scalable Text Rendering on the GPU" article).

The layout process should not modify the StyleRuleSet of a Node.

Current layout algorithm modifies a stretched entry to a fixed-sized one when the size of all children overflows:

// change all HorizontallyStretched entries to fixed width

// change all VerticallyStretched entries to fixed height

This should be re-considered. The style (StyleRuleSet) of a node should never be modified by layouting depending on runtime conditions such as a overflow situation.

dynamic layout issue: controls inside a CollapsingHeader are always shown after all existing controls

code to reproduce:

public void ShowTwoCollapsingHeader()
{
    Application.IsRunningInUnitTest = true;
    Application.Init();

    var form = new MainForm();
    bool open1 = false, open2 = false;
    form.OnGUIAction = () =>
    {
        if (GUILayout.CollapsingHeader("Header 1", ref open1))
        {
            GUILayout.Label("Item A");
            GUILayout.Label("Item B");
        }
        if (GUILayout.CollapsingHeader("Header 2", ref open2))
        {
            GUILayout.Label("Item C");
            GUILayout.Label("Item D");
        }
    };

    Application.Run(form);
}

result:
dynamic_layout_collapsingheader_issuee

Bullet issue: bullet text isn't indented and the bullet point is drawn on text.

GUILayout.BulletText("Bullet point 1");
GUILayout.BulletText("Bullet point 2\nOn multiple lines");
GUILayout.PushStyle(StylePropertyName.CellSpacingHorizontal, 0);//remove horizontal cell spacing of following groups.
GUILayout.BeginHorizontal("HGroup~1"); GUILayout.Bullet("_Bullet"); GUILayout.Text("Bullet point 3 (two calls)"); GUILayout.EndHorizontal();
GUILayout.BeginHorizontal("HGroup~2"); GUILayout.Bullet("_Bullet"); GUILayout.Button("Button"); GUILayout.EndHorizontal();

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.