~neon/nemini

e79adedf85257f82a48be3ec008545763f38457f — Jens Pitkanen 3 years ago 9c1b823
Fix initial scroll
3 files changed, 16 insertions(+), 8 deletions(-)

M src/browser.c
M src/browser.h
M src/main.c
M src/browser.c => src/browser.c +2 -1
@@ 114,6 114,7 @@ static int load_page(void *data) {

enum nemini_error browser_start_loading(const char *url,
                                        struct loaded_page *from,
                                        float initial_scroll,
                                        int page_width, float page_scale) {
    struct loaded_page page = {0};
    struct gemini_response response = {0};


@@ 125,7 126,7 @@ enum nemini_error browser_start_loading(const char *url,
    page.response = response;
    page.rendered_width = page_width;
    page.rendered_scale = page_scale;
    page.rendered_scroll = 0;
    page.rendered_scroll = initial_scroll;
    page.surface = NULL;
    page.texture = NULL;
    sb_push(loaded_pages, page);

M src/browser.h => src/browser.h +1 -0
@@ 42,6 42,7 @@ struct loaded_page {
void browser_set_status(enum loading_status new_status);
enum nemini_error browser_start_loading(const char *url,
                                        struct loaded_page *from,
                                        float initial_scroll,
                                        int page_width, float page_scale);
void browser_redraw_page(struct loaded_page *page, int page_width,
                         float page_scale);

M src/main.c => src/main.c +13 -7
@@ 103,6 103,12 @@ int main(int argc, char **argv) {
    cursor_hand = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
    cursor_wait = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAITARROW);

    // UI state:
    float loading_bar_width = 0;
    float scroll_margin = 64;
    float scroll = scroll_margin;
    int content_height = 0;

    browser_set_status(LOADING_CONNECTING);
    if (argc >= 2) {
        float scale_x, scale_y;


@@ 113,17 119,14 @@ int main(int argc, char **argv) {
        SDL_GetRendererOutputSize(renderer, &width, &height);

        int content_width = get_desired_content_width(width, scale_x);
        browser_start_loading(argv[1], NULL, content_width, scale_x);
        browser_start_loading(argv[1], NULL,
                              scroll_margin,
                              content_width, scale_x);
    } else {
        SDL_Log("Usage: %s <url>", argv[0]);
        return 0;
    }

    // UI state:
    float loading_bar_width = 0;
    float scroll = 0;
    int content_height = 0;

    bool mouse_held = false;
    bool mouse_clicked = false;
    SDL_Point mouse = {0};


@@ 179,7 182,9 @@ int main(int argc, char **argv) {
            current_cursor = cursor_wait;
        }

        scroll = SDL_min(64, SDL_max(height - content_height - 64, scroll));
        int max_scroll = scroll_margin;
        int min_scroll = height - content_height - scroll_margin;
        scroll = SDL_min(max_scroll, SDL_max(min_scroll, scroll));

        if (page->texture != NULL || page->surface != NULL) {
            if (page->surface != NULL) {


@@ 241,6 246,7 @@ int main(int argc, char **argv) {

                        if (mouse_clicked) {
                            browser_start_loading(link.link, page,
                                                  scroll_margin,
                                                  desired_width, scale_x);
                        }
                    }