CogImGui: Fix key down/up not properly sent to imgui

This commit is contained in:
Arnaud Jamin
2023-12-18 12:47:38 -05:00
parent 85a903a341
commit 829be00034
2 changed files with 13 additions and 12 deletions
@@ -37,12 +37,12 @@ void SCogImguiWidget::Tick(const FGeometry& AllottedGeometry, const double InCur
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
int32 SCogImguiWidget::OnPaint( int32 SCogImguiWidget::OnPaint(
const FPaintArgs& Args, const FPaintArgs& Args,
const FGeometry& AllottedGeometry, const FGeometry& AllottedGeometry,
const FSlateRect& MyClippingRect, const FSlateRect& MyClippingRect,
FSlateWindowElementList& OutDrawElements, FSlateWindowElementList& OutDrawElements,
int32 LayerId, int32 LayerId,
const FWidgetStyle& WidgetStyle, const FWidgetStyle& WidgetStyle,
bool bParentEnabled) const bool bParentEnabled) const
{ {
@@ -122,17 +122,17 @@ FReply SCogImguiWidget::OnKeyChar(const FGeometry& MyGeometry, const FCharacterE
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FReply SCogImguiWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) FReply SCogImguiWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent)
{ {
return HandleKeyEvent(MyGeometry, KeyEvent); return HandleKeyEvent(MyGeometry, KeyEvent, true);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FReply SCogImguiWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) FReply SCogImguiWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent)
{ {
return HandleKeyEvent(MyGeometry, KeyEvent); return HandleKeyEvent(MyGeometry, KeyEvent, false);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down)
{ {
if (Context->GetEnableInput() == false) if (Context->GetEnableInput() == false)
{ {
@@ -152,8 +152,9 @@ FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEv
{ {
return FReply::Unhandled(); return FReply::Unhandled();
} }
ImGuiIO& IO = ImGui::GetIO(); ImGuiIO& IO = ImGui::GetIO();
IO.AddKeyEvent(FCogImguiInputHelper::ToImKey(KeyEvent.GetKey()), false); IO.AddKeyEvent(FCogImguiInputHelper::ToImKey(KeyEvent.GetKey()), Down);
IO.AddKeyEvent(ImGuiMod_Ctrl, KeyEvent.IsControlDown()); IO.AddKeyEvent(ImGuiMod_Ctrl, KeyEvent.IsControlDown());
IO.AddKeyEvent(ImGuiMod_Shift, KeyEvent.IsShiftDown()); IO.AddKeyEvent(ImGuiMod_Shift, KeyEvent.IsShiftDown());
IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown()); IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown());
@@ -177,7 +178,7 @@ FReply SCogImguiWidget::OnAnalogValueChanged(const FGeometry& MyGeometry, const
// return FReply::Unhandled(); // return FReply::Unhandled();
//} //}
return FReply::Unhandled(); return FReply::Unhandled();
} }
return FReply::Handled(); return FReply::Handled();
@@ -19,7 +19,7 @@ class COGIMGUI_API SCogImguiWidget : public SLeafWidget
public: public:
SLATE_BEGIN_ARGS(SCogImguiWidget) {} SLATE_BEGIN_ARGS(SCogImguiWidget) {}
SLATE_ARGUMENT(FCogImguiContext*, Context) SLATE_ARGUMENT(FCogImguiContext*, Context)
SLATE_END_ARGS() SLATE_END_ARGS()
void Construct(const FArguments& InArgs); void Construct(const FArguments& InArgs);
@@ -53,7 +53,7 @@ public:
protected: protected:
FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent); FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down);
void RefreshVisibility(); void RefreshVisibility();