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:
Top