refactor: centre buttons

This commit is contained in:
Anna 2024-01-03 23:40:32 -05:00
parent da918e4bf4
commit b7bf72d4d1
Signed by: anna
GPG Key ID: D0943384CD9F87D1
1 changed files with 28 additions and 26 deletions

View File

@ -109,37 +109,39 @@ internal class QuestionsTab {
}
}
var heightLeft = ImGui.GetContentRegionAvail().Y;
if (heightLeft > 0) {
heightLeft -= ImGuiHelpers.GetButtonSize("A").Y;
ImGui.Dummy(new Vector2(1, heightLeft));
var pageLabel = $"{this.Plugin.Manager.Page:N0}";
ImGui.PushFont(UiBuilder.IconFont);
using (new OnDispose(ImGui.PopFont)) {
var prev = ImGuiHelpers.GetButtonSize(FontAwesomeIcon.ArrowLeft.ToIconString());
var label = ImGui.CalcTextSize(pageLabel);
var next = ImGuiHelpers.GetButtonSize(FontAwesomeIcon.ArrowRight.ToIconString());
var heightLeft = ImGui.GetContentRegionAvail().Y;
if (heightLeft > 0) {
heightLeft -= Math.Max(prev.Y, next.Y);
ImGui.Dummy(new Vector2(1, heightLeft));
}
var width = prev.X + label.X + next.X + ImGui.GetStyle().ItemSpacing.X * 2;
ImGuiHelpers.CenterCursorFor(width);
}
if (ImGui.BeginTable("##pagination-controls", 3)) {
ImGui.TableSetupColumn("##prev", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("##page", ImGuiTableColumnFlags.WidthFixed);
ImGui.TableSetupColumn("##next", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableNextRow();
if (ImGui.TableSetColumnIndex(0)) {
using var endDisabled = ImGuiHelper.WithDisabled(loading || this.Plugin.Manager.Page == 1);
if (ImGuiHelper.IconButton(FontAwesomeIcon.ArrowLeft)) {
this.Plugin.Manager.Page -= 1;
}
using (ImGuiHelper.WithDisabled(loading || this.Plugin.Manager.Page == 1)) {
if (ImGuiHelper.IconButton(FontAwesomeIcon.ArrowLeft)) {
this.Plugin.Manager.Page -= 1;
}
}
if (ImGui.TableSetColumnIndex(1)) {
ImGui.TextUnformatted($"{this.Plugin.Manager.Page:N0}");
ImGui.SameLine();
ImGui.TextUnformatted(pageLabel);
ImGui.SameLine();
using (ImGuiHelper.WithDisabled(loading || !this.Plugin.Manager.HasNext)) {
if (ImGuiHelper.IconButton(FontAwesomeIcon.ArrowRight)) {
this.Plugin.Manager.Page += 1;
}
if (ImGui.TableSetColumnIndex(2)) {
using var endDisabled = ImGuiHelper.WithDisabled(loading || !this.Plugin.Manager.HasNext);
if (ImGuiHelper.IconButton(FontAwesomeIcon.ArrowRight)) {
this.Plugin.Manager.Page += 1;
}
}
ImGui.EndTable();
}
}
}