2022-12-11 21:18:06 +03:00
|
|
|
|
//
|
|
|
|
|
// Unit tests for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
|
|
|
|
// Copyright 1998-2022 by Bill Spitzak and others.
|
|
|
|
|
//
|
|
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
|
//
|
|
|
|
|
// https://www.fltk.org/COPYING.php
|
|
|
|
|
//
|
|
|
|
|
// Please see the following page on how to report bugs and issues:
|
|
|
|
|
//
|
|
|
|
|
// https://www.fltk.org/bugs.php
|
|
|
|
|
//
|
|
|
|
|
|
2022-12-11 22:00:08 +03:00
|
|
|
|
// FLTK DEVS: utf-8 encoding must be enabled to edit this file.
|
|
|
|
|
|
2022-12-11 21:18:06 +03:00
|
|
|
|
#include "unittests.h"
|
|
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
|
#include <FL/Fl_Text_Display.H>
|
|
|
|
|
#include <FL/Fl_Multiline_Input.H>
|
|
|
|
|
#include <FL/Fl_Choice.H>
|
|
|
|
|
#include <FL/Fl_Hor_Value_Slider.H>
|
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
|
2022-12-11 22:00:08 +03:00
|
|
|
|
static const char *utf8_box_test =
|
|
|
|
|
"╳╳ ██ ▏▏┏━━┓ ╔══╗ ╔═╦═╗ ██████\n"
|
|
|
|
|
"╳╳ ██ ▏▏┃ ┃ ║ ║ ╠═╬═╣ ██ ██\n"
|
|
|
|
|
"╳╳ ██ ▏▏┗━━┛ ╚══╝ ╚═╩═╝ ██████\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"underbar: ______\n"
|
|
|
|
|
" overbar: ‾‾‾‾‾‾\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"underbar/overbar alternate:\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"___‾‾‾___‾‾‾___‾‾‾___‾‾‾___\n"
|
|
|
|
|
"‾‾‾___‾‾‾___‾‾‾___‾‾‾___‾‾‾\n";
|
|
|
|
|
|
2022-12-11 21:18:06 +03:00
|
|
|
|
static const char *helptext =
|
|
|
|
|
"In this test, ideally the box's lines should all be touching "
|
|
|
|
|
"without white space between. Underbar and overbars should both "
|
|
|
|
|
"be visible and not touching. All the above should be unaffected "
|
|
|
|
|
"by different font sizes and font settings.";
|
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
|
class Ut_Unicode_Box_Test : public Fl_Group {
|
2022-12-11 21:18:06 +03:00
|
|
|
|
Fl_Text_Buffer *textbuffer;
|
|
|
|
|
Fl_Text_Display *textdisplay;
|
|
|
|
|
Fl_Multiline_Input *multilineinput;
|
|
|
|
|
Fl_Choice *font_choice;
|
|
|
|
|
Fl_Hor_Value_Slider *fontsize_slider;
|
|
|
|
|
|
|
|
|
|
// Font choice callback
|
2022-12-17 15:16:57 +03:00
|
|
|
|
void font_choice_cb2() {
|
2022-12-11 21:18:06 +03:00
|
|
|
|
switch ( font_choice->value() ) {
|
|
|
|
|
case 0: textdisplay->textfont(FL_COURIER); break;
|
|
|
|
|
case 1: textdisplay->textfont(FL_SCREEN); break;
|
|
|
|
|
}
|
|
|
|
|
parent()->redraw();
|
|
|
|
|
}
|
2022-12-17 15:16:57 +03:00
|
|
|
|
static void foant_choice_cb(Fl_Widget*, void *userdata) {
|
|
|
|
|
Ut_Unicode_Box_Test *o = (Ut_Unicode_Box_Test*)userdata;
|
|
|
|
|
o->font_choice_cb2();
|
2022-12-11 21:18:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Slider callback - apply new font size to widgets
|
2022-12-17 15:16:57 +03:00
|
|
|
|
void font_size_slider_cb2() {
|
2022-12-11 21:18:06 +03:00
|
|
|
|
// Get font size from slider value, apply to widgets
|
|
|
|
|
int fontsize = (int)fontsize_slider->value();
|
|
|
|
|
textdisplay->textsize(fontsize);
|
|
|
|
|
multilineinput->textsize(fontsize);
|
2023-02-02 22:54:19 +03:00
|
|
|
|
multilineinput->insert_position(0); // keep scrolled to top
|
2022-12-11 21:18:06 +03:00
|
|
|
|
parent()->redraw();
|
|
|
|
|
}
|
2022-12-17 15:16:57 +03:00
|
|
|
|
static void font_size_slider_cb(Fl_Widget*, void *userdata) {
|
|
|
|
|
Ut_Unicode_Box_Test *o = (Ut_Unicode_Box_Test*)userdata;
|
|
|
|
|
o->font_size_slider_cb2();
|
2022-12-11 21:18:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static Fl_Widget *create() {
|
2022-12-17 15:16:57 +03:00
|
|
|
|
return new Ut_Unicode_Box_Test(UT_TESTAREA_X, UT_TESTAREA_Y, UT_TESTAREA_W, UT_TESTAREA_H);
|
2022-12-11 21:18:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
|
Ut_Unicode_Box_Test(int x, int y, int w, int h) : Fl_Group(x, y, w, h) {
|
2022-12-11 21:18:06 +03:00
|
|
|
|
// Fl_Text_Display
|
|
|
|
|
textbuffer = new Fl_Text_Buffer();
|
|
|
|
|
textbuffer->text(utf8_box_test);
|
|
|
|
|
textdisplay = new Fl_Text_Display(x+5, y+20, 250, 250, "Fl_Text_Display");
|
|
|
|
|
textdisplay->textfont(FL_COURIER);
|
|
|
|
|
textdisplay->buffer(textbuffer);
|
|
|
|
|
textdisplay->tooltip(helptext);
|
|
|
|
|
// Fl_Multiline_Input
|
|
|
|
|
multilineinput = new Fl_Multiline_Input(x+250+15, y+20, 250, 250, "Fl_Multiline_Input");
|
|
|
|
|
multilineinput->align(FL_ALIGN_CENTER|FL_ALIGN_TOP);
|
|
|
|
|
multilineinput->textfont(FL_COURIER);
|
|
|
|
|
multilineinput->value(utf8_box_test);
|
|
|
|
|
multilineinput->tooltip(helptext);
|
|
|
|
|
// Font choice
|
|
|
|
|
// Fonts must be fixed width to work correctly..
|
|
|
|
|
font_choice = new Fl_Choice(x+150, y+h-80, 200, 25, "Font face");
|
|
|
|
|
font_choice->add("FL_COURIER");
|
|
|
|
|
font_choice->add("FL_SCREEN");
|
|
|
|
|
font_choice->value(0);
|
2022-12-17 15:16:57 +03:00
|
|
|
|
font_choice->callback(foant_choice_cb, (Fl_Widget*)this);
|
2022-12-11 21:18:06 +03:00
|
|
|
|
// Font size slider
|
|
|
|
|
fontsize_slider = new Fl_Hor_Value_Slider(x+150, y+h-50, 200, 25, "Font size");
|
|
|
|
|
fontsize_slider->align(FL_ALIGN_LEFT);
|
|
|
|
|
fontsize_slider->range(1.0, 50.0);
|
|
|
|
|
fontsize_slider->step(1.0);
|
|
|
|
|
fontsize_slider->value(14.0);
|
2022-12-17 15:16:57 +03:00
|
|
|
|
fontsize_slider->callback(font_size_slider_cb, (Fl_Widget*)this);
|
2022-12-11 21:18:06 +03:00
|
|
|
|
end();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-17 15:16:57 +03:00
|
|
|
|
UnitTest unicode_font_test(UT_TEST_UNICODE, "Unicode Boxes", Ut_Unicode_Box_Test::create);
|