PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 2024 → Help with Making STATIC Element Responsive
Help with Making STATIC Element Responsive
Started by priv!qr5n441yynq14FM5v56rzn5vp10t+p1z, Oct., 03 2024 1:27 AM - No answer
Posted on October, 03 2024 - 1:27 AM
Hello everyone at PC Soft,

At work, we're currently updating an old proprietary software, and one of the key features we're working on is a chatbox linked to an AI. The AI connection via fetch requests is working successfully, but we're struggling to adapt a `STATIC` element to make it responsive on the screen.

The goal is to dynamically adjust the `STATIC` element’s width and height based on the window size and the content inside it (such as text length). Currently, it seems that the width stays fixed at its initial size, regardless of the window adjustments.

### What we’re trying to achieve:
- **Make the static element's width** adjust based on the window size.
- **Make the static element's height** increase or decrease based on the length of the text content (line wrapping when the width reduces).

### Here’s part of the code we’re using:
Procedure MakeTextResponsive()
// Get the number of elements in the Multiline Zone
nElementCount is int = MZ_ChatTest..Occurrence

// Get the text width based on current window size
INT_TextWidth is int = GetTextWidth()

// Loop through all rows in the Multiline Zone
FOR IndexRow = 1 TO nElementCount
Trace("Row #" + IndexRow)

// We set Text to the static of the index row, if user static is empty then we set it to AI msg
Text is string = MZ_ChatTest[IndexRow].STC_User_MSG
IF Text = "" THEN Text = MZ_ChatTest[IndexRow].STC_AI_MSG

// Calculate word count and required lines
TotalWordCount is int = StringCount(Text, " ") + 1
LineCount is int = TotalWordCount / 6 + 1
nLineHeightNum is int

// Set the height based on line count
SWITCH LineCount
CASE 1: nLineHeightNum = 36
OTHER CASE: nLineHeightNum = 24
END

LineHeight is int = nLineHeightNum
INT_TextHeight is int = LineCount * LineHeight

// Adjust the height and width for both user and assistant messages
IF MZ_ChatTest[IndexRow].STC_User_MSG <> "" THEN
MZ_ChatTest[IndexRow].STC_User_MSG..Height = INT_TextHeight
MZ_ChatTest[IndexRow].STC_User_MSG..Width = INT_TextWidth
ELSE
MZ_ChatTest[IndexRow].STC_AI_MSG..Height = INT_TextHeight
MZ_ChatTest[IndexRow].STC_AI_MSG..Width = INT_TextWidth
END

// Adjust the overall height of the looper row
MZ_ChatTest[IndexRow]..Height = INT_TextHeight + 24
END


Procedure MakeTextResponsive()
// Set the width to a fixed size (you can calculate it based on character length if needed)
INT_TextWidth is int = Min(400, WIN_Test_MultiLineTEXT..Width - 50)


We’ve tried adjusting both the width and height based on the window size and content length, but the `STATIC` elements seem to remain at their initially created width. We would greatly appreciate any insights or suggestions on how to properly handle dynamic resizing for `STATIC` elements.

Thanks in advance for your help!