Skip to content

Commit e3b434e

Browse files
authored
Update transform editor UX/UI
add increment buttons to transform editors
2 parents 2158197 + c794f6b commit e3b434e

File tree

7 files changed

+314
-85
lines changed

7 files changed

+314
-85
lines changed

Brio/UI/Controls/Core/UIConstants.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
namespace Brio.UI.Controls.Core;
2-
1+

2+
namespace Brio.UI.Controls.Core;
33
internal static class UIConstants
44
{
55
public const uint ToggleButtonInactive = 0xFFFFFFFF;
66
public const uint ToggleButtonActive = 0xFF0050FF;
77
public const uint Transparent = 0x00000000;
88

99
public const uint SlightGrey = 0xFF999999;
10+
11+
public const uint GizmoBlue = 0x88FF3333;
12+
public const uint GizmoGreen = 0x8833FF33;
13+
public const uint GizmoRed = 0x883333FF;
1014
}

Brio/UI/Controls/Editors/PosingTransformEditor.cs

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ internal class PosingTransformEditor
1414
private Transform? _trackingTransform;
1515
private Vector3? _trackingEuler;
1616

17-
public void Draw(string id, PosingCapability posingCapability, float? width = null)
17+
private bool _compactMode = false;
18+
19+
public void Draw(string id, PosingCapability posingCapability, bool compactMode = false)
1820
{
1921
var selected = posingCapability.Selected;
2022

23+
_compactMode = compactMode;
24+
25+
if(_compactMode)
26+
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 3));
27+
else
28+
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(4, 5));
29+
2130
using(ImRaii.PushId(id))
2231
{
2332
selected.Switch(
@@ -26,24 +35,24 @@ public void Draw(string id, PosingCapability posingCapability, float? width = nu
2635
var realBone = posingCapability.SkeletonPosing.GetBone(bone);
2736
if(realBone != null && realBone.Skeleton.IsValid)
2837
{
29-
DrawBoneTransformEditor(posingCapability, bone, width);
38+
DrawBoneTransformEditor(posingCapability, bone);
3039
}
3140
else
3241
{
33-
DrawModelTransformEditor(posingCapability, width);
42+
DrawModelTransformEditor(posingCapability);
3443
}
3544
},
36-
_ => DrawModelTransformEditor(posingCapability, width),
37-
_ => DrawModelTransformEditor(posingCapability, width)
45+
_ => DrawModelTransformEditor(posingCapability),
46+
_ => DrawModelTransformEditor(posingCapability)
3847
);
3948
}
49+
50+
ImGui.PopStyleVar();
51+
4052
}
4153

