B4J Library Replacement TitleBar

I've seen a few questions on the forums about changing the titlebar color. The answer is that you have to replace the title bar.

This gives the problem of then losing all of the form controls, resizing minimising, maximising and close buttons.

This is a customview, that does all of this. Just add the titlebarCV customview to the top of a layout and it will replace the existing titlebar with one defined int the titlebar layout.

The title color is controlled by the color selected for the background on the TitlebarBG pane. The font can be changed on the TitleLabel.

There are no methods available for the titlebar. Through listeners, the title and icon are updated when the title and icon are changed on the Form that the customview is added to.

There are three custom properties, 1 displays a dropshadow and another to choose the dropshadow color. The thirds allows turning off the minimize animation.

If you choose to add a drop shadow, the layout must be inset by 8 pixels all round. This is because the shadow is actually drawn on the form in it's transparent borders. See the layout in the demo for an example.

I've tried to recreate the look and behaviour of a Windows form, I don't have access to a Mac or linux box, so if you create a layout for either of these I would be grateful if you would share it.

The code is one class and a utility class (FormUtils) and is all in the attached project.

TitleBar.jpg


Update to V1.0

  • Reworked the drag logic
  • Added Emulation of windows snap to screen
  • Added more designer properties
  • Added method ResetMouseListeners

The added properties include options to turn off the windows snapping, icon state colours and specify a layout name.

The layout must include all of the views that are in the provided titlebar layout.

Emulated snap to screen does not integrate with the windows snap to screen, but is still quite useful and you can temporarily disable it by pressing the Ctrl key. Works with multiple screens.

Resizing is now done using additional panes added to the forms.rootpane. If you add a lot of views in code, you may need to call ResetMouseListeners which will ensure that the listening panes are at the front.(Not required from v1.1) The listening panes are 5px wide, So you cannot capture mouseclicks within 5 px of the form edges, but they are transparent so you can see anything that is under them.

Depends on:
CssUtils
JavaObject

Update: v1.1
  • Added listener to getChildrenUnmodifiable to automatically call ResetMouseListeners as needed.
  • Made important Titlebar views public for styling.
  • Removed redundant code
  • Added CloseRequst(EventData as Event) Event to delegate to MainForm_CloseRequest(EventData as Event)
  • Set default icon so that it's click can be captured if required.
  • Stop the form closing on Right mouse button click
  • Added override for Maximize size, mainly for Mac users.
The Titlebar close request callback should be delegated directly to the Form CloseRequest sub

B4X:
Private Sub TitleBarCV1_CloseRequest (EventData As Event)
    'Delegate the call to MainForm_CloseRequest
    MainForm_CloseRequest(EventData)
End Sub

Private Sub MainForm_CloseRequest (EventData As Event)


End Sub

Using the Override Maximum size
If you change the left or top, you also need to make the opposite change to the width or height.​
You could selectively implement this in case the app is running on a Mac with this code:​
B4X:
If TB_Utils.isMac Then
    TitleBarCV1.OverrideMaximizedLayout(0,30,0,-30)
End If

I don't have a mac to try it on but I believe it should work.

Update V1.2
  • Implemented FullScreen Mode
  • Bug Fixes
Update V1.3
  • Added Snapping background and border colors to designer properties.
  • Fixed bug on Snapping background for multiple screens
  • improved Linux compatibility (see post#25)



Let me know how you get on with it.
 

Attachments

  • TitleBar1-3.zip
    37.5 KB · Views: 264
  • TitleBar.b4xlib
    17.3 KB · Views: 260
Last edited:

BPak

Active Member
Licensed User
Longtime User
Ran your example program on desktop Mac OS. Ran Ok. Images of 3 windows attached.
On Maximize it places top of maximized window under the Mac Menu Bar which is at the top of Desktop screen. Easily move window down to fit ok.
 

Attachments

  • TitleBar_Mac.png
    TitleBar_Mac.png
    99.4 KB · Views: 562

stevel05

Expert
Licensed User
Longtime User
On Maximize it places top of maximized window under the Mac Menu Bar

That's strange, as it calls a java API routine to Maximize. Does it do the same with the comparison form? That's just a standard form.
 
Last edited:

BPak

Active Member
Licensed User
Longtime User
Comparison Form works correct. Both the other Forms put the top of the window under the Menu Bar at top of Desktop Display
 

Attachments

  • Drop.png
    Drop.png
    15.7 KB · Views: 508
  • Comparison.png
    Comparison.png
    41.3 KB · Views: 497

behnam_tr

Active Member
Licensed User

i cant close forms when i opened one form(like form2) for two time

B4X:
sub mainform start()
mainform.show

sleep(1000)
form2.show  'its can close'

sleep(1000)
form2.show  'i can not close this'

endsub

this problem only when i use titlebar
thats ok in decorated or ..... style
 

stevel05

Expert
Licensed User
Longtime User
The title color is controlled by the color selected for the background on the TitlebarBG pane. The font can be changed on the TitleLabel.

In the Titlebar layout. If you want different colors for different windows, you can add a method to the TitlebarCV.
 

stevel05

Expert
Licensed User
Longtime User
Upgrade to V1.0
  • Reworked the drag logic
  • Added Emulation of windows snap to screen
  • Added more designer properties
  • Added method ResetMouseListeners
 
Last edited:

behnam_tr

Active Member
Licensed User
thanks
how change maximized size?
when form maxmized windows taskbar going to back how bring to front and show taskbar when??

sorry for bad english.
 

stevel05

Expert
Licensed User
Longtime User
Is this on Mac as in post #2? The Maximized size is controlled by the Operating system. I don't have a Mac to try it on. It would be fairly straight forward to allow override of the maximize functionality, but knowing the appropriate size would be difficult. And would it be the same on all sized screens?
 

behnam_tr

Active Member
Licensed User
Is this on Mac as in post #2? The Maximized size is controlled by the Operating system. I don't have a Mac to try it on. It would be fairly straight forward to allow override of the maximize functionality, but knowing the appropriate size would be difficult. And would it be the same on all sized screens?

yse i test in windows 7,8.1 and different sizes

when i set form style to Decorated mode and defualt titlebar its ok and taskbar is showing and form height is ok

with "replacment titlebar" i have to set height manualy
 

behnam_tr

Active Member
Licensed User
in FormUtils class

B4X:
'Sets the value of the property maximized.
Public Sub SetMaximized(F As Form, Value As Boolean)
    Dim TJo As JavaObject = GetStage(F)
    TJo.RunMethod("setMaximized",Array As Object(Value))
    
    Dim ps As Screen = fx.PrimaryScreen
    f.WindowHeight = ps.MaxY - ps.MinY
    
End Sub

its ok on different sizes screen
 

stevel05

Expert
Licensed User
Longtime User
Do you get the same problem if you used the window snapping to the left or right?
 

behnam_tr

Active Member
Licensed User
Do you get the same problem if you used the window snapping to the left or right?

yes i tested new version and same problem when snapping to top center or normal maximize with click or double click
but its ok when snapping to right or left

every things is ok on Comparison form
 

stevel05

Expert
Licensed User
Longtime User
Try this one, you need to call OverrideMaximizedLayout on the Titlebar with the appropriate amendments.

Added to update V1.1 see first post.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Update to V1.1 (see first post)

As you can probably tell, I've been using this a fair bit lately, so have added some functions that I feel are important. I hope you like them.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
@behnam_tr I've included the Override amendment in V1.1 with a couple of bug fixes. If you haven't tried it yet, download the latest version.
 
Top