Change indentation of column text in the ListIconGadget

Mac OSX specific forum
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Change indentation of column text in the ListIconGadget

Post by Shardik »

If you think that you loose too much space in your ListIconGadgets
by the default indentation of text in your columns, I might offer you
the cure... :wink:
Take a look into my code example which demonstrates how to use
the API function DataBrowserSetMetric to find the ideal indentation
by using a slider:

Code: Select all

ImportC ""
  DataBrowserSetMetric(ControlRef.L, MetricType.L, UseDefaultValue.L, Value.F)
EndImport

#kDataBrowserMetricCellContentInset = 1

OpenWindow(0, 200, 100, 460, 130, "ListIcon Example")
ListIconGadget(0, 5, 30, 450, WindowHeight(0) - 30, "Name", 140)
AddGadgetColumn(0, 1, "Address", 289)
AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown")
TrackBarGadget(1, 5, 7, 55, 20, 0, 55)
TextGadget(2, 65, 7, 290, 20, "Current text indentation in columns:")
TextGadget(3, 300, 7, 30, 17, "12", #PB_Text_Border | #PB_Text_Center)
SetGadgetState(1, 12)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        CurrentIndentation = GetGadgetState(1)
        DataBrowserSetMetric(GadgetID(0), #kDataBrowserMetricCellContentInset, #False, 0.0 + CurrentIndentation)
        SetGadgetText(3, Str(CurrentIndentation))
      EndIf
  EndSelect
ForEver
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Change indentation of column text in the ListIconGadget

Post by WilliamL »

Shardik,

Great addition! I have avoided using the ListIcon gadget in the past because of the wide margins and this solves that problem. The example shows that the API is short and easy to use. I like the way the code demonstrates the margin changes too. :)

Thanks for all your efforts.

Here, using your information (and code) is a ListView gadget with adjustable margins, column lines (not possible in pb), and color on alternating lines. Looks pretty good!

Code: Select all

ImportC ""
    DataBrowserSetMetric(ControlRef.L, MetricType.L, UseDefaultValue.L, Value.F)
    DataBrowserChangeAttributes(ControlRef.L, AttributesToSet.L, AttributesToClear.L)
EndImport
#kDataBrowserAttributeListViewAlternatingRowColors = (1 << 1)
#kDataBrowserAttributeListViewDrawColumnDividers = (1 << 2)
#kDataBrowserMetricCellContentInset = 1

OpenWindow(0, 200, 100, 460, 130, "ListIcon Example")
ListIconGadget(0, 5, 30, 450, WindowHeight(0) - 30, "Name", 140)
DataBrowserChangeAttributes(GadgetID(0), #kDataBrowserAttributeListViewAlternatingRowColors | #kDataBrowserAttributeListViewDrawColumnDividers, 0)
AddGadgetColumn(0, 1, "Address", 289)
AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit"+ #LF$ + "321 Logo Drive, Mouse House, Downtown")
TrackBarGadget(1, 5, 7, 55, 20, 0, 55)
TextGadget(2, 65, 7, 290, 20, "Current text indentation in columns:")
TextGadget(3, 300, 7, 30, 17, "12", #PB_Text_Border | #PB_Text_Center)
SetGadgetState(1, 12)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        CurrentIndentation = GetGadgetState(1)
        DataBrowserSetMetric(GadgetID(0), #kDataBrowserMetricCellContentInset, #False, 0.0 + CurrentIndentation)
        SetGadgetText(3, Str(CurrentIndentation))
      EndIf
  EndSelect
ForEver
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Change indentation of column text in the ListIconGadget

Post by Shardik »

William,

I am glad that my API example proved to be useful for you. And thank you
for your expanded example. Although I think that the slider to adjust the
indentation is more a utility for the programmer to evaluate the optimal
indentation during design and development of the GUI than a valuable
control for the end user... :wink:
Post Reply