static void update_constraints(glw_expander_t *exp) { glw_t *c = TAILQ_FIRST(&exp->w.glw_childs); int e, o; int f = c ? glw_filter_constraints(c->glw_flags) : 0; if(exp->w.glw_class == &glw_expander_x) { e = exp->expansion * (c != NULL ? c->glw_req_size_x : 0); o = (c != NULL ? c->glw_req_size_y : 0); f &= GLW_CONSTRAINT_Y; } else { e = exp->expansion * (c != NULL ? c->glw_req_size_y : 0); o = (c != NULL ? c->glw_req_size_x : 0); f &= GLW_CONSTRAINT_X; } if(e == 0) glw_focus_close_path(&exp->w); else if(exp->w.glw_flags & GLW_FOCUS_BLOCKED) glw_focus_open_path(&exp->w); if(exp->w.glw_class == &glw_expander_x) glw_set_constraints(&exp->w, e, o, 0, GLW_CONSTRAINT_X | f, 0); else glw_set_constraints(&exp->w, o, e, 0, GLW_CONSTRAINT_Y | f, 0); }
static int glw_slider_callback(glw_t *w, void *opaque, glw_signal_t signal, void *extra) { glw_slider_t *s = (glw_slider_t *)w; glw_t *c; switch(signal) { case GLW_SIGNAL_DESTROY: slider_unbind(s); break; case GLW_SIGNAL_CHILD_CONSTRAINTS_CHANGED: c = extra; if(w->glw_class == &glw_slider_y) { glw_set_constraints(w, c->glw_req_size_x, 0, 0, GLW_CONSTRAINT_X); } else { glw_set_constraints(w, 0, c->glw_req_size_y, 0, GLW_CONSTRAINT_Y); } return 1; default: break; } return 0; }
static void glw_image_update_constraints(glw_image_t *gi) { glw_loadable_texture_t *glt = gi->gi_current; glw_t *c; glw_root_t *gr = gi->w.glw_root; if(gi->gi_bitmap_flags & GLW_IMAGE_FIXED_SIZE) { glw_set_constraints(&gi->w, glt->glt_xs, glt->glt_ys, 0, GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y, 0); } else if(gi->w.glw_class == &glw_backdrop) { c = TAILQ_FIRST(&gi->w.glw_childs); if(c != NULL) { glw_set_constraints(&gi->w, c->glw_req_size_x + gi->gi_box_left + gi->gi_box_right, c->glw_req_size_y + gi->gi_box_top + gi->gi_box_bottom, c->glw_req_weight, c->glw_flags & GLW_CONSTRAINT_FLAGS, 0); } else if(glt != NULL) { glw_set_constraints(&gi->w, glt->glt_xs, glt->glt_ys, 0, 0, 0); } } else if(gi->w.glw_class == &glw_icon) { float siz = gi->gi_size_scale * gr->gr_fontsize; glw_set_constraints(&gi->w, siz, siz, 0, GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y, 0); } else if(gi->w.glw_class == &glw_image && glt != NULL && gi->gi_bitmap_flags & GLW_IMAGE_SET_ASPECT) { float aspect = (float)glt->glt_xs / glt->glt_ys; glw_set_constraints(&gi->w, 0, 0, -aspect, GLW_CONSTRAINT_W, 0); } }
static int glw_image_callback(glw_t *w, void *opaque, glw_signal_t signal, void *extra) { glw_t *c; switch(signal) { default: break; case GLW_SIGNAL_LAYOUT: glw_image_layout(w, extra); break; case GLW_SIGNAL_EVENT: TAILQ_FOREACH(c, &w->glw_childs, glw_parent_link) if(glw_signal0(c, GLW_SIGNAL_EVENT, extra)) return 1; break; case GLW_SIGNAL_CHILD_CONSTRAINTS_CHANGED: case GLW_SIGNAL_CHILD_CREATED: glw_image_update_constraints((glw_image_t *)w); return 1; case GLW_SIGNAL_CHILD_DESTROYED: glw_set_constraints(w, 0, 0, 0, 0); return 1; } return 0; }
/** * Only for icon class */ static void set_size_scale(glw_t *w, float f) { glw_image_t *gi = (glw_image_t *)w; gi->gi_size_scale = f; float siz = gi->gi_size_scale * w->glw_root->gr_fontsize; glw_set_constraints(w, siz, siz, 0, GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y, 0); }
static void glw_icon_ctor(glw_t *w) { glw_image_ctor(w); glw_image_t *gi = (glw_image_t *)w; glw_root_t *gr = w->glw_root; float siz = w->glw_root->gr_current_size; glw_set_constraints(w, siz, siz, 0, GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y); LIST_INSERT_HEAD(&gr->gr_icons, gi, gi_link); }
static void thaw(glw_t *w) { glw_text_bitmap_t *gtb = (glw_text_bitmap_t *)w; gtb->gtb_frozen = 0; if(!(gtb->w.glw_flags & GLW_CONSTRAINT_Y)) { int lh = (gtb->gtb_default_size ?: w->glw_root->gr_current_size) * gtb->gtb_size_scale; int ys = gtb->gtb_padding[1] + gtb->gtb_padding[3] + lh; glw_set_constraints(>b->w, 0, ys, 0, GLW_CONSTRAINT_Y); }
static int glw_slider_callback(glw_t *w, void *opaque, glw_signal_t signal, void *extra) { glw_slider_t *s = (glw_slider_t *)w; glw_t *c; switch(signal) { case GLW_SIGNAL_LAYOUT: glw_slider_layout(w, extra); break; case GLW_SIGNAL_EVENT: if(w->glw_class == &glw_slider_x) return glw_slider_event_x(w, extra); else return glw_slider_event_y(w, extra); case GLW_SIGNAL_POINTER_EVENT: return pointer_event(w, extra); case GLW_SIGNAL_DESTROY: slider_unbind(s); break; case GLW_SIGNAL_CHILD_CONSTRAINTS_CHANGED: c = extra; if(w->glw_class == &glw_slider_y) { glw_set_constraints(w, c->glw_req_size_x, 0, 0, GLW_CONSTRAINT_X); } else { glw_set_constraints(w, 0, c->glw_req_size_y, 0, GLW_CONSTRAINT_Y); } return 1; default: break; } return 0; }
static void glw_image_update_constraints(glw_image_t *gi) { glw_loadable_texture_t *glt = gi->gi_current; glw_t *c; if(gi->gi_bitmap_flags & GLW_IMAGE_FIXED_SIZE) { glw_set_constraints(&gi->w, glt->glt_xs, glt->glt_ys, 0, GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y); } else if(gi->w.glw_class == &glw_backdrop || gi->w.glw_class == &glw_frontdrop) { c = TAILQ_FIRST(&gi->w.glw_childs); if(c != NULL) { glw_set_constraints(&gi->w, c->glw_req_size_x + gi->gi_box_left + gi->gi_box_right, c->glw_req_size_y + gi->gi_box_top + gi->gi_box_bottom, c->glw_req_weight, c->glw_flags & GLW_CONSTRAINT_FLAGS); if(gi->w.glw_flags2 & GLW2_AUTOMARGIN) gi->gi_update = 1; if(gi->w.glw_flags & GLW_DEBUG) printf("Req size: %d,%d\n", c->glw_req_size_x, c->glw_req_size_y); } else if(glt != NULL) { glw_set_constraints(&gi->w, glt->glt_xs, glt->glt_ys, 0, 0); } } else if(gi->w.glw_class == &glw_image && glt != NULL) { float aspect = (float)glt->glt_xs / glt->glt_ys; if(gi->gi_bitmap_flags & GLW_IMAGE_SET_ASPECT) { glw_set_constraints(&gi->w, 0, 0, -aspect, GLW_CONSTRAINT_W); } else if(gi->w.glw_flags & GLW_CONSTRAINT_CONF_X) { int ys = gi->w.glw_req_size_x / aspect; glw_set_constraints(&gi->w, 0, ys, 0, GLW_CONSTRAINT_Y); } else if(gi->w.glw_flags & GLW_CONSTRAINT_CONF_Y) { int xs = gi->w.glw_req_size_y * aspect; glw_set_constraints(&gi->w, xs, 0, 0, GLW_CONSTRAINT_X); } } }
static void gtb_set_constraints(glw_root_t *gr, glw_text_bitmap_t *gtb, const pixmap_t *pm) { int flags = GLW_CONSTRAINT_Y; #if 0 int lines = pm && pm->pm_lines ? pm->pm_lines : 1; int ys = gtb->gtb_padding_top + gtb->gtb_padding_bottom; int xs = gtb->gtb_padding_left + gtb->gtb_padding_right; int lh = (gtb->gtb_default_size ?: gr->gr_fontsize) * gtb->gtb_size_scale; int height = lh * lines; height = MAX(pm ? pm->pm_height - pm->pm_margin*2: 0, height); ys += height; if(pm != NULL) xs += pm->pm_width - pm->pm_margin*2; if(xs > 0 && gtb->gtb_maxlines == 1) flags |= GLW_CONSTRAINT_X; #else int xs = pm->pm_width - pm->pm_margin*2 + gtb->gtb_padding_left + gtb->gtb_padding_right; int ys = pm->pm_height - pm->pm_margin*2 + gtb->gtb_padding_top + gtb->gtb_padding_bottom; if(gtb->gtb_maxlines == 1 && !(gtb->gtb_flags & GTB_ELLIPSIZE)) flags |= GLW_CONSTRAINT_X; #endif if(gtb->w.glw_flags & GLW_DEBUG) printf("Constraints %c%c %d,%d\n", flags & GLW_CONSTRAINT_X ? 'X' : ' ', flags & GLW_CONSTRAINT_Y ? 'Y' : ' ', xs, ys); glw_set_constraints(>b->w, xs, ys, 0, flags); }
static void gtb_recompute_constraints_after_padding_change(glw_text_bitmap_t *gtb, const int16_t oldpad[4]) { glw_t *w = >b->w; int flags = w->glw_flags & (GLW_CONSTRAINT_Y | GLW_CONSTRAINT_X); if(flags == 0) return; const int xs = w->glw_req_size_x - oldpad[0] - oldpad[2] + gtb->gtb_padding[0] + gtb->gtb_padding[2]; const int ys = w->glw_req_size_y - oldpad[1] - oldpad[3] + gtb->gtb_padding[1] + gtb->gtb_padding[3]; if(gtb->w.glw_flags2 & GLW2_DEBUG) printf("Constraints %c%c %d,%d (padding changed)\n", flags & GLW_CONSTRAINT_X ? 'X' : ' ', flags & GLW_CONSTRAINT_Y ? 'Y' : ' ', xs, ys); glw_set_constraints(w, xs, ys, 0, flags); }
static void gtb_set_constraints(glw_root_t *gr, glw_text_bitmap_t *gtb, const image_t *im) { int flags = GLW_CONSTRAINT_Y; const int xs = im->im_width - im->im_margin * 2 + gtb->gtb_padding[0] + gtb->gtb_padding[2]; const int ys = im->im_height - im->im_margin * 2 + gtb->gtb_padding[1] + gtb->gtb_padding[3]; if(gtb->gtb_maxlines == 1 && !(gtb->gtb_flags & GTB_ELLIPSIZE)) flags |= GLW_CONSTRAINT_X; if(gtb->w.glw_flags2 & GLW2_DEBUG) printf("Textbitmap constraints %c%c %d,%d\n", flags & GLW_CONSTRAINT_X ? 'X' : ' ', flags & GLW_CONSTRAINT_Y ? 'Y' : ' ', xs, ys); glw_set_constraints(>b->w, xs, ys, 0, flags); }
static void glw_segway_layout(glw_t *w, const glw_rctx_t *rc) { glw_segway_t *s = (glw_segway_t *)w; glw_t *c; if((c = TAILQ_FIRST(&w->glw_childs)) == NULL) return; s->req_width = 0; int f = glw_filter_constraints(c); if(f & GLW_CONSTRAINT_X) { s->req_width = glw_req_width(c); } else if(f & GLW_CONSTRAINT_W && c->glw_req_weight < 0) { s->req_width = rc->rc_height * -c->glw_req_weight; } glw_rctx_t rc0 = *rc; float alpha; if(s->req_width == 0 || !s->direction) { rc0.rc_width = w->glw_root->gr_width; rc0.rc_segwayed = 1; alpha = 0; } else { rc0.rc_width = s->req_width; alpha = 1; } glw_lp(&s->alpha, w->glw_root, alpha, 0.25); glw_lp(&s->actual_width, w->glw_root, s->req_width, 0.25); s->actual_width_rounded = rintf(s->actual_width); rc0.rc_alpha *= s->alpha; glw_layout0(c, &rc0); glw_set_constraints(w, s->actual_width_rounded, 0, 0, GLW_CONSTRAINT_X); }
static void glw_segway_ctor(glw_t *w) { glw_set_constraints(w, 0, 0, 0, GLW_CONSTRAINT_X); }
static void set_weight(glw_t *w, float v) { glw_set_constraints(w, 0, 0, v, GLW_CONSTRAINT_W, GLW_CONSTRAINT_CONF_W); }
static void set_width(glw_t *w, int v) { glw_set_constraints(w, v, 0, 0, GLW_CONSTRAINT_X, GLW_CONSTRAINT_CONF_X); }
static void set_height(glw_t *w, int v) { glw_set_constraints(w, 0, v, 0, GLW_CONSTRAINT_Y, GLW_CONSTRAINT_CONF_Y); }