choice5 [Re: patch for UI and font_factor]
"corvid" <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20110915201559.GE11600@local> |
I wrote: > - Choice5 does not handle it well. I made a nicer choice5 a few > months ago, but Jorge didn't like it. I looked around for the old patch and made it apply cleanly. It _is_ charmless, but maybe it can be used for raw materials at some point, since at least the text fits. So far as I can recall, I made it squarish because I was thinking that dealing with long narrow boxes on handhelds was probably suboptimal. (Speaking of which, remember how Andreas and Justus would talk about usability on handhelds, and then we didn't really proceed to make any decisions about anything? Has anyone tried dillo on handhelds of late?) _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
choice5.patch
(text/plain, 3.7 KB)
diff -r c65ce48b7ec9 src/dialog.cc
--- a/src/dialog.cc Wed Sep 14 21:33:51 2011 +0000
+++ b/src/dialog.cc Thu Sep 15 20:01:01 2011 +0000
@@ -302,7 +302,7 @@
/*
* Make a question-dialog with a question and up to five alternatives.
- * (if less alternatives, non used parameters must be NULL).
+ * (if fewer alternatives, unused parameters must be NULL).
*
* Return value: 0 = dialog was cancelled, 1-5 = selected alternative.
*/
@@ -312,56 +312,73 @@
{
choice5_answer = 0;
- int ww = 440, wh = 120, bw = 50, bh = 45, ih = 50, nb = 0;
- const char *txt[7];
+ const int gap = 10;
+ int ww, wh = 120, nb = 0, buttons_w = 0, y, box_h;
+ Fl_Button *buttons[5];
- txt[0] = txt[6] = NULL;
- txt[1] = alt1; txt[2] = alt2; txt[3] = alt3;
- txt[4] = alt4; txt[5] = alt5;
- for (int i=1; txt[i]; ++i, ++nb)
- ;
-
+ if (alt1) {
+ buttons[nb++] = new Fl_Button(0,0,0,0,alt1);
+ if (alt2) {
+ buttons[nb++] = new Fl_Button(0,0,0,0,alt2);
+ if (alt3) {
+ buttons[nb++] = new Fl_Button(0,0,0,0,alt3);
+ if (alt4) {
+ buttons[nb++] = new Fl_Button(0,0,0,0,alt4);
+ if (alt5) {
+ buttons[nb++] = new Fl_Button(0,0,0,0,alt5);
+ }
+ }
+ }
+ }
+ }
if (!nb) {
MSG_ERR("a_Dialog_choice5: No choices.\n");
return choice5_answer;
}
- ww = 140 + nb*(bw+10);
+ Fl_Group::current(0);
+ fl_font(FL_HELVETICA, 14);
+ for (int i=0; i < nb; ++i) {
+ Fl_Button *b = buttons[i];
+ int w = 0, h;
- Fl_Window *window = new Fl_Window(ww,wh,"Choice5");
+ b->labelfont(FL_HELVETICA);
+ b->labelsize(14);
+ fl_measure(b->label(), w, h, 0);
+ b->size(w + 10, h + 10);
+ buttons_w += b->w() + gap;
+ }
+ buttons_w += gap;
+
+ ww = MAX(240, buttons_w);
+
+ Fl_Window *window = new Fl_Window(ww, wh, "Dillo choice");
+ Fl_Group::current(0);
window->set_modal();
- window->begin();
- Fl_Group* ib = new Fl_Group(0,0,window->w(),window->h());
- ib->begin();
- window->resizable(ib);
- /* '?' Icon */
- Fl_Box* o = new Fl_Box(10, (wh-bh-ih)/2, ih, ih);
- o->box(FL_THIN_UP_BOX);
- o->labelfont(FL_TIMES_BOLD);
- o->labelsize(34);
- o->color(FL_WHITE);
- o->labelcolor(FL_BLUE);
- o->label("?");
- o->show();
+ y = gap;
+ int box_w = ww - 2 * gap;
+ Fl_Box *box = new Fl_Box(gap, y, box_w, wh-buttons[0]->h(), QuestionTxt);
+ box->labelfont(FL_HELVETICA);
+ box->labelsize(14);
+ box->align(FL_ALIGN_WRAP | FL_ALIGN_TOP_LEFT | FL_ALIGN_INSIDE);
+ fl_font(box->labelfont(), box->labelsize());
+ box_w -= 6; /* The label doesn't fill the entire box. */
+ fl_measure(QuestionTxt, box_w, box_h, 0);
+ box->size(box->w(), box_h);
+ window->add(box);
- Fl_Box *box = new Fl_Box(60,0,ww-60,wh-bh, QuestionTxt);
- box->labelfont(FL_HELVETICA);
- box->labelsize(14);
- box->align(FL_ALIGN_WRAP);
+ y += box_h + gap;
+ int x = ww - buttons_w + gap;
+ for (int i = 0; i < nb; i++) {
+ window->add(buttons[i]);
+ buttons[i]->position(x, y);
+ buttons[i]->callback(choice5_cb, INT2VOIDP(i + 1));
+ x += buttons[i]->w() + gap;
+ /* TODO: set focus to the *-prefixed alternative */
+ }
- Fl_Button *b;
- int xpos = 0, gap = 8;
- bw = (ww - gap)/nb - gap;
- xpos += gap;
- for (int i=1; i <= nb; ++i) {
- b = new Fl_Button(xpos, wh-bh, bw, bh, txt[i]);
- b->align(FL_ALIGN_WRAP|FL_ALIGN_CLIP);
- b->box(FL_UP_BOX);
- b->callback(choice5_cb, INT2VOIDP(i));
- xpos += bw + gap;
- /* TODO: set focus to the *-prefixed alternative */
- }
- window->end();
+ y += buttons[0]->h() + gap;
+ window->size(ww, y);
window->show();
while (window->shown())