Is there a way to get “small” versions of some of the basic UI controls that will work cross-platform (Mac/Win)? I would imagine that it can be done with declares (or MBS) in the Open events. Would someone be able to point me to the requisite code? Here are my four issues:
Slider
Setting the “Height” to something other than the default (23px) works, but only in Windows.
The Mac version always displays at the default size, regardless of the height setting.
Interestingly, the default height for this control is different in Win (24px) and Mac OS X (23px)
PopupMenu
Setting the “Font” to “SmallSystem” (and “Height” to 16px) works, but only on Mac OS X
The Widows version always displays in the full size, regardless of the Height value
UpDownArrows
On both platforms setting the size to anything smaller than the default 13x23px results in clipping
Anything larger than the default doesn’t show any visual difference.
Essentially you’re stuck with 13x23px, have a good day!
CheckBox
There doesn’t seem to be any way to get at the smaller version of this control on either platform
Does anyone know of example code (cross-platform) where this deficiency is addressed? I’m sure that I could build custom versions of these controls, but the “small” versions are already baked into the OS, and therefore look and behave natively on both platforms, why reinvent the wheel?
Since for the most part XOJO uses the native controls as defined by each OS, you are pretty much at the mercy of Apple or Microsoft, and not so much XOJO itself.
You can always roll you own (subclass a Canvas) and have 100% control over what it does and when it does it
Where did you find information that “small” versions are baked in already?
[quote=153461:@Dave S]Since for the most part XOJO uses the native controls as defined by each OS, you are pretty much at the mercy of Apple or Microsoft, and not so much XOJO itself.
You can always roll you own (subclass a Canvas) and have 100% control over what it does and when it does it
Where did you find information that “small” versions are baked in already?
[/quote]
Xcode and VisualStudio both provide ways to display smaller versions of many basic UI controls. I suppose that I should add “RadioButton” to the list as well.
Of course I can roll my own using custom canvases, but then you loose things like keyboard control, or native appearance depending on the version of the OS. I’ve done this with my Histogram control where I needed three slider thumbs in one slider (white point, gamma, and black point), but I would rather not get into the habit of replacing perfectly good native controls when they are available.
[quote=153471:@William Koperwhats]Xcode and VisualStudio both provide ways to display smaller versions of many basic UI controls. I suppose that I should add “RadioButton” to the list as well.
Of course I can roll my own using custom canvases, but then you loose things like keyboard control, or native appearance depending on the version of the OS. I’ve done this with my Histogram control where I needed three slider thumbs in one slider (white point, gamma, and black point), but I would rather not get into the habit of replacing perfectly good native controls when they are available.
Cheers.
-bill k[/quote]
Since these seem available natively, it is probably just a declare to set the adequate property. It should be pretty simple, after a visit to the Mac developer Library or the Microsoft developer Network.
For most of the controls on OS X, it is possible with a declare or two! I’ve lifted this code from “Interface Tricks” which comes with the Retina Kit (available as part of the Omega Bundle).
Add the following code to a module.
[code]Sub setControlSize(Extends c as RectControl, inSize as NSControlSize) #if TargetCocoa then
Declare Function NSClassFromString Lib “Cocoa” (className as CFStringRef) As Ptr
declare sub setSize lib “Cocoa” selector “setControlSize:” ( ObjectHandle as Integer, inSize as NSControlSize )
Declare function getCell lib “Cocoa” selector “cell” ( handle as integer ) as Integer
if c isa progressBar then
setSize( c.handle, inSize )
else
setSize( getCell( c.handle ), inSize )
// - Now we also update the text font to match
Dim fontSize as single
select case inSize
case NSControlSize.NSRegularControlSize
declare function systemFontSize lib "Cocoa" selector "systemFontSize" ( classRef as Ptr ) as single
fontSize = systemFontSize( NSClassFromString( "NSFont" ) )
else
// + (CGFloat)smallSystemFontSize
declare function smallSystemFontSize lib "Cocoa" selector "smallSystemFontSize" ( classRef as Ptr ) as single
fontSize = smallSystemFontSize( NSClassFromString( "NSFont" ) )
end select
// + (NSFont *)systemFontOfSize:(CGFloat)fontSize
declare function systemFontOfSize lib "Cocoa" selector "systemFontOfSize:" ( classRef as Ptr, inSize as single ) as Ptr
Dim ref as Ptr = systemFontOfSize( NSClassFromString( "NSFont" ), fontSize )
if ref <> nil then
// - (void)setFont:(NSFont *)fontObject
declare sub setFont lib "Cocoa" selector "setFont:" ( NSControlHandle as integer, font as Ptr )
setFont( c.handle, ref )
end if
end if
#else #pragma undefined
#endif
End Sub
[/code]
Now add the following enum to the same module.
Public Enum NSControlSize
NSRegularControlSize
NSSmallControlSize
NSMiniControlSize
Then in the open event of the window or the control (this doesn’t work if used in the constructor).
Sam, I can’t seem to get this working for sliders (with or without tick marks). They always show up in the default size. I haven’t noticed any sliders in AppWrapper (at least in my version) and was wondering if you’ve been able to get this to work.
Lovely, looks like it’s another Yosemite issue. I’ve got a HD with a Mavericks virtual machine that I’ll try Monday when I’m back at the office. Thanks for the help Sam.
I’ll give it a test later on Yosemite (if I don’t forget), but I’ll let you have the honor of logging the bug with Apple (I think they’re probably fed up with my weekly bug reports).
I think our hot water heater must have auto updated to Yosemite, I have to keep restarting it to get hot water.
Sliders seems to be working as expected on Yosemite for me. I do have some issues though; There seems to be a problem with controls inside container controls (at least if there are multiple levels of container controls inside container controls). Setting controls to small or mini works fine in simple test apps, where I just place the controls on the window, or in a container control.
I had my (real) app resizing a single checkbox as expected in a test, but when I then added further checkboxes and updown arrows it stopped working and all controls remained at the default size.
Many controls lose their mini or smallness when the window is resized. Reapplying in that event fixes it ok. Haven’t tested with ContainerControls. Also Labels and Scrollbars don’t have a mini or small size and ProgressWheels cause an ObjC exception. It is very cute! thanks for the code Sam.
Adding the setControlSize to the Resized event, works to some extent. It’s not consistent though, so at the moment it’s, unfortunately, still useless to me.
[quote=154105:@Sam Rowlands]@William Koperwhats Sam, I can’t seem to get this working for sliders (with or without tick marks). They always show up in the default size. I haven’t noticed any sliders in AppWrapper (at least in my version) and was wondering if you’ve been able to get this to work.
I wouldn’t be surprised if it doesn’t work on 10.10, there is a lot of GUI issues with 10.10.[/quote]
Sliders show small perfectly well here with your method, Sam. 10.10.1.
There is obviously something that the Xojo framework is doing when a control resizes that resets this property of the NSControl. Probably need to log a feedback report.