How do I use ImGui.NET to make a slider with a specified position and size? Everything seems to be rendered in the order they are called going down the window or to the right of the last component with the same line method. I tried making a window with no background or title bar but the slider seems to use a width about 0.65x the width of the window and the only way with my trial and error checking that I found to control the height is by using ImGuiStylePtr.FramePadding which seems to add on to the font size. Anything that works in the original Dear ImGui is probably applicable to ImGui.NET if anyone knows a solution there.
Asked
Active
Viewed 715 times
1 Answers
0
Figured it out
void Init()
{
ImGui.GetStyle().WindowPadding = Vector2.Zero;
}
...
public void DrawSlider(int x, int y, int width, int height, float min, float max, ref float value, string label = "")
{
ImGui.SetNextWindowPos(new Vector2(x - 2, y - 2));
ImGui.Begin("slider1", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoBackground);
ImGui.SetNextItemWidth(width + 2);
var style = ImGui.GetStyle();
var framePadding = style.FramePadding;
style.FramePadding = new Vector2(0, (height - ImGui.GetFontSize() + 1) * 0.5f);
ImGui.SliderFloat(label, ref value, min, max, "");
style.FramePadding = framePadding;
ImGui.End();
}

Jacbo
- 13
- 6