// File: Ciaxur[P]yagb-emu/include/imgui/imgui_tables.cpp
// Function: ImGui::TableSetColumnWidth(int, float)
void ImGui::TableSetColumnWidth(int column_n, float width)
{
    ImGuiContext& g = *GImGui;
    ImGuiTable* table = g.CurrentTable;
    IM_ASSERT(table != NULL && table->IsLayoutLocked == false);
    IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
    ImGuiTableColumn* column_0 = &table->Columns[column_n];
    float column_0_width = width;

    // Apply constraints early
    // Compare both requested and actual given width to avoid overwriting requested width when column is stuck (minimum size, bounded)
    IM_ASSERT(table->MinColumnWidth > 0.0f);
    const float min_width = table->MinColumnWidth;
    const float max_width = ImMax(min_width, TableGetMaxColumnWidth(table, column_n));
    column_0_width = ImClamp(column_0_width, min_width, max_width);
    if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width)
        return;

    //IMGUI_DEBUG_LOG("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width);
    ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL;

    // In this surprisingly not simple because of how we support mixing Fixed and multiple Stretch columns.
    // - All fixed: easy.
    // - All stretch: easy.
    // - One or more fixed + one stretch: easy.
    // - One or more fixed + more than one stretch: tricky.
    // Qt when manual resize is enabled only support a single _trailing_ stretch column.

    // When forwarding resize from Wn| to Fn+1| we need to be considerate of the _NoResize flag on Fn+1.
    // FIXME-TABLE: Find a way to rewrite all of this so interactions feel more consistent for the user.
    // Scenarios:
    // - F1 F2 F3  resize from F1| or F2|   --> ok: alter ->WidthRequested of Fixed column. Subsequent columns will be offset.
    // - F1 F2 F3  resize from F3|          --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered.
    // - F1 F2 W3  resize from F1| or F2|   --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered, but it doesn't make much sense as the Stretch column will always be minimal size.
    // - F1 F2 W3  resize from W3|          --> ok: no-op (disabled by Resize Rule 1)
    // - W1 W2 W3  resize from W1| or W2|   --> ok
    // - W1 W2 W3  resize from W3|          --> ok: no-op (disabled by Resize Rule 1)
    // - W1 F2 F3  resize from F3|          --> ok: no-op (disabled by Resize Rule 1)
    // - W1 F2     resize from F2|          --> ok: no-op (disabled by Resize Rule 1)
    // - W1 W2 F3  resize from W1| or W2|   --> ok
    // - W1 F2 W3  resize from W1| or F2|   --> ok
    // - F1 W2 F3  resize from W2|          --> ok
    // - F1 W3 F2  resize from W3|          --> ok
    // - W1 F2 F3  resize from W1|          --> ok: equivalent to resizing |F2. F3 will not move.
    // - W1 F2 F3  resize from F2|          --> ok
    // All resizes from a Wx columns are locking other columns.

    // Possible improvements:
    // - W1 W2 W3  resize W1|               --> to not be stuck, both W2 and W3 would stretch down. Seems possible to fix. Would be most beneficial to simplify resize of all-weighted columns.
    // - W3 F1 F2  resize W3|               --> to not be stuck past F1|, both F1 and F2 would need to stretch down, which would be lossy or ambiguous. Seems hard to fix.

    // [Resize Rule 1] Can't resize from right of right-most visible column if there is any Stretch column. Implemented in TableUpdateLayout().

    // If we have all Fixed columns OR resizing a Fixed column that doesn't come after a Stretch one, we can do an offsetting resize.
    // This is the preferred resize path
    if (column_0->Flags & ImGuiTableColumnFlags_WidthFixed)
        if (!column_1 || table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder >= column_0->DisplayOrder)
        {
            column_0->WidthRequest = column_0_width;
            table->IsSettingsDirty = true;
            return;
        }

    // We can also use previous column if there's no next one (this is used when doing an auto-fit on the right-most stretch column)
    if (column_1 == NULL)
        column_1 = (column_0->PrevEnabledColumn != -1) ? &table->Columns[column_0->PrevEnabledColumn] : NULL;
    if (column_1 == NULL)
        return;

    // Resizing from right-side of a Stretch column before a Fixed column forward sizing to left-side of fixed column.
    // (old_a + old_b == new_a + new_b) --> (new_a == old_a + old_b - new_b)
    float column_1_width = ImMax(column_1->WidthRequest - (column_0_width - column_0->WidthRequest), min_width);
    column_0_width = column_0->WidthRequest + column_1->WidthRequest - column_1_width;
    IM_ASSERT(column_0_width > 0.0f && column_1_width > 0.0f);
    column_0->WidthRequest = column_0_width;
    column_1->WidthRequest = column_1_width;
    if ((column_0->Flags | column_1->Flags) & ImGuiTableColumnFlags_WidthStretch)
        TableUpdateColumnsWeightFromWidth(table);
    table->IsSettingsDirty = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movss %xmm0, -0x8(%rbp)
