Implemented the new fontbutton routines on GTK+.
This commit is contained in:
parent
cfa1b6bf0a
commit
e6effa042d
31
unix/draw.c
31
unix/draw.c
|
@ -538,12 +538,27 @@ static const PangoStretch pangoStretches[] = {
|
||||||
// TODO really see if there's a better way instead; what do GDK and GTK+ do internally? gdk_pango_context_get()?
|
// TODO really see if there's a better way instead; what do GDK and GTK+ do internally? gdk_pango_context_get()?
|
||||||
#define mkGenericPangoCairoContext() (pango_font_map_create_context(pango_cairo_font_map_get_default()))
|
#define mkGenericPangoCairoContext() (pango_font_map_create_context(pango_cairo_font_map_get_default()))
|
||||||
|
|
||||||
|
PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc)
|
||||||
|
{
|
||||||
|
PangoFont *f;
|
||||||
|
PangoContext *context;
|
||||||
|
|
||||||
|
// in this case, the context is necessary for the metrics to be correct
|
||||||
|
context = mkGenericPangoCairoContext();
|
||||||
|
f = pango_font_map_load_font(pango_cairo_font_map_get_default(), context, pdesc);
|
||||||
|
if (f == NULL) {
|
||||||
|
// TODO
|
||||||
|
g_error("[libui] no match in pangoDescToPangoFont(); report to andlabs");
|
||||||
|
}
|
||||||
|
g_object_unref(context);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc)
|
uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc)
|
||||||
{
|
{
|
||||||
PangoFont *f;
|
PangoFont *f;
|
||||||
PangoFontDescription *pdesc;
|
PangoFontDescription *pdesc;
|
||||||
//TODO PangoVariant variant;
|
//TODO PangoVariant variant;
|
||||||
PangoContext *context;
|
|
||||||
|
|
||||||
pdesc = pango_font_description_new();
|
pdesc = pango_font_description_new();
|
||||||
pango_font_description_set_family(pdesc,
|
pango_font_description_set_family(pdesc,
|
||||||
|
@ -563,17 +578,9 @@ TODO
|
||||||
#endif
|
#endif
|
||||||
pango_font_description_set_stretch(pdesc,
|
pango_font_description_set_stretch(pdesc,
|
||||||
pangoStretches[desc->Stretch]);
|
pangoStretches[desc->Stretch]);
|
||||||
|
f = pangoDescToPangoFont(pdesc);
|
||||||
// in this case, the context is necessary for the metrics to be correct
|
pango_font_description_free(pdesc);
|
||||||
context = mkGenericPangoCairoContext();
|
return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref
|
||||||
f = pango_font_map_load_font(pango_cairo_font_map_get_default(), context, pdesc);
|
|
||||||
if (f == NULL) {
|
|
||||||
// TODO
|
|
||||||
g_error("[libui] no match in uiDrawLoadClosestFont(); report to andlabs");
|
|
||||||
}
|
|
||||||
g_object_unref(context);
|
|
||||||
|
|
||||||
return mkTextFont(f, FALSE); // we hold the initial reference; no need to retain
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiDrawFreeTextFont(uiDrawTextFont *font)
|
void uiDrawFreeTextFont(uiDrawTextFont *font)
|
||||||
|
|
|
@ -7,6 +7,8 @@ struct uiFontButton {
|
||||||
GtkButton *button;
|
GtkButton *button;
|
||||||
GtkFontButton *fb;
|
GtkFontButton *fb;
|
||||||
GtkFontChooser *fc;
|
GtkFontChooser *fc;
|
||||||
|
void (*onChanged)(uiFontButton *, void *);
|
||||||
|
void *onChangedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiUnixDefineControl(
|
uiUnixDefineControl(
|
||||||
|
@ -19,25 +21,31 @@ static void onFontSet(GtkFontButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
uiFontButton *b = uiFontButton(data);
|
uiFontButton *b = uiFontButton(data);
|
||||||
|
|
||||||
//TODO (*(b->onClicked))(b, b->onClickedData);
|
(*(b->onChanged))(b, b->onChangedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
static void defaultOnChanged(uiFontButton *b, void *data)
|
||||||
TODO
|
|
||||||
static void defaultOnClicked(uiButton *b, void *data)
|
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
uiDrawTextFont *uiFontButtonFont(uiFontButton *b)
|
||||||
TODO
|
|
||||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
|
||||||
{
|
{
|
||||||
b->onClicked = f;
|
PangoFont *f;
|
||||||
b->onClickedData = data;
|
PangoFontDescription *desc;
|
||||||
|
|
||||||
|
desc = gtk_font_chooser_get_font_desc(b->fc);
|
||||||
|
f = pangoDescToPangoFont(desc);
|
||||||
|
// desc is transfer-full and thus is a copy
|
||||||
|
pango_font_description_free(desc);
|
||||||
|
return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data)
|
||||||
|
{
|
||||||
|
b->onChanged = f;
|
||||||
|
b->onChangedData = data;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
uiFontButton *uiNewFontButton(void)
|
uiFontButton *uiNewFontButton(void)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +67,7 @@ uiFontButton *uiNewFontButton(void)
|
||||||
gtk_font_chooser_set_show_preview_entry(b->fc, TRUE);
|
gtk_font_chooser_set_show_preview_entry(b->fc, TRUE);
|
||||||
|
|
||||||
g_signal_connect(b->widget, "font-set", G_CALLBACK(onFontSet), b);
|
g_signal_connect(b->widget, "font-set", G_CALLBACK(onFontSet), b);
|
||||||
//TODO uiButtonOnClicked(b, defaultOnClicked, NULL);
|
uiFontButtonOnChanged(b, defaultOnChanged, NULL);
|
||||||
|
|
||||||
uiUnixFinishNewControl(b, uiFontButton);
|
uiUnixFinishNewControl(b, uiFontButton);
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ extern void childSetMargined(struct child *c, int margined);
|
||||||
extern uiDrawContext *newContext(cairo_t *);
|
extern uiDrawContext *newContext(cairo_t *);
|
||||||
extern void freeContext(uiDrawContext *);
|
extern void freeContext(uiDrawContext *);
|
||||||
extern uiDrawTextFont *mkTextFont(PangoFont *f, gboolean add);
|
extern uiDrawTextFont *mkTextFont(PangoFont *f, gboolean add);
|
||||||
|
extern PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
#define uiControlQueueResize(...)
|
#define uiControlQueueResize(...)
|
||||||
|
|
Loading…
Reference in New Issue