Exemplo n.º 1
0
static int get_directory_pathname(struct directory *begin,
                                  struct directory *last,
                                  char *buf, size_t count)
{
    struct directory *ptr;
    sf_list_iter_t iter;
    int nwritten = 0;

    if (!sf_list_begin(&fs.directories, &iter)) {
        return nwritten;
    }

    ptr = sf_list_iter_elt(&iter);
    while (begin != ptr) {
        sf_list_iter_next(&iter);
        ptr = sf_list_iter_elt(&iter);
    }

    do {
        int n;
        int len;

        ptr = sf_list_iter_elt(&iter);
        len = strlen(ptr->name) + 1;
        n = snprintf(buf, count, "%s/", ptr->name);
        nwritten += n;
        if (n != len) {
            break;
        }
        buf += n;
        count -= n;
    } while (ptr != last && sf_list_iter_next(&iter));

    return nwritten;
}
Exemplo n.º 2
0
static int get_zip_cwd(char *buf, size_t count)
{
    sf_list_iter_t iter;
    int iszip = 0;

    buf[0] = '\0';

    if (sf_list_begin(&fs.directories, &iter)) do {
        struct directory *d = sf_list_iter_elt(&iter);
        if (d->iszip) {
            iszip = 1;
            break;
        }
    } while (sf_list_iter_next(&iter));

    if (iszip && sf_list_iter_next(&iter)) {
        return get_directory_pathname(sf_list_iter_elt(&iter),
                                      sf_list_tail(&fs.directories),
                                      buf, count);
    }

    return 0;
}
Exemplo n.º 3
0
static void ui_toolbox_update_buttons(struct ui_toolbox *tb) {
    sf_list_iter_t iter;
    float xstep;
    float x;

    /*
     * 假设每个 buttons 的宽度相同,高度和 toolbox 一样。
     * 后期改进可以使用权重来计算每个 button 的位置。
     */
    xstep = tb->ui.area.w * 1.0f / (sf_list_cnt(&tb->buttons) + 1);

    x = xstep;

    if (sf_list_begin(&tb->buttons, &iter)) do {
        struct ui *button = *(struct ui**) sf_list_iter_elt(&iter);
        ui_move(button, x - button->area.w / 2, 0);
        x += xstep;
    } while (sf_list_iter_next(&iter));
}