iOS Question HexMenu [SOLVED] - Please help to color text / change font and add images with CSBuilder

Mashiane

Expert
Licensed User
Longtime User
Hi there

I need some help in making this work. This is my code

B4X:
'clear the hexagon
    HexMenu1.Items.Initialize
    For i = 1 To 10
        Dim eachD As CSBuilder
        eachD.Initialize.Alignment("ALIGN_CENTER").Color(Colors.White).Font(Font.CreateNew(8))
        eachD.Append($"Item ${i}"$).PopAll
                
        HexMenu1.Items.Add(eachD)
    Next
    HexMenu1.Update

This is the output, that is not what I need. I have changed the font size also, nothing happens. What am I missing?

WhatsApp Image 2021-11-09 at 8.14.24 PM.jpeg


Also within the items, I need to add an image from file.dirassets, this works well in b4a.

I have tried this code, I found and modified.. (dont know how to figure it out also)

B4X:
Sub AppendImage(cs As CSBuilder, bmp As Bitmap)
    Dim attachment As NativeObject
    attachment = attachment.Initialize("NSTextAttachment").RunMethod("new", Null)
    attachment.SetField("image", bmp)
    Dim attributedString As NativeObject
    attributedString = attributedString.Initialize("NSAttributedString") _
     .RunMethod("attributedStringWithAttachment:", Array(attachment))
    Dim no As NativeObject = cs
    no.RunMethod("appendAttributedString:", Array(attributedString))
End Sub

1. The text on the hexagon should be white.
2. Each item should have an image, with

B4X:
'Dim bmp As Bitmap = LoadBitmapResize(File.DirAssets, "sos.png", 70dip, 65dip, False)
        'AppendImage(eachD, bmp)

Any help will be appreciated!

Thanks,
 
Solution
Use the source code and change this line: lbl.Text = Items.Get(i)
To:
B4X:
XUIViewsUtils.SetTextOrCSBuilderToLabel(lbl, Items.Get(i))

Mashiane

Expert
Licensed User
Longtime User
Awesome, thank you.

Updated HexMenu source

B4X:
Public Sub Update
    bc.DrawRect(bc.TargetRect, xui.Color_Transparent, True, 0)
    Dim h As Int = Min(iv.Height,  iv.Width) 
    Dim r As Float = (h - 6dip) / 6
    UpdatedCenters.Clear
    For i = 0 To Centers.Size - 1
        Dim c() As Float = Centers.Get(i)
        Dim cx As Float = c(0) * r + h / 2
        Dim cy As Float = c(1) * r + h / 2
        Dim lbl As B4XView = labels.Get(i)
        If i <= Items.Size - 1 Then
            'lbl.Text = Items.Get(i)
            XUIViewsUtils.SetTextOrCSBuilderToLabel(lbl, Items.Get(i))
            lbl.SetLayoutAnimated(0, iv.Left + (cx - r), iv.Top + (cy - r), (r  * 2), (r * 2))
            UpdatedCenters.Add(Array As Float(cx, cy))
            DrawCell(cx + 0.5, cy + 0.5, r + 0.5, FillColor, 8dip)
        Else
            lbl.Text = ""
        End If
    Next
    bc.SetBitmapToImageView(bc.Bitmap, iv)
End Sub
 
Upvote 0
Top