Implemented the new fontbutton routines on GTK+.

This commit is contained in:
Pietro Gagliardi 2016-04-20 13:59:59 -04:00
parent cfa1b6bf0a
commit e6effa042d
3 changed files with 40 additions and 24 deletions

View File

@ -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()?
#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)
{
PangoFont *f;
PangoFontDescription *pdesc;
//TODO PangoVariant variant;
PangoContext *context;
pdesc = pango_font_description_new();
pango_font_description_set_family(pdesc,
@ -563,17 +578,9 @@ TODO
#endif
pango_font_description_set_stretch(pdesc,
pangoStretches[desc->Stretch]);
// 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 uiDrawLoadClosestFont(); report to andlabs");
}
g_object_unref(context);
return mkTextFont(f, FALSE); // we hold the initial reference; no need to retain
f = pangoDescToPangoFont(pdesc);
pango_font_description_free(pdesc);
return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref
}
void uiDrawFreeTextFont(uiDrawTextFont *font)

View File

@ -7,6 +7,8 @@ struct uiFontButton {
GtkButton *button;
GtkFontButton *fb;
GtkFontChooser *fc;
void (*onChanged)(uiFontButton *, void *);
void *onChangedData;
};
uiUnixDefineControl(
@ -19,25 +21,31 @@ static void onFontSet(GtkFontButton *button, gpointer data)
{
uiFontButton *b = uiFontButton(data);
//TODO (*(b->onClicked))(b, b->onClickedData);
(*(b->onChanged))(b, b->onChangedData);
}
#if 0
TODO
static void defaultOnClicked(uiButton *b, void *data)
static void defaultOnChanged(uiFontButton *b, void *data)
{
// do nothing
}
#endif
#if 0
TODO
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
uiDrawTextFont *uiFontButtonFont(uiFontButton *b)
{
b->onClicked = f;
b->onClickedData = data;
PangoFont *f;
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)
{
@ -59,7 +67,7 @@ uiFontButton *uiNewFontButton(void)
gtk_font_chooser_set_show_preview_entry(b->fc, TRUE);
g_signal_connect(b->widget, "font-set", G_CALLBACK(onFontSet), b);
//TODO uiButtonOnClicked(b, defaultOnClicked, NULL);
uiFontButtonOnChanged(b, defaultOnChanged, NULL);
uiUnixFinishNewControl(b, uiFontButton);

View File

@ -45,6 +45,7 @@ extern void childSetMargined(struct child *c, int margined);
extern uiDrawContext *newContext(cairo_t *);
extern void freeContext(uiDrawContext *);
extern uiDrawTextFont *mkTextFont(PangoFont *f, gboolean add);
extern PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc);
// TODO
#define uiControlQueueResize(...)