<commit_before>#include "../stdafx.h"
#include "../../foobar2000/SDK/foobar2000.h"

namespace uih {

void ListView::ensure_visible(t_size index, EnsureVisibleMode mode)
{
    if (index > m_items.get_count())
        return;

    const auto item_visibility = get_item_visibility(index);

    const auto item_area_height = get_item_area_height();
    const auto item_height = get_item_height(index);
    const auto item_start_position = get_item_position(index);
    const auto item_end_position = get_item_position_bottom(index);

    switch (mode) {
    case EnsureVisibleMode::PreferCentringItem:
        switch (item_visibility) {
        case ItemVisibility::ObscuredAbove:
            scroll(item_start_position);
            break;
        case ItemVisibility::ObscuredBelow:
            scroll(item_end_position - item_area_height);
            break;
        case ItemVisibility::FullyVisible:
            break;
        default:
            scroll(item_start_position - (item_area_height + item_height) / 2);
        }
        break;
    case EnsureVisibleMode::PreferMinimalScrolling:
        switch (item_visibility) {
        case ItemVisibility::ObscuredAbove:
        case ItemVisibility::AboveViewport:
            scroll(item_start_position);
            break;
        case ItemVisibility::ObscuredBelow:
        case ItemVisibility::BelowViewport:
            scroll(item_end_position - item_area_height);
            break;
        case ItemVisibility::FullyVisible:
            break;
        }
    }
}

void ListView::scroll(int position, bool b_horizontal, bool update_display)
{
    const INT scroll_bar_type = b_horizontal ? SB_HORZ : SB_VERT;
    int& scroll_position = b_horizontal ? m_horizontal_scroll_position : m_scroll_position;
    const int original_scroll_position = scroll_position;<commit_msg>Correct centring of list view items when ensuring an item is visible<commit_after>#include "../stdafx.h"
#include "../../foobar2000/SDK/foobar2000.h"

namespace uih {

void ListView::ensure_visible(t_size index, EnsureVisibleMode mode)
{
    if (index > m_items.get_count())
        return;

    const auto item_visibility = get_item_visibility(index);

    const auto item_area_height = get_item_area_height();
    const auto item_height = get_item_height(index);
    const auto item_start_position = get_item_position(index);
    const auto item_end_position = get_item_position_bottom(index);

    switch (mode) {
    case EnsureVisibleMode::PreferCentringItem:
        switch (item_visibility) {
        case ItemVisibility::ObscuredAbove:
            scroll(item_start_position);
            break;
        case ItemVisibility::ObscuredBelow:
            scroll(item_end_position - item_area_height);
            break;
        case ItemVisibility::FullyVisible:
            break;
        default:
            scroll(item_start_position - (item_area_height - item_height) / 2);
        }
        break;
    case EnsureVisibleMode::PreferMinimalScrolling:
        switch (item_visibility) {
        case ItemVisibility::ObscuredAbove:
        case ItemVisibility::AboveViewport:
            scroll(item_start_position);
            break;
        case ItemVisibility::ObscuredBelow:
        case ItemVisibility::BelowViewport:
            scroll(item_end_position - item_area_height);
            break;
        case ItemVisibility::FullyVisible:
            break;
        }
    }
}

void ListView::scroll(int position, bool b_horizontal, bool update_display)
{
    const INT scroll_bar_type = b_horizontal ? SB_HORZ : SB_VERT;
    int& scroll_position = b_horizontal ? m_horizontal_scroll_position : m_scroll_position;
    const int original_scroll_position = scroll_position;
{'fraction_non_alphanumeric': 0.07922392886014551, 'fraction_numerical': 0.004850444624090542, 'mean_word_length': 3.012972972972973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7366564', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1037, 'n_words': 212}