B4J Question How to get xGaugesRect from Pane

MrKim

Well-Known Member
Licensed User
Longtime User
1719842366378.png

I am using Klause's amazing xGaugesRect library but I can't for the life of me figure out how to get at them once they have been added to a pane. I have 3 gauges on the pane and if you click on any one the event occurs and Sender is a xGaugesRect and I can get the parent pane but I can't seem to figure out how to get at the gauges. I tried every combination I could think of with no luck.
Added like this from a Layout file::
Dim P As B4XView = MachPane.GetView(3)
P.RemoveAllViews
P.LoadLayout("WeeklyGaugeS")
WeeklyGaugeGA1.ScaleMidLimitColors = Array As Int(xui.Color_Green, xui.Color_Yellow)
WeeklyGaugeGA1.ScaleMidLimit2Colors = Array As Int(xui.Color_Yellow, xui.Color_Red)
WeeklyGaugeGA1.TickText = CalcGaugeScale(MachData.Get("SchM_HrsPerWk"))  '  "0|10|20|30|40|50"
.
.
If I add a click event for the gauges Sender is definitely xGaugesRect but I get the parent view and I can't seem to access the gauges.
I solved the problem by adding each gauge to a map and storing that map in the parent tag property, but that is a bit of a waste and I would rather get them from the parent directly if possible. As always, I fell like I must of missed something obvious. When I loop through the controls on the parent none of them seem to have a tag property that is the control. Likewise testing each control and its tag to see if it is an xGaugesRect gets no result.

As always thanks for any help.
 

klaus

Expert
Licensed User
Longtime User
Sorry, but I do not understand what exactly you want to do ?
In the common click event you get the xGaugesRect which raised the event.
Therefore, what do want to do ?
Not enough information to help.
As DonManfred already suggested post a small project to show the problem.

I made a small test program with 3 xGaugesRect in the layout.

And the code of the xGaugesRect_Click event.
B4X:
Private Sub xGaugesRect_Click
    Private Gauge As xGaugesRect
    Private Parent As B4XView
 
    Gauge = Sender        ' the xGaugeRect which raised the event
    Log(Gauge.GaugeTitle)
 
    Parent = Gauge.mBase.Parent    'gets its parent, the Parent is not exposed directly.
    Log(Parent.NumberOfViews)
 
    For i = 0 To Parent.NumberOfViews -1
        Private g As xGaugesRect
        g = Parent.GetView(i).Tag        'gets the xGaugeRect with its given index
        Log(g.GaugeTitle)
    Next
End Sub
 

Attachments

  • Test3Gauges.zip
    10.4 KB · Views: 14
Last edited:
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I made a small test program with 3 xGaugesRect in the layout.
My layout is actually quite a bit more complicated. The gauges are on a b4xview on a pane which is the inner pane on a scrollview. So I added all of that and it still worked fine. I switched to the xGaugesRect.bas in my app and immediately notice that it was different did not contain:
B4X:
WeeklyGaugeGA1.ScaleMidLimitColors = Array As Int(xui.Color_Green, xui.Color_Yellow)
WeeklyGaugeGA1.ScaleMidLimit2Colors = Array As Int(xui.Color_Yellow, xui.Color_Red)
(which I use)
I also notice the xGaugesRect.bas I am using has a different ReInitialize sub.
Yours::
'reinitializes the gauge
Public Sub ReInitialize
    If mBase.IsInitialized Then
'        mBase.RemoveViewFromParent
'        mBase = xui.CreatePanel("pnlGauge")
'        cParent.AddView(mBase, cLeft, cTop, cWidth, cHeight)
'        pnlNeedle.RemoveViewFromParent
        mBase.RemoveAllViews
        InitGauge
    End If
End Sub
The one I am using::
'reinitializes the gauge
Public Sub ReInitialize
'    If mBase.IsInitialized Then
    If pnlAction.IsInitialized Then
        mBase.RemoveViewFromParent
        mBase = xui.CreatePanel("pnlGauge")
        cParent.AddView(mBase, cLeft, cTop, cWidth, cHeight)
        pnlNeedle.RemoveViewFromParent
        mBase.RemoveAllViews
        InitGauge
    Else
        InitGauge
    End If
Perhaps that is the problem?
My xGaugesRect.bas file came from xGaugesDemo_V1_9.zip located HERE:

I modified the demo and tried to access the gauges and could not. I have attached the modified demo. Perhaps I am still doing something wrong.

Thanks for all your help and all your hard work.
 

Attachments

  • jxGaugesDemo-B4J-Modified.zip
    34.4 KB · Views: 7
  • jxGaugesDemo-B4J-Modified.zip
    34.4 KB · Views: 7
Upvote 0
Top