It is currently Tue Aug 22, 2017 9:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Wed Dec 28, 2016 12:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Dec 08, 2003 7:50 pm
Posts: 154
Location: Germany
Hi,

when using the TreeGadget with icons and a custom set font / font size I observed a small thing: the text is not centered vertically with regard to the icons anymore. It's not a big thing, but it looks somehow ... ugly. (PB 5.51 x64 on macOS Sierra 10.12)

Here is a small example code:

Code:
EnableExplicit

Define WindowEvent.q

LoadFont(0, "Verdana", 12)

If OpenWindow(0, 0, 0, 200, 500, "TreeGadget", #PB_Window_ScreenCentered)
  TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
    SetGadgetFont(0, FontID(0))
 
  CreateImage(0, 16, 16)

  If StartDrawing(ImageOutput(0))
    Box(0, 0, OutputWidth(), OutputHeight(), $CC3299)
    StopDrawing()
  EndIf

  CreateImage(1, 16, 16)

  If StartDrawing(ImageOutput(1))
    Box(0, 0, OutputWidth(), OutputHeight(), $7A96E9)
    StopDrawing()
  EndIf
 
  AddGadgetItem(0, -1, "Item", ImageID(0))
  AddGadgetItem(0, -1, "Subitem", ImageID(1), 1)
  SetGadgetItemState(0, 0, #PB_Tree_Expanded)

  Repeat
    WindowEvent = WaitWindowEvent()

    Select WindowEvent
    EndSelect
  Until WindowEvent = #PB_Event_CloseWindow
EndIf


Is this a bug or do I overlook something? Does anyone have an idea for a simple workaround?

Thanks and best regards,
Christian


Last edited by Christian on Mon Jan 02, 2017 6:24 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Wed Dec 28, 2016 4:27 pm 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1100
Location: Seattle, USA
Oh, I see what you mean. With the custom icons, the sub items are indented the custom icon width. Looks nice to me but it is not the same as the Help example. I tried it on 5.42LTS and 5.51b1x64 and the sub items are indented the same.

...maybe a bug.. or a feature. :)

_________________
MacBook Pro-r, OSX 10.11.6, Command Line Tools 7.3 (10.11), PB-5.60x64


Top
 Profile  
Reply with quote  
 Post subject: Re: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Sat Dec 31, 2016 1:41 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Dec 08, 2003 7:50 pm
Posts: 154
Location: Germany
Thanks for your answer, William. But, actually I don't mean the subitem indentation. What I mean is the vertical position of the text, which is not in the center (vertically) of the row height of any item. Here is a picture:

Image

On the left is what purebasic does. On the right, how it should look like. It's only 2 or 3 pixels in this example with a custom font. But in my opinion it looks not nice how PB does it.

So, a bug?


Top
 Profile  
Reply with quote  
 Post subject: Re: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Sun Jan 01, 2017 10:18 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1433
Location: Germany
Christian wrote:
So, a bug?
It looks indeed like a bug.

You may workaround this bug by using my old workaround for older PB versions (up to 5.11, in 5.24 this is fixed) which were not able to indent icons together with their node text. For your convenience I have taken that example and modified it to match your example and the vertical alignment of the node text now seems to look as you would like it (tested with MacOS 10.6.8 'Snow Leopard' and PB 5.44 x86):
Code:
EnableExplicit

#NSSwitchButton = 3

Define i.I
Define Indentation.CGFloat = 25

Dim ButtonCell.I(0)

ProcedureC CellDisplayCallback(Object.I, Selector.I, OutlineView.I,
  TableColumn.I, Item.I)
  Shared ButtonCell.I()
  Protected Row.I = CocoaMessage(0, GadgetID(0), "rowForItem:", Item)

  If ButtonCell(Row) <> 0
    ProcedureReturn ButtonCell(Row)
  EndIf
EndProcedure

Procedure SetGadgetCallback(GadgetID.I, GadgetCallback.I, Method.S)
  Protected AppDelegate.I
  Protected DelegateClass.I
  Protected PlaceholderList.S

  PlaceholderList = LSet("@:", CountString(Method, ":"), "@")
  AppDelegate = CocoaMessage(0, CocoaMessage(0, 0,
    "NSApplication sharedApplication"), "delegate")
  DelegateClass = CocoaMessage(0, AppDelegate, "class")
  class_addMethod_(DelegateClass, sel_registerName_(Method), GadgetCallback,
    PlaceholderList)
  CocoaMessage(0, GadgetID(GadgetID), "setDelegate:", AppDelegate)
EndProcedure

Procedure AddImageToTreeRow(ImageID.I, Row.I)
  Shared ButtonCell.I()
  Protected ItemText.S
  Protected TableColumn.I

  TableColumn = CocoaMessage(0, CocoaMessage(0, GadgetID(0), "tableColumns"),
    "objectAtIndex:", 0)
  ButtonCell(Row) = CocoaMessage(0, 0, "NSButtonCell new")
  CocoaMessage(0, ButtonCell(Row), "setButtonType:", #NSSwitchButton)
  CocoaMessage(0, ButtonCell(Row), "setImage:", ImageID(ImageID))
  ItemText = GetGadgetItemText(0, Row)
  CocoaMessage(0, ButtonCell(Row), "setTitle:$", @ItemText)
EndProcedure

CreateImage(0, 16, 16)

If StartDrawing(ImageOutput(0))
  Box(0, 0, OutputWidth(), OutputHeight(), $CC3299)
  StopDrawing()
EndIf

CreateImage(1, 16, 16)

If StartDrawing(ImageOutput(1))
  Box(0, 0, OutputWidth(), OutputHeight(), $7A96E9)
  StopDrawing()
EndIf

LoadFont(0, "Verdana", 12)

OpenWindow(0, 270, 100, 140, 100, "Tree")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
SetGadgetFont(0, FontID(0))

AddGadgetItem(0, -1, "Item", ImageID(0))
AddGadgetItem(0, -1, "Subitem", ImageID(1), 1)
SetGadgetItemState(0, 0, #PB_Tree_Expanded)

; ----- Setup callback for TreeGadget
SetGadgetCallback(0, @CellDisplayCallback(),
  "outlineView:dataCellForTableColumn:item:")

; ----- Add images to specified rows
ReDim ButtonCell(CountGadgetItems(0) - 1)
AddImageToTreeRow(0, 0)
AddImageToTreeRow(1, 1)

; ----- Don't indent indentation marker along with cell contents
CocoaMessage(0, GadgetID(0), "setIndentationMarkerFollowsCell:", #NO)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

; ----- Release NSButtonCell objects
For i = 0 To CountGadgetItems(0) - 1
  If ButtonCell(i) <> 0
    CocoaMessage(0, ButtonCell(i), "release")
  EndIf
Next i


Top
 Profile  
Reply with quote  
 Post subject: Re: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Mon Jan 02, 2017 6:24 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Dec 08, 2003 7:50 pm
Posts: 154
Location: Germany
Thanks for your sample code, Shardik. Unfortunately, it still does not align in fully correctly under macOS Sierra 10.12. It is now shifted a little bit to the top of the row instead of being shifted to the bottom. Apart from that I don't see where the exact position of the text is set in your code. Maybe you can point it out? I'm not so familiar with macOS programming and the Objective C classes and methods. :oops:


Top
 Profile  
Reply with quote  
 Post subject: Re: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Wed Jan 04, 2017 12:02 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1433
Location: Germany
The easiest workaround without needing any API function should be to move the icon vertically down until it matches your preferred text position by increasing the height of your icon. I have taken your example and added the new constant #yOffset. Simply adjust #yOffset until the text is displayed in your preferred vertical position in relation to your icon:
Code:
EnableExplicit

#yOffset = 3

Define WindowEvent.I

LoadFont(0, "Verdana", 12)

If OpenWindow(0, 270, 100, 140, 100, "Tree")
  TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
  SetGadgetFont(0, FontID(0))
 
  CreateImage(0, 16, 16 + #yOffset, 32, $FFFFFF)

  If StartDrawing(ImageOutput(0))
    Box(0, #yOffset, OutputWidth(), OutputHeight() - #yOffset, $CC3299)
    StopDrawing()
  EndIf

  CreateImage(1, 16, 16 + #yOffset, 32, $FFFFFF)

  If StartDrawing(ImageOutput(1))
    Box(0, #yOffset, OutputWidth(), OutputHeight() - #yOffset, $7A96E9)
    StopDrawing()
  EndIf
 
  AddGadgetItem(0, -1, "Item", ImageID(0))
  AddGadgetItem(0, -1, "Subitem", ImageID(1), 1)
  SetGadgetItemState(0, 0, #PB_Tree_Expanded)

  Repeat
    WindowEvent = WaitWindowEvent()

    Select WindowEvent
    EndSelect
  Until WindowEvent = #PB_Event_CloseWindow
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: [Bug?] SetGadgetFont() on TreeGadget() with icons
PostPosted: Sat Jan 14, 2017 10:41 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Dec 08, 2003 7:50 pm
Posts: 154
Location: Germany
Thanks, Shardik. I think these suggestion will help, until the bug is fixed. :)

Best regards,
Christian


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye