Column alignment in ListIconGadget
Column alignment in ListIconGadget
An optional parameter in the AddGadgetColumn command for individual coulmn alignment, cross-platform enabled.
This is quite commonly used since certain texts are more professionally presented when right-justified, for example prices range from $1.00 to $1,000.50 or quantity range from 0 to like 1000, or whatever large number.
Something similar to the TextGadget like:
#PB_Text_Center : The text is centered in the gadget.
#PB_Text_Right : The text is right aligned.
This is quite commonly used since certain texts are more professionally presented when right-justified, for example prices range from $1.00 to $1,000.50 or quantity range from 0 to like 1000, or whatever large number.
Something similar to the TextGadget like:
#PB_Text_Center : The text is centered in the gadget.
#PB_Text_Right : The text is right aligned.
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Column alignment in ListIconGadget
+1
Just hit this in my current project. Mostly, my values have the same number of digits so it does not look too bad but right-justify would be a great option.
Just hit this in my current project. Mostly, my values have the same number of digits so it does not look too bad but right-justify would be a great option.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Column alignment in ListIconGadget
+2
i was also looking for this 'simple' feature
i was also looking for this 'simple' feature
PureBasic 4.51(x86) on WinXP SP3
Re: Column alignment in ListIconGadget
+1
I requested the same thing awhile back with a slightly different implementation but ultimately the same goal:
http://www.purebasic.fr/english/viewtop ... =alignment
I requested the same thing awhile back with a slightly different implementation but ultimately the same goal:
http://www.purebasic.fr/english/viewtop ... =alignment
Re: Column alignment in ListIconGadget
I was just able to present a cross-platform solution for Windows,
Linux and MacOS X:
http://www.purebasic.fr/english/viewtop ... 31&start=8
Linux and MacOS X:
http://www.purebasic.fr/english/viewtop ... 31&start=8
- Michael Vogel
- Addict
- Posts: 2680
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Column alignment in ListIconGadget
To define the alignment by using PB internal commands would be fine, this would need to allow to use flags for both gadget command, AddGadgetColumn and ListIconGadget...
Code: Select all
ListIconGadget(0, 10, 25, 300, 70, "Column 1", 100,#PB_Text_Center)
AddGadgetColumn(0, 1, "Address", 250,#PB_Text_Right)
Re: Column alignment in ListIconGadget
I use the good Shardik's code http://www.purebasic.fr/english/viewtop ... 22#p410422 (Tue Feb 21, 2012 22:37), but I agree.
It would be fine to have a column alignment in ListIconGadget.
It would be fine to have a column alignment in ListIconGadget.
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
Re: Column alignment in ListIconGadget
+1 for native Text alignment in individual columns in ListIconGadget.
DE AA EB
- zxtunes.com
- Enthusiast
- Posts: 375
- Joined: Wed Apr 23, 2008 7:51 am
- Location: Saint-Petersburg, Russia
- Contact:
Re: Column alignment in ListIconGadget
Fred, It's time to go !
Re: Column alignment in ListIconGadget
+100
In my case I use that forum snippet, but I have no idea how it works and if it correct - but it works on Windows and Mac OS:
And don't forget the ColumnHeaderClick-Event!!! If you want to implement a sortable list (a list without sorting possibility is no list), then you need the ColumnHeaderClick-Event. There are some OS-specific workarounds here in the forum, but it would be nice to have some basic functionalities build in PureBasic. Thanks!
In my case I use that forum snippet, but I have no idea how it works and if it correct - but it works on Windows and Mac OS:
Code: Select all
Procedure SetListIconColumnAlignment(ListIconID.i, ColumnIndex.i, Alignment.i)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Protected Aligment.LV_COLUMN
Aligment\mask = #LVCF_FMT
Aligment\fmt = Alignment
SendMessage_(GadgetID(ListIconID), #LVM_SETCOLUMN, ColumnIndex, @Aligment)
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
Protected ColumnHeaderCell.i
Protected ColumnObject.i
Protected ColumnObjectArray.i
CocoaMessage(@ColumnObjectArray, GadgetID(ListIconID), "tableColumns")
CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", ColumnIndex)
CocoaMessage(0, CocoaMessage(0, ColumnObject, "dataCell"), "setAlignment:", Alignment)
CocoaMessage(@ColumnHeaderCell, ColumnObject, "headerCell")
CocoaMessage(0, ColumnHeaderCell, "setAlignment:", Alignment)
CompilerEndIf
EndProcedure
Re: Column alignment in ListIconGadget
+1
My two cents
My two cents
Code: Select all
; Windows Ok
; Linux Ok but #PB_ListIcon_TextItemAutoSize
; Mac OS no tested
DeclareModule ListIconText
EnableExplicit
#PB_ListIcon_TextLeft = 1<<1
#PB_ListIcon_TextCenter = 1<<2
#PB_ListIcon_TextRight = 1<<3
#PB_ListIcon_TextItemAutoSize = 1<<4
#PB_ListIcon_TextColumnAutoSize = 1<<5
Declare Alignment(Gadget, Column, Alignment)
EndDeclareModule
Module ListIconText
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux ;- OS_Linux
ImportC ""
g_object_set_double(*Object, Property.p-ascii, Value.D, Null) As "g_object_set"
gtk_cell_layout_get_cells(*cell_layout)
gtk_tree_view_column_set_alignment(*tree_column, xalign.f); replaced PureBasic's V5.* buggy: gtk_tree_view_column_set_alignment_(*Column, Alignment)
EndImport
ProcedureC Alignment(Gadget, Column, Alignment)
Protected AlignmentFactor.D
Protected *CellRenderers
Protected *Column
Protected Count
Protected i
If ((Alignment & #PB_ListIcon_TextLeft) = #PB_ListIcon_TextLeft)
AlignmentFactor = 0.0
ElseIf ((Alignment & #PB_ListIcon_TextCenter) = #PB_ListIcon_TextCenter)
AlignmentFactor = 0.5
ElseIf ((Alignment & #PB_ListIcon_TextRight) = #PB_ListIcon_TextRight)
AlignmentFactor = 1.0
EndIf
*Column = gtk_tree_view_get_column_(GadgetID(Gadget), Column)
If *Column
;gtk_tree_view_column_set_alignment_(*Column, AlignmentFactor) ; bug
gtk_tree_view_column_set_alignment(*Column, AlignmentFactor); title-alignment - fixed with ImportC
If ((Alignment & #PB_ListIcon_TextColumnAutoSize) = #PB_ListIcon_TextColumnAutoSize)
gtk_tree_view_column_set_sizing_(*Column, #GTK_TREE_VIEW_COLUMN_AUTOSIZE)
EndIf
; *CellRenderers = gtk_tree_view_column_get_cell_renderers_(*Column)
*CellRenderers = gtk_cell_layout_get_cells(*Column)
If *CellRenderers
Count = g_list_length_(*CellRenderers) ; number of columns
For i = 0 To Count - 1
;g_object_set_double(g_list_nth_data_(*CellRenderers, i), "xalign", AlignmentFactor, #Null)
Protected *Cellule.GtkCellRenderer = g_list_nth_data_(*CellRenderers, i) : *Cellule\xalign=AlignmentFactor
Next i
g_list_free_(*CellRenderers)
EndIf
gtk_widget_queue_draw_(GadgetID(Gadget)); force Redraw
EndIf
EndProcedure
CompilerCase #PB_OS_MacOS ;- OS_MacOS
#kControlUseJustMask = $0040
#teCenter = 1
#teFlushRight = -1
#teFlushLeft = -2
ImportC ""
GetDataBrowserListViewHeaderDesc(DataBrowserRef, ColumnID, *HeaderDesc)
GetDataBrowserTableViewColumnProperty(DataBrowserRef, Column, *ColumnID)
HiliteControl(ControlRef, ControlPart)
SetControlVisibility(ControlRef, IsVisible, DoDraw)
SetDataBrowserListViewHeaderDesc(DataBrowserRef, ColumnID, *HeaderDesc)
EndImport
Structure RGBColor
Red.U
Green.U
Blue.U
EndStructure
Structure ControlFontStyleRec
Flags.W
Font.W
Size.W
Style.W
Mode.W
Just.W
ForeColor.RGBColor
BackColor.RGBColor
EndStructure
Structure DataBrowserListViewHeaderDesc
Version.L
MinimumColumnWidth.U
MaximumColumnWidth.U
TitleOffset.W
CFTitleString.L
InitialSortOrder.U
FontStyle.ControlFontStyleRec
IconInfo.L
EndStructure
ProcedureC Alignment(Gadget, Column, Alignment)
; Protected ColumnID.L
; Protected HeaderDesc.DataBrowserListViewHeaderDesc
;
; If GetDataBrowserTableViewColumnProperty(GadgetID(Gadget), Column, @ColumnID) = 0
; If GetDataBrowserListViewHeaderDesc(GadgetID(Gadget), ColumnID, @HeaderDesc) = 0
; HeaderDesc\FontStyle\Flags = #kControlUseJustMask
;
; If ((Alignment & #PB_ListIcon_TextLeft) = #PB_ListIcon_TextLeft)
; HeaderDesc\FontStyle\Just = #teFlushLeft
; ElseIf ((Alignment & #PB_ListIcon_TextCenter) = #PB_ListIcon_TextCenter)
; HeaderDesc\FontStyle\Just = #teCenter
; ElseIf ((Alignment & #PB_ListIcon_TextRight) = #PB_ListIcon_TextRight)
; HeaderDesc\FontStyle\Just = #teFlushRight
; EndIf
;
; SetDataBrowserListViewHeaderDesc(GadgetID(Gadget), ColumnID, @HeaderDesc)
; EndIf
; EndIf
Protected ColumnHeaderCell.I
Protected ColumnObject.I
Protected ColumnObjectArray.I
If ((Alignment & #PB_ListIcon_TextLeft) = #PB_ListIcon_TextLeft)
Alignment = 0
ElseIf ((Alignment & #PB_ListIcon_TextCenter) = #PB_ListIcon_TextCenter)
Alignment = 2
ElseIf ((Alignment & #PB_ListIcon_TextRight) = #PB_ListIcon_TextRight)
Alignment = 1
EndIf
; ----- Justify text of column cells
CocoaMessage(@ColumnObjectArray, GadgetID(Gadget), "tableColumns")
CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", Column)
CocoaMessage(0, CocoaMessage(0, ColumnObject, "dataCell"), "setAlignment:", Alignment)
; ----- Justify text of column header
CocoaMessage(@ColumnHeaderCell, ColumnObject, "headerCell")
CocoaMessage(0, ColumnHeaderCell, "setAlignment:", Alignment)
; ----- Redraw ListIcon contents to see change
CocoaMessage(0, GadgetID(Gadget), "reloadData")
EndProcedure
CompilerCase #PB_OS_Windows ;- OS_Windows
Procedure Alignment(Gadget, Column, Alignment)
Protected ListIconColumn.LV_COLUMN
ListIconColumn\mask = #LVCF_FMT
If ((Alignment & #PB_ListIcon_TextLeft) = #PB_ListIcon_TextLeft)
ListIconColumn\fmt = #LVCFMT_LEFT
ElseIf ((Alignment & #PB_ListIcon_TextCenter) = #PB_ListIcon_TextCenter)
ListIconColumn\fmt = #LVCFMT_CENTER
ElseIf ((Alignment & #PB_ListIcon_TextRight) = #PB_ListIcon_TextRight)
ListIconColumn\fmt = #LVCFMT_RIGHT
EndIf
SendMessage_(GadgetID(Gadget), #LVM_SETCOLUMN, Column, @ListIconColumn)
If ((Alignment & #PB_ListIcon_TextItemAutoSize) = #PB_ListIcon_TextItemAutoSize)
SendMessage_(GadgetID(Gadget),#LVM_SETCOLUMNWIDTH,Column,#LVSCW_AUTOSIZE)
ElseIf ((Alignment & #PB_ListIcon_TextColumnAutoSize) = #PB_ListIcon_TextColumnAutoSize)
SendMessage_(GadgetID(Gadget),#LVM_SETCOLUMNWIDTH,Column,#LVSCW_AUTOSIZE_USEHEADER)
EndIf
InvalidateRect_(GadgetID(Gadget), 0, #True)
EndProcedure
CompilerEndSelect
EndModule
Enumeration Window
#Window_0
EndEnumeration
Enumeration Gadget
#Window_0_Gadget_0
EndEnumeration
Procedure Resize()
ResizeGadget(#Window_0_Gadget_0,#PB_Ignore,#PB_Ignore,WindowWidth(EventWindow()),WindowHeight(EventWindow()))
EndProcedure
If OpenWindow(#Window_0,0,0,1000,100, "",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ListIconGadget(#Window_0_Gadget_0,0,0,1000,100, "Text left", 100, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#Window_0_Gadget_0, 1, "Text center", 100)
AddGadgetColumn(#Window_0_Gadget_0, 2, "Text right", 100)
AddGadgetColumn(#Window_0_Gadget_0, 3, "Text column auto size and text center", 200)
AddGadgetColumn(#Window_0_Gadget_0, 4, "Text column auto size", 200)
AddGadgetColumn(#Window_0_Gadget_0, 5, "Text center", 250)
AddGadgetColumn(#Window_0_Gadget_0, 6, "Text right", 150)
For i =0 To 3
AddGadgetItem(#Window_0_Gadget_0,i,"(standart)" + Chr(10) + "text center" + Chr(10) + "text right" + Chr(10) + "text center" + Chr(10) + "text right" + Chr(10) + "text item auto size" + Chr(10) + "text item auto size")
Next
ListIconText::Alignment(#Window_0_Gadget_0,0,ListIconText::#PB_ListIcon_TextLeft)
ListIconText::Alignment(#Window_0_Gadget_0,1,ListIconText::#PB_ListIcon_TextCenter)
ListIconText::Alignment(#Window_0_Gadget_0,2,ListIconText::#PB_ListIcon_TextRight)
ListIconText::Alignment(#Window_0_Gadget_0,3,ListIconText::#PB_ListIcon_TextColumnAutoSize|ListIconText::#PB_ListIcon_TextCenter)
ListIconText::Alignment(#Window_0_Gadget_0,4,ListIconText::#PB_ListIcon_TextColumnAutoSize|ListIconText::#PB_ListIcon_TextRight)
ListIconText::Alignment(#Window_0_Gadget_0,5,ListIconText::#PB_ListIcon_TextItemAutoSize|ListIconText::#PB_ListIcon_TextCenter)
ListIconText::Alignment(#Window_0_Gadget_0,6,ListIconText::#PB_ListIcon_TextItemAutoSize|ListIconText::#PB_ListIcon_TextRight)
BindEvent(#PB_Event_SizeWindow, @Resize(), #Window_0)
While IsWindow(#Window_0)
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
CloseWindow(EventWindow())
EndSelect
Wend
EndIf
End
Last edited by mestnyi on Thu Oct 18, 2018 7:45 am, edited 1 time in total.
Re: Column alignment in ListIconGadget
Your example will work on MacOS only up to PB 5.11 with subsystem Carbon. Starting with version 5.00, PureBasic has changed its utilized framework on MacOS from Carbon to Cocoa.mestnyi wrote:+1
My two cents
You have taken the MacOS code part from my old code example from 2012. But you seem to have overseen my link in that thread to a solution using the Cocoa framework which also works in current PB versions. Therefore I have posted in that thread now a modified version in which I replaced the Carbon part by the Cocoa part, so that my modified example is now also working with current PB versions on MacOS.