More uiArea work. uiAreas now no longer allow arbitrary scroll unit size because GTK+ doesn't support that (it assumes 1 unit = 1 pixel).

This commit is contained in:
Pietro Gagliardi 2015-09-05 20:05:48 -04:00
parent 22d690d535
commit 8344ed5f17
3 changed files with 18 additions and 37 deletions

View File

@ -23,36 +23,35 @@ lower and upper are the bounds of the adjusment, in units
step_increment is the number of units scrolled when using the arrow keys or the buttons on an old-style scrollbar
page_incremenet is the number of page_size units scrolled with the Page Up/Down keys
according to baedert, the other condition is that upper >= page_size, and the effect is that the largest possible value is upper - page_size
TODO so the below is wrong but I'm not sure what's right...
unfortunately, everything in GTK+ assumes 1 unit = 1 pixel
let's do the same :/
*/
static void updateScroll(areaWidget *a)
{
struct areaPrivate *ap = a->priv;
uintmax_t count, pixelsPer;
uintmax_t count;
// don't call if too early
if (ap->ha == NULL || ap->va == NULL)
return;
(*(ap->ah->HScrollConfig))(ap->ah, ap->a,
&count, &pixelsPer);
count = (*(ap->ah->HScrollMax))(ap->ah, ap->a);
gtk_adjustment_configure(ap->ha,
gtk_adjustment_get_value(ap->ha),
0,
count,
1,
ap->clientWidth / pixelsPer,
ap->clientWidth,
MIN(count, ap->clientWidth));
// TODO sometimes changing htis results inn no change until the window is significantly resized
(*(ap->ah->VScrollConfig))(ap->ah, ap->a,
&count, &pixelsPer);
count = (*(ap->ah->VScrollMax))(ap->ah, ap->a);
gtk_adjustment_configure(ap->va,
gtk_adjustment_get_value(ap->va),
0,
count,
1,
ap->clientHeight / pixelsPer,
ap->clientHeight,
MIN(count, ap->clientHeight));
// TODO notify adjustment changes?

View File

@ -10,20 +10,16 @@ struct handler {
static GtkWidget *area;
static struct handler h;
static GtkWidget *nhspinb;
static GtkWidget *pphspinb;
static GtkWidget *nvspinb;
static GtkWidget *ppvspinb;
static void handlerHScrollConfig(uiAreaHandler *a, uiArea *area, uintmax_t *n, uintmax_t *pixelsPer)
static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area)
{
*n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
*pixelsPer = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pphspinb));
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
}
static void handlerVScrollConfig(uiAreaHandler *a, uiArea *area, uintmax_t *n, uintmax_t *pixelsPer)
static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
{
*n = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb));
*pixelsPer = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ppvspinb));
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb));
}
static void recalcScroll(GtkSpinButton *sb, gpointer data)
@ -48,8 +44,8 @@ int main(void)
GtkWidget *scroller;
GtkWidget *grid;
h.ah.HScrollConfig = handlerHScrollConfig;
h.ah.VScrollConfig = handlerVScrollConfig;
h.ah.HScrollMax = handlerHScrollMax;
h.ah.VScrollMax = handlerVScrollMax;
gtk_init(NULL, NULL);
@ -80,26 +76,12 @@ int main(void)
gtk_grid_attach(GTK_GRID(grid), nhspinb,
1, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("H Pixels Per"),
0, 1, 1, 1);
pphspinb = makeSpinbox(1);
gtk_grid_attach(GTK_GRID(grid), pphspinb,
1, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("V Count"),
0, 2, 1, 1);
0, 1, 1, 1);
nvspinb = makeSpinbox(0);
gtk_grid_attach(GTK_GRID(grid), nvspinb,
1, 2, 1, 1);
gtk_grid_attach(GTK_GRID(grid),
gtk_label_new("V Pixels Per"),
0, 3, 1, 1);
ppvspinb = makeSpinbox(1);
gtk_grid_attach(GTK_GRID(grid), ppvspinb,
1, 3, 1, 1);
1, 1, 1, 1);
area = newArea((uiAreaHandler *) (&h));
gtk_container_add(GTK_CONTAINER(scroller), area);

View File

@ -6,8 +6,8 @@ typedef struct uiAreaDrawParams uiAreaDrawParams;
struct uiAreaHandler {
// TODO draw
void (*HScrollConfig)(uiAreaHandler *, uiArea *, uintmax_t *, uintmax_t *);
void (*VScrollConfig)(uiAreaHandler *, uiArea *, uintmax_t *, uintmax_t *);
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *);
};
// TODO uiAreaDrawParams