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:
parent
22d690d535
commit
8344ed5f17
|
@ -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
|
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
|
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
|
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)
|
static void updateScroll(areaWidget *a)
|
||||||
{
|
{
|
||||||
struct areaPrivate *ap = a->priv;
|
struct areaPrivate *ap = a->priv;
|
||||||
uintmax_t count, pixelsPer;
|
uintmax_t count;
|
||||||
|
|
||||||
// don't call if too early
|
// don't call if too early
|
||||||
if (ap->ha == NULL || ap->va == NULL)
|
if (ap->ha == NULL || ap->va == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
(*(ap->ah->HScrollConfig))(ap->ah, ap->a,
|
count = (*(ap->ah->HScrollMax))(ap->ah, ap->a);
|
||||||
&count, &pixelsPer);
|
|
||||||
gtk_adjustment_configure(ap->ha,
|
gtk_adjustment_configure(ap->ha,
|
||||||
gtk_adjustment_get_value(ap->ha),
|
gtk_adjustment_get_value(ap->ha),
|
||||||
0,
|
0,
|
||||||
count,
|
count,
|
||||||
1,
|
1,
|
||||||
ap->clientWidth / pixelsPer,
|
ap->clientWidth,
|
||||||
MIN(count, ap->clientWidth));
|
MIN(count, ap->clientWidth));
|
||||||
|
|
||||||
// TODO sometimes changing htis results inn no change until the window is significantly resized
|
count = (*(ap->ah->VScrollMax))(ap->ah, ap->a);
|
||||||
(*(ap->ah->VScrollConfig))(ap->ah, ap->a,
|
|
||||||
&count, &pixelsPer);
|
|
||||||
gtk_adjustment_configure(ap->va,
|
gtk_adjustment_configure(ap->va,
|
||||||
gtk_adjustment_get_value(ap->va),
|
gtk_adjustment_get_value(ap->va),
|
||||||
0,
|
0,
|
||||||
count,
|
count,
|
||||||
1,
|
1,
|
||||||
ap->clientHeight / pixelsPer,
|
ap->clientHeight,
|
||||||
MIN(count, ap->clientHeight));
|
MIN(count, ap->clientHeight));
|
||||||
|
|
||||||
// TODO notify adjustment changes?
|
// TODO notify adjustment changes?
|
||||||
|
|
|
@ -10,20 +10,16 @@ struct handler {
|
||||||
static GtkWidget *area;
|
static GtkWidget *area;
|
||||||
static struct handler h;
|
static struct handler h;
|
||||||
static GtkWidget *nhspinb;
|
static GtkWidget *nhspinb;
|
||||||
static GtkWidget *pphspinb;
|
|
||||||
static GtkWidget *nvspinb;
|
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));
|
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
|
||||||
*pixelsPer = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pphspinb));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb));
|
||||||
*pixelsPer = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ppvspinb));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void recalcScroll(GtkSpinButton *sb, gpointer data)
|
static void recalcScroll(GtkSpinButton *sb, gpointer data)
|
||||||
|
@ -48,8 +44,8 @@ int main(void)
|
||||||
GtkWidget *scroller;
|
GtkWidget *scroller;
|
||||||
GtkWidget *grid;
|
GtkWidget *grid;
|
||||||
|
|
||||||
h.ah.HScrollConfig = handlerHScrollConfig;
|
h.ah.HScrollMax = handlerHScrollMax;
|
||||||
h.ah.VScrollConfig = handlerVScrollConfig;
|
h.ah.VScrollMax = handlerVScrollMax;
|
||||||
|
|
||||||
gtk_init(NULL, NULL);
|
gtk_init(NULL, NULL);
|
||||||
|
|
||||||
|
@ -80,26 +76,12 @@ int main(void)
|
||||||
gtk_grid_attach(GTK_GRID(grid), nhspinb,
|
gtk_grid_attach(GTK_GRID(grid), nhspinb,
|
||||||
1, 0, 1, 1);
|
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_grid_attach(GTK_GRID(grid),
|
||||||
gtk_label_new("V Count"),
|
gtk_label_new("V Count"),
|
||||||
0, 2, 1, 1);
|
0, 1, 1, 1);
|
||||||
nvspinb = makeSpinbox(0);
|
nvspinb = makeSpinbox(0);
|
||||||
gtk_grid_attach(GTK_GRID(grid), nvspinb,
|
gtk_grid_attach(GTK_GRID(grid), nvspinb,
|
||||||
1, 2, 1, 1);
|
1, 1, 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);
|
|
||||||
|
|
||||||
area = newArea((uiAreaHandler *) (&h));
|
area = newArea((uiAreaHandler *) (&h));
|
||||||
gtk_container_add(GTK_CONTAINER(scroller), area);
|
gtk_container_add(GTK_CONTAINER(scroller), area);
|
||||||
|
|
|
@ -6,8 +6,8 @@ typedef struct uiAreaDrawParams uiAreaDrawParams;
|
||||||
|
|
||||||
struct uiAreaHandler {
|
struct uiAreaHandler {
|
||||||
// TODO draw
|
// TODO draw
|
||||||
void (*HScrollConfig)(uiAreaHandler *, uiArea *, uintmax_t *, uintmax_t *);
|
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
|
||||||
void (*VScrollConfig)(uiAreaHandler *, uiArea *, uintmax_t *, uintmax_t *);
|
uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO uiAreaDrawParams
|
// TODO uiAreaDrawParams
|
||||||
|
|
Loading…
Reference in New Issue