fix send button and improve input focus
This commit is contained in:
@@ -44,6 +44,8 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
|||||||
private float _currentWindowOpacity = DefaultWindowOpacity;
|
private float _currentWindowOpacity = DefaultWindowOpacity;
|
||||||
private bool _isWindowPinned;
|
private bool _isWindowPinned;
|
||||||
private bool _showRulesOverlay;
|
private bool _showRulesOverlay;
|
||||||
|
private bool _refocusChatInput;
|
||||||
|
private string? _refocusChatInputKey;
|
||||||
|
|
||||||
private string? _selectedChannelKey;
|
private string? _selectedChannelKey;
|
||||||
private bool _scrollToBottom = true;
|
private bool _scrollToBottom = true;
|
||||||
@@ -308,8 +310,6 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
|||||||
_draftMessages.TryGetValue(channel.Key, out var draft);
|
_draftMessages.TryGetValue(channel.Key, out var draft);
|
||||||
draft ??= string.Empty;
|
draft ??= string.Empty;
|
||||||
|
|
||||||
using (ImRaii.Disabled(!canSend))
|
|
||||||
{
|
|
||||||
var style = ImGui.GetStyle();
|
var style = ImGui.GetStyle();
|
||||||
var sendButtonWidth = 100f * ImGuiHelpers.GlobalScale;
|
var sendButtonWidth = 100f * ImGuiHelpers.GlobalScale;
|
||||||
var counterWidth = ImGui.CalcTextSize($"{MaxMessageLength}/{MaxMessageLength}").X;
|
var counterWidth = ImGui.CalcTextSize($"{MaxMessageLength}/{MaxMessageLength}").X;
|
||||||
@@ -317,7 +317,15 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
|||||||
|
|
||||||
ImGui.SetNextItemWidth(-reservedWidth);
|
ImGui.SetNextItemWidth(-reservedWidth);
|
||||||
var inputId = $"##chat-input-{channel.Key}";
|
var inputId = $"##chat-input-{channel.Key}";
|
||||||
var send = ImGui.InputText(inputId, ref draft, MaxMessageLength, ImGuiInputTextFlags.EnterReturnsTrue);
|
if (_refocusChatInput && string.Equals(_refocusChatInputKey, channel.Key, StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
ImGui.SetKeyboardFocusHere();
|
||||||
|
_refocusChatInput = false;
|
||||||
|
_refocusChatInputKey = null;
|
||||||
|
}
|
||||||
|
ImGui.InputText(inputId, ref draft, MaxMessageLength);
|
||||||
|
var enterPressed = ImGui.IsItemFocused()
|
||||||
|
&& (ImGui.IsKeyPressed(ImGuiKey.Enter) || ImGui.IsKeyPressed(ImGuiKey.KeypadEnter));
|
||||||
_draftMessages[channel.Key] = draft;
|
_draftMessages[channel.Key] = draft;
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
@@ -340,14 +348,22 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
|||||||
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, sendHovered);
|
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, sendHovered);
|
||||||
ImGui.PushStyleColor(ImGuiCol.ButtonActive, sendActive);
|
ImGui.PushStyleColor(ImGuiCol.ButtonActive, sendActive);
|
||||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 6f * ImGuiHelpers.GlobalScale);
|
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 6f * ImGuiHelpers.GlobalScale);
|
||||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.PaperPlane, "Send", 100f * ImGuiHelpers.GlobalScale, center: true))
|
var sendClicked = false;
|
||||||
|
using (ImRaii.Disabled(!canSend))
|
||||||
{
|
{
|
||||||
send = true;
|
if (_uiSharedService.IconTextButton(FontAwesomeIcon.PaperPlane, $"Send##chat-send-{channel.Key}", 100f * ImGuiHelpers.GlobalScale, center: true))
|
||||||
|
{
|
||||||
|
sendClicked = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui.PopStyleVar();
|
ImGui.PopStyleVar();
|
||||||
ImGui.PopStyleColor(3);
|
ImGui.PopStyleColor(3);
|
||||||
|
|
||||||
if (send && TrySendDraft(channel, draft))
|
if (canSend && (enterPressed || sendClicked))
|
||||||
|
{
|
||||||
|
_refocusChatInput = true;
|
||||||
|
_refocusChatInputKey = channel.Key;
|
||||||
|
if (TrySendDraft(channel, draft))
|
||||||
{
|
{
|
||||||
_draftMessages[channel.Key] = string.Empty;
|
_draftMessages[channel.Key] = string.Empty;
|
||||||
_scrollToBottom = true;
|
_scrollToBottom = true;
|
||||||
@@ -969,6 +985,12 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
|||||||
_draftMessages.Remove(key);
|
_draftMessages.Remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_refocusChatInputKey is not null && !existingKeys.Contains(_refocusChatInputKey))
|
||||||
|
{
|
||||||
|
_refocusChatInputKey = null;
|
||||||
|
_refocusChatInput = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawConnectionControls()
|
private void DrawConnectionControls()
|
||||||
|
|||||||
Reference in New Issue
Block a user