; Module/File: LIG_ColumnSetFont.pb ; Function: Set the font of LIG-column (not in header) - Linux gtk2/gtk3 ; Author: Omi ; Date: Apr. 15, 2016 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.4 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" g_object_set(*object.GObject, property_name.p-utf8, *pdata, v= 0) g_object_set_double(*object, property.p-utf8, value.d, null= 0) As "g_object_set" g_type_check_instance_is_a(*instance.GTypeInstance, *type.GTypeClass) gtk_cell_layout_get_cells(*cell_layout) pango_font_description_from_string(str.p-utf8) EndImport ;Object constants #MainWin= 0 #LIG= 0 Enumeration PangoWeight #PANGO_WEIGHT_THIN = 100; Since: 1.24 #PANGO_WEIGHT_ULTRALIGHT= 200 #PANGO_WEIGHT_LIGHT = 300 #PANGO_WEIGHT_SEMILIGHT = 350; Since: 1.36.7 #PANGO_WEIGHT_BOOK = 380; Since: 1.24 #PANGO_WEIGHT_NORMAL = 400 #PANGO_WEIGHT_MEDIUM = 500; Since: 1.24 #PANGO_WEIGHT_SEMIBOLD = 600 #PANGO_WEIGHT_BOLD = 700 #PANGO_WEIGHT_ULTRABOLD = 800 #PANGO_WEIGHT_HEAVY = 900 #PANGO_WEIGHT_ULTRAHEAVY= 1000; Since: 1.24 EndEnumeration Global.i gEvent, gQuit Global *gProvider ;'FontDesc' can be "Monospace 10" with FontSize= 0, OR "Monospace" and FontSize= SetToPoints ;'FontWeight'= 0 isn't setwise set a PangoWeight constant Procedure TreeView_SetColumnFont(Gadget, Colmn, FontDesc.s, FontSize.d, FontWeight) Protected.GtkTreeViewColumn *Column Protected.GtkCellRenderer *CellRenderers, *CellRenderer Protected.l Count, Index *Column = gtk_tree_view_get_column_(GadgetID(Gadget), Colmn) If *Column ;Header must be converted to a Button in gtk3 to change font! In the following (simpler) way, this isn't possible! *CellRenderers= gtk_cell_layout_get_cells(*Column) If *CellRenderers Count= g_list_length_(*CellRenderers); number of renderers For Index= 0 To Count-1 *CellRenderer= g_list_nth_data_(*CellRenderers, Index) If g_type_check_instance_is_a(*CellRenderer, gtk_cell_renderer_text_get_type_()); only GtkCellRendererText g_object_set(*CellRenderer, "font-desc", pango_font_description_from_string(FontDesc)) If FontSize : g_object_set_double(*CellRenderer, "size-points", FontSize) : EndIf If FontWeight : g_object_set(*CellRenderer, "weight", FontWeight) : EndIf EndIf Next Index g_list_free_(*CellRenderers) EndIf ; gtk_widget_queue_draw_(GadgetID(Gadget)); force Redraw EndIf EndProcedure Procedure CreateWindow_Main() Protected.i I, O If OpenWindow(#MainWin, 200, 200, 400, 400, "LIG - column font", #PB_Window_SystemMenu) ListIconGadget(#LIG, 5, 5, 390, 390, "column 0", 74, #PB_ListIcon_GridLines) For O= 1 To 4 AddGadgetColumn(#LIG, O, "column " + Str(O), 74) Next O For I= 0 To 19 AddGadgetItem(#LIG, -1, Str(I) + "-0") For O= 1 To 4 SetGadgetItemText(#LIG, I, Str(I) + "-" + Str(O), O) Next O Next I EndIf EndProcedure CreateWindow_Main() TreeView_SetColumnFont(#LIG, 0, "Monospace", 11.0, #PANGO_WEIGHT_BOLD) TreeView_SetColumnFont(#LIG, 1, "Sans", 9, #PANGO_WEIGHT_LIGHT) TreeView_SetColumnFont(#LIG, 2, "Serif 11", 0, 0) TreeView_SetColumnFont(#LIG, 3, "Courier New", 11, 0) TreeView_SetColumnFont(#LIG, 4, "Andale Mono 10", 0, 0) Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect Until gQuit ; IDE Options = PureBasic 5.45 LTS (Linux - x86) ; CursorPosition = 3 ; Folding = - ; EnableUnicode ; EnableXP