i_basic_font_size - resizing of text, when the window resizes
When a window resizes often it is desired that the text sizes follow
the window size. To realise that it is necessary to know the origin
size of font and window to scale the font to current size. The class
i_basic_font_size controls these values and when added to a window
it control the resizing of text.
To get the automatic functionality it is necessar to derive from a
window class and overwrite the virtual resize() method, for call of
i_basic_font_size when resizing:
#include <FL/Fl_Double_Window.H>
#include <f_font_size.h>
class Fl_Font_Window:
public Fl_Double_Window,
// Use your favoured window type, e.g. Fl_Window,
Fl_Overlay_Window
public
f_font_size::i_basic_font_size // Basic
font and size settings
{
public:
Fl_Font_Window(int x, int y,
int w, int h, const char* label= 0):
Fl_Double_Window(x, y, w, h, label),
i_basic_font_size(w, h), // Remember origin values
m_Resize_Text(true)
{}
Fl_Font_Window(int w, int h,
const char* label= 0):
Fl_Double_Window(w, h, label),
i_basic_font_size(w, h), // Remember origin values
m_Resize_Text(true)
{}
virtual ~Fl_Font_Window() {}
// Activate/ Deactivate
resizing of text:
inline void Resize_Text(bool
An) { m_Resize_Text= An; }
inline bool Resize_Text()
const { return
m_Resize_Text; }
// virtual method of
Fl_Double_Window. overwrite for resize of fonts:
virtual void resize(int px,
int py, int pw, int ph)
{ //
Callback, when window is resized, resize fonts now
Fl_Double_Window::resize(px, py, pw, ph); //
Resize window
m_wn=
pw;
// Remember size
m_hn= ph;
if
(m_Resize_Text) Resize(this, pw,
ph); // Resize text
}
private:
bool
m_Resize_Text; // Current mode
};
Now this class can be used like a standard window class:
Fl_Font_Window
Wnd(400, 200, "Font Window");
new Fl_Box(20, 20, 100, 25, "Hello World");
Wnd.end();
Wnd.resizable(Wnd);
Wnd.show();
return Fl::run();
Also it can be used to add resizing to
fluid windows.
The example code uses this inside of fluid class Fl_Example.
[ index ] [ i_local_font_size ] [ i_font_size ]