42-
private void DrawBoneTransformEditor(PosingCapability posingCapability, BonePoseInfoId boneId, float? width)
54+
private void DrawBoneTransformEditor(PosingCapability posingCapability, BonePoseInfoId boneId)
4355
{
44-
if(width.HasValue)
45-
width -= ImGui.CalcTextSize("XXXX").X;
46-
4756
var bone = posingCapability.SkeletonPosing.GetBone(boneId);
4857
var bonePose = bone != null ? posingCapability.SkeletonPosing.GetBonePose(boneId) : null;
4958

@@ -57,63 +66,30 @@ private void DrawBoneTransformEditor(PosingCapability posingCapability, BonePose
5766
bool didChange = false;
5867
bool anyActive = false;
5968

60-
61-
if(width.HasValue)
62-
ImGui.PushItemWidth(width.Value);
63-
6469
var text = "No Bone Selected";
6570
if(bone != null)
6671
text = bone.FriendlyDescriptor;
67-
ImGui.Text(text);
6872

69-
ImGui.SameLine();
70-
if(ImBrio.FontIconButtonRight("ik", FontAwesomeIcon.Adjust, 1.2f, "Inverse Kinematics", bone?.EligibleForIK == true))
71-
ImGui.OpenPopup("transform_ik_popup");
73+
ImGui.Text(text);
7274

73-
didChange |= ImGui.DragFloat3("###position", ref realTransform.Position, 0.001f);
75+
didChange |= ImBrio.DragFloat3($"{FontAwesomeIcon.ArrowsUpDownLeftRight.ToIconString()}", ref realTransform.Position, 0.1f, "Position");
7476
anyActive |= ImGui.IsItemActive();
75-
if(ImGui.IsItemHovered())
76-
ImGui.SetTooltip("Position");
77-
ImGui.SameLine();
78-
bool propBool = propagate.HasFlag(TransformComponents.Position);
79-
if(ImGui.Checkbox("###propagate_position", ref propBool))
80-
{
81-
didChange |= true;
82-
propagate = propBool ? propagate | TransformComponents.Position : propagate & ~TransformComponents.Position;
83-
}
84-
if(ImGui.IsItemHovered())
85-
ImGui.SetTooltip("Propagate");
8677

87-
didChange |= ImGui.DragFloat3("###rotation", ref realEuler, 0.1f);
78+
didChange |= ImBrio.DragFloat3($"{FontAwesomeIcon.ArrowsSpin.ToIconString()}", ref realEuler, 5.0f, "Rotation");
8879
anyActive |= ImGui.IsItemActive();
89-
if(ImGui.IsItemHovered())
90-
ImGui.SetTooltip("Rotation");
91-
ImGui.SameLine();
92-
propBool = propagate.HasFlag(TransformComponents.Rotation);
93-
if(ImGui.Checkbox("###propagate_rotation", ref propBool))
94-
{
95-
didChange |= true;
96-
propagate = propBool ? propagate | TransformComponents.Rotation : propagate & ~TransformComponents.Rotation;
97-
}
98-
if(ImGui.IsItemHovered())
99-
ImGui.SetTooltip("Propagate");
10080

101-
didChange |= ImGui.DragFloat3("###scale", ref realTransform.Scale, 0.001f);
81+
didChange |= ImBrio.DragFloat3($"{FontAwesomeIcon.ExpandAlt.ToIconString()}", ref realTransform.Scale, 0.1f, "Scale");
10282
anyActive |= ImGui.IsItemActive();
103-
if(ImGui.IsItemHovered())
104-
ImGui.SetTooltip("Scale");
83+
84+
ImGui.Spacing();
85+
86+
if(ImBrio.FontIconButton("ik", FontAwesomeIcon.Adjust, "Inverse Kinematics", bone?.EligibleForIK == true))
87+
ImGui.OpenPopup("transform_ik_popup");
88+
10589
ImGui.SameLine();
106-
propBool = propagate.HasFlag(TransformComponents.Scale);
107-
if(ImGui.Checkbox("###propagate_scale", ref propBool))
108-
{
109-
didChange |= true;
110-
propagate = propBool ? propagate | TransformComponents.Scale : propagate & ~TransformComponents.Scale;
111-
}
112-
if(ImGui.IsItemHovered())
113-
ImGui.SetTooltip("Propagate");
11490

115-
if(width.HasValue)
116-
ImGui.PopItemWidth();
91+
if(ImBrio.FontIconButton("propagate", FontAwesomeIcon.Compress, "Propagate", bone?.EligibleForIK == true))
92+
ImGui.OpenPopup("transform_propagate_popup");
11793

11894
using(var popup = ImRaii.Popup("transform_ik_popup"))
11995
{
@@ -123,6 +99,14 @@ private void DrawBoneTransformEditor(PosingCapability posingCapability, BonePose
12399
}
124100
}
125101

102+
using(var popup = ImRaii.Popup("transform_propagate_popup"))
103+
{
104+
if(popup.Success && bonePose != null)
105+
{
106+
didChange |= DrawPropagateCheckboxes(propagate);
107+
}
108+
}
109+
126110
realTransform.Rotation = realEuler.ToQuaternion();
127111
var toApply = before + realTransform.CalculateDiff(beforeMods);
128112

@@ -149,8 +133,44 @@ private void DrawBoneTransformEditor(PosingCapability posingCapability, BonePose
149133
}
150134
}
151135

136+
private bool DrawPropagateCheckboxes(TransformComponents propagate)
137+
{
138+
var didChange = false;
139+
140+
bool propBool = propagate.HasFlag(TransformComponents.Position);
141+
if(ImGui.Checkbox("P###propagate_position", ref propBool))
142+
{
143+
didChange |= true;
144+
propagate = propBool ? propagate | TransformComponents.Position : propagate & ~TransformComponents.Position;
145+
}
146+
if(ImGui.IsItemHovered())
147+
ImGui.SetTooltip("Propagate Positions");
148+
149+
ImGui.SameLine();
150+
propBool = propagate.HasFlag(TransformComponents.Rotation);
151+
if(ImGui.Checkbox("R###propagate_rotation", ref propBool))
152+
{
153+
didChange |= true;
154+
propagate = propBool ? propagate | TransformComponents.Rotation : propagate & ~TransformComponents.Rotation;
155+
}
156+
if(ImGui.IsItemHovered())
157+
ImGui.SetTooltip("Propagate Rotations");
158+
159+
ImGui.SameLine();
160+
161+
propBool = propagate.HasFlag(TransformComponents.Scale);
162+
if(ImGui.Checkbox("S###propagate_scale", ref propBool))
163+
{
164+
didChange |= true;
165+
propagate = propBool ? propagate | TransformComponents.Scale : propagate & ~TransformComponents.Scale;
166+
}
167+
if(ImGui.IsItemHovered())
168+
ImGui.SetTooltip("Propagate Scales");
169+
170+
return didChange;
171+
}
152172

153-
private void DrawModelTransformEditor(PosingCapability posingCapability, float? width)
173+
private void DrawModelTransformEditor(PosingCapability posingCapability)
154174
{
155175
var before = posingCapability.ModelPosing.Transform;
156176
var realTransform = _trackingTransform ?? before;
@@ -159,32 +179,16 @@ private void DrawModelTransformEditor(PosingCapability posingCapability, float?
159179
bool didChange = false;
160180
bool anyActive = false;
161181

162-
163-
if(width.HasValue)
164-
ImGui.PushItemWidth(width.Value);
165-
166182
ImGui.Text("Model Transform");
167183

168-
didChange |= ImGui.DragFloat3("###position", ref realTransform.Position, 0.001f);
184+
didChange |= ImBrio.DragFloat3($"{FontAwesomeIcon.ArrowsUpDownLeftRight.ToIconString()}", ref realTransform.Position, 0.1f, "Position");
169185
anyActive |= ImGui.IsItemActive();
170-
if(ImGui.IsItemHovered())
171-
ImGui.SetTooltip("Position");
172-
173186

174-
didChange |= ImGui.DragFloat3("###rotation", ref realEuler, 0.1f);
187+
didChange |= ImBrio.DragFloat3($"{FontAwesomeIcon.ArrowsSpin.ToIconString()}", ref realEuler, 5.0f, "Rotation");
175188
anyActive |= ImGui.IsItemActive();
176-
if(ImGui.IsItemHovered())
177-
ImGui.SetTooltip("Rotation");
178-
179189

180-
didChange |= ImGui.DragFloat3("###scale", ref realTransform.Scale, 0.001f);
190+
didChange |= ImBrio.DragFloat3($"{FontAwesomeIcon.ExpandAlt.ToIconString()}", ref realTransform.Scale, 0.1f, "Scale");
181191
anyActive |= ImGui.IsItemActive();
182-
if(ImGui.IsItemHovered())
183-
ImGui.SetTooltip("Scale");
184-
185-
186-
if(width.HasValue)
187-
ImGui.PopItemWidth();
188192

189193

190194
realTransform.Rotation = realEuler.ToQuaternion();

0 commit comments

Comments
 (0)