leaq 0xe8019(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x20a8(%rax), %rax
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x3d(%rbp)
je 0x12af61
movq -0x18(%rbp), %rax
movb 0x248(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x12af6a
jmp 0x12af6c
jmp 0x12af8b
leaq 0x61cb8(%rip), %rdi     # 0x18cc2b
leaq 0x61028(%rip), %rsi     # 0x18bfa2
movl $0x7ad, %edx            # imm = 0x7AD
leaq 0x61cd7(%rip), %rcx     # 0x18cc5d
callq 0xd180
xorl %eax, %eax
cmpl $0x0, -0x4(%rbp)
movb %al, -0x3e(%rbp)
jl 0x12afa6
movl -0x4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
setl %al
movb %al, -0x3e(%rbp)
movb -0x3e(%rbp), %al
testb $0x1, %al
jne 0x12afaf
jmp 0x12afb1
jmp 0x12afd0
leaq 0x61a61(%rip), %rdi     # 0x18ca19
leaq 0x60fe3(%rip), %rsi     # 0x18bfa2
movl $0x7ae, %edx            # imm = 0x7AE
leaq 0x61c92(%rip), %rcx     # 0x18cc5d
callq 0xd180
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
movl -0x4(%rbp), %esi
callq 0xeea20
movq %rax, -0x20(%rbp)
movss -0x8(%rbp), %xmm0
movss %xmm0, -0x24(%rbp)
movq -0x18(%rbp), %rax
movss 0xb4(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x12b004
jmp 0x12b023
leaq 0x61c7e(%rip), %rdi     # 0x18cc89
leaq 0x60f90(%rip), %rsi     # 0x18bfa2
movl $0x7b4, %edx            # imm = 0x7B4
leaq 0x61c3f(%rip), %rcx     # 0x18cc5d
callq 0xd180
movq -0x18(%rbp), %rax
movss 0xb4(%rax), %xmm0
movss %xmm0, -0x28(%rbp)
movss -0x28(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x18(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x12cde0
movaps %xmm0, %xmm1
movss -0x44(%rbp), %xmm0
callq 0x12a620
movss %xmm0, -0x2c(%rbp)
movss -0x24(%rbp), %xmm0
movss -0x28(%rbp), %xmm1
movss -0x2c(%rbp), %xmm2
callq 0x12cfd0
movss %xmm0, -0x24(%rbp)
movq -0x20(%rbp), %rax
movss 0x4(%rax), %xmm0
ucomiss -0x24(%rbp), %xmm0
jne 0x12b088
jp 0x12b088
jmp 0x12b099
movq -0x20(%rbp), %rax
movss 0x10(%rax), %xmm0
ucomiss -0x24(%rbp), %xmm0
jne 0x12b09e
jp 0x12b09e
jmp 0x12b265
movq -0x20(%rbp), %rax
movsbl 0x55(%rax), %eax
cmpl $-0x1, %eax
je 0x12b0c6
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rax
movsbl 0x55(%rax), %esi
callq 0xeea20
movq %rax, -0x50(%rbp)
jmp 0x12b0ce
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x12b0ce
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x12b143
cmpq $0x0, -0x38(%rbp)
je 0x12b123
movq -0x18(%rbp), %rax
movsbl 0x23c(%rax), %eax
cmpl $-0x1, %eax
je 0x12b123
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rax
movsbl 0x23c(%rax), %esi
callq 0xeea20
movsbl 0x52(%rax), %eax
movq -0x20(%rbp), %rcx
movsbl 0x52(%rcx), %ecx
cmpl %ecx, %eax
jl 0x12b141
movss -0x24(%rbp), %xmm0
movq -0x20(%rbp), %rax
movss %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x24f(%rax)
jmp 0x12b265
jmp 0x12b143
cmpq $0x0, -0x38(%rbp)
jne 0x12b182
movq -0x20(%rbp), %rax
movsbl 0x54(%rax), %eax
cmpl $-0x1, %eax
je 0x12b172
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rax
movsbl 0x54(%rax), %esi
callq 0xeea20
movq %rax, -0x58(%rbp)
jmp 0x12b17a
xorl %eax, %eax
movq %rax, -0x58(%rbp)
jmp 0x12b17a
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x12b18e
jmp 0x12b265
movq -0x38(%rbp), %rax
movss 0x10(%rax), %xmm0
movss -0x24(%rbp), %xmm1
movq -0x20(%rbp), %rax
subss 0x10(%rax), %xmm1
subss %xmm1, %xmm0
movss -0x28(%rbp), %xmm1
callq 0x12a620
movss %xmm0, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movss 0x10(%rax), %xmm0
movq -0x38(%rbp), %rax
addss 0x10(%rax), %xmm0
subss -0x3c(%rbp), %xmm0
movss %xmm0, -0x24(%rbp)
movss -0x24(%rbp), %xmm0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, -0x59(%rbp)
jbe 0x12b1f7
movss -0x3c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
seta %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x12b200
jmp 0x12b202
jmp 0x12b221
leaq 0x61a9d(%rip), %rdi     # 0x18cca6
leaq 0x60d92(%rip), %rsi     # 0x18bfa2
movl $0x7f2, %edx            # imm = 0x7F2
leaq 0x61a41(%rip), %rcx     # 0x18cc5d
callq 0xd180
movss -0x24(%rbp), %xmm0
movq -0x20(%rbp), %rax
movss %xmm0, 0x10(%rax)
movss -0x3c(%rbp), %xmm0
movq -0x38(%rbp), %rax
movss %xmm0, 0x10(%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
orl (%rcx), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x12b25a
movq -0x18(%rbp), %rdi
callq 0x131e10
movq -0x18(%rbp), %rax
movb $0x1, 0x24f(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)