B4J Question Base_Resize Problem in Class Module

mmieher

Active Member
Licensed User
Longtime User
I am trying to create my first class. I want to dynamically create a layout so that it is not necessary for users of this class to create a layout using the designer.

Problem is that I cannot seem to get the Base_Resize event to fire from within the class. It must be something simple.

Here is the class code:
B4X:
Sub Class_Globals
   
    Private xui As XUI 'ignore

    Private fx As JFX
   
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As B4XView
   
    Private xPnl As B4XView

   End Sub

'You can add more parameters here.
Public Sub Initialize (Callback As Object, EventName As String)
     mEventName = EventName
    mCallBack = Callback
   
    DesignerCreateView(mCallBack)

End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
     'load the layout to Root
    'Root = Root1
End Sub

Public Sub DesignerCreateView (Base As Object)
    Log("DesignerCreateView")

    mBase = Base
    xPnl = xui.CreatePanel("xPnl")
    mBase.AddView(xPnl,0,0,mBase.Width,40dip)
    mBase.BringToFront

End Sub

'     DOES NOT FIRE
Private Sub Base_Resize (Width As Int, Height As Int)
    Log("Base_Resize " & Width & " x " & Height)
End Sub

'     NOPE
Private Sub mBase_Resize (Width As Int, Height As Int)
    Log("mBase_Resize " & Width & " x " & Height)
End Sub

'     ME NEITHER
Private Sub B4XPage_Resize (Width As Int, Height As Int)
    Log("B4XPage_Resize " & Width & " x " & Height)
End Sub

'     WORKS!  However xPnl is what I want to resize when the window is resized
Private Sub xPnl_Resize (Width As Double, Height As Double)
    Log("xPnl_Resize " & Width & " x " & Height)
End Sub
[\CODE]
 

klaus

Expert
Licensed User
Longtime User
Sorry, but you do not give enough information.
What exactly do you want to do?
Is it a Standard Class or a CustumView ?
In your code, you seem to mixing up some incompatible subjects.
Therefore to be able to give a concrete advice, please explain exactly what you want do.

Did you have a look at the B4X CustomViews booklet ?

This kind of routine has nothing to do in a class:
Private Sub B4XPage_Created (Root1 As B4XView)

This routine is automatically called be B4X when a CustomView is Initialized.
DesignerCreateView(mCallBack)
Therefore no need to call it.
So, again, what exactly do you want to do ?
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Hi, Klaus. I was hoping you were out there.

It is not a CustomView, but a Standard Class.
I will remove B4XPage_Created from the class.

From the class, I am trying to create a menu-type panel which contains various views. I want the panel to display over the current page. That part works.

However, when the window is resized, the event does not fire. I need to resize the panel at that point and also do the equivalent of a B4A anchor.

I have "band aided" it by using CallSubDelayed from the Main module resize event. This is not ideal as it would require a code change to a page module by the user of the class.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I do not understand what exactly you want to do.
I first thought:
In B4XMainPage you can add the B4XPage_Resize routine.
Then in the class module add a Resize routine which is called from the B4XMainPage B4XPage_Resize routine.
In my mind, depending on how the layout is generated this should be automatic.

Do you have a test project?
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Yes I do. This is a work in progress, and I know there are lots of menu classes out there.
This is an exercise for me to learn the basics of B4XPages, xui, etc.
 

Attachments

  • PicaCentro.zip
    5.3 KB · Views: 147
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your project.

1. Do you want your prjoect be a cross-platfoem project ?
If yes you should zip the project with this line on top of B4XMainPage, press CTRL and click:
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
This will zip the entire project.
I had to comment the first line in B4XMainPage because the Shared Files folder does not exist.

2. As you have defined a standard class, there is no automatic Resize event fired.
Only the B4XPage_Resize event is raised. And you need to make all the resizing on your own as you did it.
If you define a CustomView, then you have the Base_Resize event and can do the resizing there.
In B4A, there is no Resize event.
If you make a layout for the menu and work with anchors and Designer script the resizing works.
You can see this in the modified project below for a Pane on the B4XPage.

3. Your project will work only with B4J, the MouseClicked event does only exist in B4J, in B4A and B4i it is the Click event.
Therefore, for a cross-platform project you would need to differentiate the events depending on the platform.

I zipped the project as B4J project.
 

Attachments

  • PicaCentro1.zip
    5.5 KB · Views: 137
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
Thanks, Klaus.

I am trying to learn how to write a platform-independent class. This has been an exercise. xCustomListView was a poor choice for a dynamic view. Erel has said it is a bad idea. I switched to panels and labels.

I started with B4J because A) I wanted to check it out, and B) the B4XPages tutorial is in B4J. I think I swill switch to B4A and deal with the compiler-directives for iOS.

I might be missing something, but how does one write a reusable class (then Library some day) if I have to include designer layouts, and the user has to make mods to other modules -- other than the Events in my class.

We can drop this issue. Thanks for your time.
 
Upvote 0
Top