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 bool _isWindowPinned;
|
||||
private bool _showRulesOverlay;
|
||||
private bool _refocusChatInput;
|
||||
private string? _refocusChatInputKey;
|
||||
|
||||
private string? _selectedChannelKey;
|
||||
private bool _scrollToBottom = true;
|
||||
@@ -308,46 +310,60 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
||||
_draftMessages.TryGetValue(channel.Key, out var draft);
|
||||
draft ??= string.Empty;
|
||||
|
||||
var style = ImGui.GetStyle();
|
||||
var sendButtonWidth = 100f * ImGuiHelpers.GlobalScale;
|
||||
var counterWidth = ImGui.CalcTextSize($"{MaxMessageLength}/{MaxMessageLength}").X;
|
||||
var reservedWidth = sendButtonWidth + counterWidth + style.ItemSpacing.X * 2f;
|
||||
|
||||
ImGui.SetNextItemWidth(-reservedWidth);
|
||||
var inputId = $"##chat-input-{channel.Key}";
|
||||
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;
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey3);
|
||||
ImGui.TextUnformatted($"{draft.Length}/{MaxMessageLength}");
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGui.SameLine();
|
||||
var buttonScreenPos = ImGui.GetCursorScreenPos();
|
||||
var rightEdgeScreen = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
|
||||
var desiredButtonX = rightEdgeScreen - sendButtonWidth;
|
||||
var minButtonX = buttonScreenPos.X + style.ItemSpacing.X;
|
||||
var finalButtonX = MathF.Max(minButtonX, desiredButtonX);
|
||||
ImGui.SetCursorScreenPos(new Vector2(finalButtonX, buttonScreenPos.Y));
|
||||
var sendColor = UIColors.Get("LightlessPurpleDefault");
|
||||
var sendHovered = UIColors.Get("LightlessPurple");
|
||||
var sendActive = UIColors.Get("LightlessPurpleActive");
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, sendColor);
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, sendHovered);
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonActive, sendActive);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 6f * ImGuiHelpers.GlobalScale);
|
||||
var sendClicked = false;
|
||||
using (ImRaii.Disabled(!canSend))
|
||||
{
|
||||
var style = ImGui.GetStyle();
|
||||
var sendButtonWidth = 100f * ImGuiHelpers.GlobalScale;
|
||||
var counterWidth = ImGui.CalcTextSize($"{MaxMessageLength}/{MaxMessageLength}").X;
|
||||
var reservedWidth = sendButtonWidth + counterWidth + style.ItemSpacing.X * 2f;
|
||||
|
||||
ImGui.SetNextItemWidth(-reservedWidth);
|
||||
var inputId = $"##chat-input-{channel.Key}";
|
||||
var send = ImGui.InputText(inputId, ref draft, MaxMessageLength, ImGuiInputTextFlags.EnterReturnsTrue);
|
||||
_draftMessages[channel.Key] = draft;
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey3);
|
||||
ImGui.TextUnformatted($"{draft.Length}/{MaxMessageLength}");
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGui.SameLine();
|
||||
var buttonScreenPos = ImGui.GetCursorScreenPos();
|
||||
var rightEdgeScreen = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
|
||||
var desiredButtonX = rightEdgeScreen - sendButtonWidth;
|
||||
var minButtonX = buttonScreenPos.X + style.ItemSpacing.X;
|
||||
var finalButtonX = MathF.Max(minButtonX, desiredButtonX);
|
||||
ImGui.SetCursorScreenPos(new Vector2(finalButtonX, buttonScreenPos.Y));
|
||||
var sendColor = UIColors.Get("LightlessPurpleDefault");
|
||||
var sendHovered = UIColors.Get("LightlessPurple");
|
||||
var sendActive = UIColors.Get("LightlessPurpleActive");
|
||||
ImGui.PushStyleColor(ImGuiCol.Button, sendColor);
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, sendHovered);
|
||||
ImGui.PushStyleColor(ImGuiCol.ButtonActive, sendActive);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 6f * ImGuiHelpers.GlobalScale);
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.PaperPlane, "Send", 100f * ImGuiHelpers.GlobalScale, center: true))
|
||||
if (_uiSharedService.IconTextButton(FontAwesomeIcon.PaperPlane, $"Send##chat-send-{channel.Key}", 100f * ImGuiHelpers.GlobalScale, center: true))
|
||||
{
|
||||
send = true;
|
||||
sendClicked = true;
|
||||
}
|
||||
ImGui.PopStyleVar();
|
||||
ImGui.PopStyleColor(3);
|
||||
}
|
||||
ImGui.PopStyleVar();
|
||||
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;
|
||||
_scrollToBottom = true;
|
||||
@@ -969,6 +985,12 @@ public sealed class ZoneChatUi : WindowMediatorSubscriberBase
|
||||
_draftMessages.Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (_refocusChatInputKey is not null && !existingKeys.Contains(_refocusChatInputKey))
|
||||
{
|
||||
_refocusChatInputKey = null;
|
||||
_refocusChatInput = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnectionControls()
|
||||
|
||||
Reference in New Issue
Block a user