Skip to content

Commit

Permalink
Demo tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed May 4, 2024
1 parent d9503e0 commit 6fd8549
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions addons/imgui-godot/ImGuiGodot/ImGuiController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if GODOT_PC
#nullable enable
using Godot;
using ImGuiGodot.Internal;
using ImGuiNET;
Expand Down
1 change: 1 addition & 0 deletions addons/imgui-godot/ImGuiGodot/ImGuiLayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Godot;
using ImGuiGodot.Internal;
#if GODOT_PC
#nullable enable

namespace ImGuiGodot;

Expand Down
15 changes: 12 additions & 3 deletions data/demo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,42 @@ expand_mode = 1

[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 0
offset_right = 241.0
offset_bottom = 168.0
offset_right = 209.0
offset_bottom = 173.0

[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
custom_minimum_size = Vector2(200, 0)
custom_minimum_size = Vector2(180, 0)
layout_mode = 2

[node name="Button1" type="Button" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
focus_mode = 0
theme_override_fonts/font = ExtResource("3_fjiyg")
theme_override_font_sizes/font_size = 24
text = "Widgets"

[node name="Button2" type="Button" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
focus_mode = 0
theme_override_fonts/font = ExtResource("3_fjiyg")
theme_override_font_sizes/font_size = 24
text = "New Window"

[node name="Button3" type="Button" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
focus_mode = 0
theme_override_fonts/font = ExtResource("3_fjiyg")
theme_override_font_sizes/font_size = 24
text = "3D Scene"

[node name="CheckBox" type="CheckBox" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
focus_mode = 0
text = "ImGui Viewports"

[connection signal="pressed" from="PanelContainer/CenterContainer/VBoxContainer/ButtonCIE" to="MyNode" method="OnContentScaleCIE"]
[connection signal="pressed" from="PanelContainer/CenterContainer/VBoxContainer/ButtonD" to="MyNode" method="OnContentScaleDisabled"]
14 changes: 14 additions & 0 deletions src/MyNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ namespace DemoProject;
public partial class MyNode : Node
{
private Window _window = null!;
private CheckBox _checkBox = null!;

public override void _Ready()
{
_window = GetWindow();
GetNode<Button>("%Button1").Pressed += OnButton1Pressed;
GetNode<Button>("%Button2").Pressed += OnButton2Pressed;
GetNode<Button>("%Button3").Pressed += OnButton3Pressed;
_checkBox = GetNode<CheckBox>("%CheckBox");
_checkBox.ButtonPressed = ImGui.GetIO().ConfigFlags
.HasFlag(ImGuiConfigFlags.ViewportsEnable);
_checkBox.Pressed += OnCheckBoxPressed;

if (DisplayServer.WindowGetVsyncMode() == DisplayServer.VSyncMode.Disabled)
{
Expand Down Expand Up @@ -52,6 +57,15 @@ private void OnButton3Pressed()
GetTree().ChangeSceneToFile("res://data/gui_in_3d.tscn");
}

private void OnCheckBoxPressed()
{
var io = ImGui.GetIO();
if (_checkBox.ButtonPressed)
io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;
else
io.ConfigFlags &= ~ImGuiConfigFlags.ViewportsEnable;
}

private void OnContentScaleCIE()
{
_window.ContentScaleMode = Window.ContentScaleModeEnum.CanvasItems;
Expand Down

0 comments on commit 6fd8549

Please sign in to comment.