static napi_value napi_stretch_style_create()

in GaiaXHarmony/GXStretchBinding/GXStretch/src/main/cpp/napi_init.cpp [378:645]


static napi_value napi_stretch_style_create(napi_env env, napi_callback_info info) {


    size_t argc = 0;
    // argv 传入 nullptr 来获取传入参数真实数量
    napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr);
    if (argc != 59) {
        OH_LOG_ERROR(LOG_APP, "napi_stretch napi_stretch_style_create argc != 59 argc=%{public}zu", argc);
        return nullptr;
    }

    OH_LOG_DEBUG(LOG_APP, "napi_stretch napi_stretch_style_create argc=%{public}zu", argc);

    // 创建数组以获取JS传入的参数
    napi_value *argv = new napi_value[argc];
    napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);

    int32_t display;
    napi_get_value_int32(env, argv[0], &display);

    int32_t position_type;
    napi_get_value_int32(env, argv[1], &position_type);

    int32_t direction;
    napi_get_value_int32(env, argv[2], &direction);

    int32_t flex_direction;
    napi_get_value_int32(env, argv[3], &flex_direction);

    int32_t flex_wrap;
    napi_get_value_int32(env, argv[4], &flex_wrap);

    int32_t overflow;
    napi_get_value_int32(env, argv[5], &overflow);

    int32_t align_items;
    napi_get_value_int32(env, argv[6], &align_items);

    int32_t align_self;
    napi_get_value_int32(env, argv[7], &align_self);

    int32_t align_content;
    napi_get_value_int32(env, argv[8], &align_content);

    int32_t justify_content;
    napi_get_value_int32(env, argv[9], &justify_content);

    // position

    int32_t position_start_type;
    napi_get_value_int32(env, argv[10], &position_start_type);

    double position_start_value;
    napi_get_value_double(env, argv[11], &position_start_value);

    int32_t position_end_type;
    napi_get_value_int32(env, argv[12], &position_end_type);

    double position_end_value;
    napi_get_value_double(env, argv[13], &position_end_value);

    int32_t position_top_type;
    napi_get_value_int32(env, argv[14], &position_top_type);

    double position_top_value;
    napi_get_value_double(env, argv[15], &position_top_value);

    int32_t position_bottom_type;
    napi_get_value_int32(env, argv[16], &position_bottom_type);

    double position_bottom_value;
    napi_get_value_double(env, argv[17], &position_bottom_value);

    StretchStyleRect position = {
        {position_start_type, (float)position_start_value},  // start
        {position_end_type, (float)position_end_value},      // end
        {position_top_type, (float)position_top_value},      // top
        {position_bottom_type, (float)position_bottom_value} // bottom
    };


    // margin

    int32_t margin_start_type;
    napi_get_value_int32(env, argv[18], &margin_start_type);

    double margin_start_value;
    napi_get_value_double(env, argv[19], &margin_start_value);

    int32_t margin_end_type;
    napi_get_value_int32(env, argv[20], &margin_end_type);

    double margin_end_value;
    napi_get_value_double(env, argv[21], &margin_end_value);

    int32_t margin_top_type;
    napi_get_value_int32(env, argv[22], &margin_top_type);

    double margin_top_value;
    napi_get_value_double(env, argv[23], &margin_top_value);

    int32_t margin_bottom_type;
    napi_get_value_int32(env, argv[24], &margin_bottom_type);

    double margin_bottom_value;
    napi_get_value_double(env, argv[25], &margin_bottom_value);

    StretchStyleRect margin = {
        {margin_start_type, (float)margin_start_value},  // start
        {margin_end_type, (float)margin_end_value},      // end
        {margin_top_type, (float)margin_top_value},      // top
        {margin_bottom_type, (float)margin_bottom_value} // bottom
    };


    // padding

    int32_t padding_start_type;
    napi_get_value_int32(env, argv[26], &padding_start_type);

    double padding_start_value;
    napi_get_value_double(env, argv[27], &padding_start_value);

    int32_t padding_end_type;
    napi_get_value_int32(env, argv[28], &padding_end_type);

    double padding_end_value;
    napi_get_value_double(env, argv[29], &padding_end_value);

    int32_t padding_top_type;
    napi_get_value_int32(env, argv[30], &padding_top_type);

    double padding_top_value;
    napi_get_value_double(env, argv[31], &padding_top_value);

    int32_t padding_bottom_type;
    napi_get_value_int32(env, argv[32], &padding_bottom_type);

    double padding_bottom_value;
    napi_get_value_double(env, argv[33], &padding_bottom_value);

    StretchStyleRect padding = {
        {padding_start_type, (float)padding_start_value},  // start
        {padding_end_type, (float)padding_end_value},      // end
        {padding_top_type, (float)padding_top_value},      // top
        {padding_bottom_type, (float)padding_bottom_value} // bottom
    };

    // border


    int32_t border_start_type;
    napi_get_value_int32(env, argv[34], &border_start_type);

    double border_start_value;
    napi_get_value_double(env, argv[35], &border_start_value);

    int32_t border_end_type;
    napi_get_value_int32(env, argv[36], &border_end_type);

    double border_end_value;
    napi_get_value_double(env, argv[37], &border_end_value);

    int32_t border_top_type;
    napi_get_value_int32(env, argv[38], &border_top_type);

    double border_top_value;
    napi_get_value_double(env, argv[39], &border_top_value);

    int32_t border_bottom_type;
    napi_get_value_int32(env, argv[40], &border_bottom_type);

    double border_bottom_value;
    napi_get_value_double(env, argv[41], &border_bottom_value);

    StretchStyleRect border = {
        {border_start_type, (float)border_start_value},  // start
        {border_end_type, (float)border_end_value},      // end
        {border_top_type, (float)border_top_value},      // top
        {border_bottom_type, (float)border_bottom_value} // bottom
    };

    //
    double flex_grow;
    napi_get_value_double(env, argv[42], &flex_grow);

    double flex_shrink;
    napi_get_value_double(env, argv[43], &flex_shrink);

    // flex_basis

    int32_t flex_basis_type;
    napi_get_value_int32(env, argv[44], &flex_basis_type);

    double flex_basis_value;
    napi_get_value_double(env, argv[45], &flex_basis_value);

    StretchStyleDimension flex_basis = {flex_basis_type, (float)flex_basis_value};

    // size
    int32_t width_type;
    napi_get_value_int32(env, argv[46], &width_type);

    double width_value;
    napi_get_value_double(env, argv[47], &width_value);

    int32_t height_type;
    napi_get_value_int32(env, argv[48], &height_type);

    double height_value;
    napi_get_value_double(env, argv[49], &height_value);

    StretchStyleSize size = {
        {width_type, (float)width_value},
        {height_type, (float)height_value},
    };

    // min-size
    int32_t min_width_type;
    napi_get_value_int32(env, argv[50], &min_width_type);

    double min_width_value;
    napi_get_value_double(env, argv[51], &min_width_value);

    int32_t min_height_type;
    napi_get_value_int32(env, argv[52], &min_height_type);

    double min_height_value;
    napi_get_value_double(env, argv[53], &min_height_value);

    StretchStyleSize min_size = {
        {min_width_type, (float)min_width_value},
        {min_height_type, (float)min_height_value},
    };

    // max-size
    int32_t max_width_type;
    napi_get_value_int32(env, argv[54], &max_width_type);

    double max_width_value;
    napi_get_value_double(env, argv[55], &max_width_value);

    int32_t max_height_type;
    napi_get_value_int32(env, argv[56], &max_height_type);

    double max_height_value;
    napi_get_value_double(env, argv[57], &max_height_value);

    StretchStyleSize max_size = {
        {max_width_type, (float)max_width_value},
        {max_height_type, (float)max_height_value},
    };

    //
    double aspect_ratio;
    napi_get_value_double(env, argv[58], &aspect_ratio);

    void *ptr = stretch_style_create(display, position_type, direction, flex_direction, flex_wrap, overflow, align_items, align_self, align_content, justify_content,
                                     position, margin, padding, border, (float)flex_grow, (float)flex_shrink, flex_basis, size, min_size, max_size, (float)aspect_ratio);

    int64_t value = (int64_t)ptr;

    napi_value ret;
    napi_create_int64(env, value, &ret);

    OH_LOG_DEBUG(LOG_APP, "napi_stretch napi_stretch_style_create ptr=%{public}p value=%{public}ld", ptr, value);
    return ret;
}