Skip to content
Cecil edited this page Sep 16, 2018 · 1 revision

Understanding Layouts.

Simplified: Each 'slot' has an array of 'elements' A flow slot draws them across and a stack slot draws them down. An element can be a 'widget', art (like arrows and ovals) and it could also be a another slot. To draw them we need to know the starting top,left point (y,x) and the width and height of the element and any spacing between elements.

The size of an element could change when the Shoes program modifies an element or the slot by adding or deleting an element in the slot. Or, the user changes the window size and all slots and elements need to be drawn to fit the new space.

More details: One of those rectangular spaces could be a canvas (Shoes internal name). A canvas struct contains many fields (see canvas.h)

typedef struct {
    VALUE parent;
    VALUE attr;
    shoes_place place;
    cairo_t *cr, *shape;
    shoes_transform *st, **sts;
    int stl, stt;
    VALUE contents;
    unsigned char stage;
    long insertion;
    int cx, cy;               // cursor x and y (stored in absolute coords)
    int endx, endy;           // jump points if the cursor spills over
    int topy, fully;          // since we often stack vertically
    int width, height;        // the full height and width used by this box
    char hover;
    struct _shoes_app *app;
    SHOES_SLOT_OS *slot;
    SHOES_GROUP_OS group;
} shoes_canvas;

parent is a ruby VALUE (the Shoes slot that contains this canvas). The attr field is a Ruby hash that holds any style names and values and many other things (click handlers and more). Next is 'place' which is another struct of type 'shoes_place` (canvas.h)

typedef struct {
    int x, y, w, h, dx, dy;
    int ix, iy, iw, ih;
    unsigned char flags;
} shoes_place;

There's a whole lot of x,y,w,h fields in canvas and place - what do they mean, or do, and when do they get set, modified and why?

shoes_canvas_draw() in canvas.c is called a lot.

Welcome to shoes_place_decide(). It's in ruby.c around line 407. Looking at the end of the function we can guess that ix,iy,iw,ih are 'internal' (after adjusting for margins). Looking at shoes_canvas_draw and friends it seems like a good guess for ix,iy,iw,ih.

Clone this wiki locally