How to determine width needed for a button in SwiftUI - swiftui

If I have a string that I will place inside of a SwiftUI button label, how can I determine how much width I need to allow the button to consume such that the text in the button will not be truncated with ellipsis?
This would assume no font size modifier is applied and would take into account the current Dynamic Type size preference.

The fixedSize modifier as mentioned by Asperi works for this.

Related

How to prevent the text within the static control from getting clipped?

I am having a static control in which I am setting some text. When I am trying to set lengthy text in the static control the text is getting clipped.
Can anyone please let me know, how can I prevent the text from getting clipped.
The problem is that a static control always clips a word, that is longer than the width of the control. If you use the SS_LEFT style words are wrapped into the next line. So a higher control would help (I can read in the comments that this is possible).
But the Style must be SSLEFT and not SS_LEFTNOWRAP!
Another solution would be to use a Read Only Edit control without a border In this case you can scroll inside the edit control, because it is possible to give it the focus. Also you are able to use a vertical or horizontal scrollbar.
As long as you don't use WS_TABSTOP you will se no real difference between a read only edit control without a border and a static control. Except that the edit control can be activated with the mouse.
Make the static text control larger than the text you a putting in it. A window draws in its client and non-client space. It clips to its window.
If you're concerned about space on a dialog or form, or, language translation could be a possible issue, then you should consider using a CStatic tool tip. Using a tool tip would allow you to keep the current size for the control and provide a mechanism to display its full text. When the user mouses over the CStatic, a tool tip pops up to display the entire text. It's a compromise I've had to use to balance UI design with space on a dialog.

Scrolling in C++ Builder RadioGroup

I have RadioGroup with many buttons. Now when I add an item, they become smaller and smaller. How is it possible to make them scrollable?
TRadioGroup does not natively support scrolling. However, what you can do instead is the following:
place a TGroupBox on your UI.
place a TScrollBox onto the TGroupBox, set its Align property to alClient, and its BorderStyle property to bsNone.
place a TRadioGroup onto the TScrollBox, clear its Caption property, and set its Left property to -2 and its Top property to -15 (or whatever the TRadioGroup.Font is set to plus a few extra pixels). This positioning is needed because you cannot turn off the TRadioGroup's borders or the space reserved for its Caption.
Tweak the TScrollBox.HorzScrollBar.Range and TScrollBox.VertScrollBar.Range properties so they do not scroll far enough to see the TRadioGroup's right and bottom borders.
This way, the buttons appear as if they are part of the TGroupBox, but with the added scrollbar(s).
RadioGroup->Items->Count
TRadioGroup component doesn't have an embedded scrollbar, but you can put the radio group on a TScrollBox for a similar effect.
You can use the Buttons collection to refer each button, e.g.
RadioGroup->Buttons[0]->Height = 5;
RadioGroup->Buttons[1]->Top = RadioGroup->Buttons[0]->Top + 10;
Anyway a TComboBox could also be a good choice.

QTableWidget show scroll bar

I would like the horizontal scroll bar to appear whenever there is text eliding. Such that the user won't have to resize the whole GUI. How would I do this?
This is what I have coded:
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
ui->tableWidget->resizeColumnsToContents();
I also tried enabling scrollbar to appear always, but scrolling to the very right doesn't do anything.
If I set textElideMode to ElideNone , the text from the 2nd column is partially hidden and no scrollbar appears.
QHeaderView::Stretch will stretch the column width to the available space. Use QHeaderView::ResizeToContents to make the column wide enough to display the content, resulting in a horizontal scroll bar if necessary.
This will have a couple of side effects of which I'm not sure you want them.
There will probably be no more ellipsis in the elided text.
If all of the values in your Hash column are very small, then that column will be very thin, so there might be 'empty' space next to that column.

MFC add scrollbar to CWnd member

I have a member of CWnd class name mywindow
and i want to add to it a scroll-bar.
how i can do it?
i try already to do:
mywindow.EnableScrollBarCtrl(SB_BOTH,TRUE);
it display both Horizontal and Vertical scroll-bars,
but i cannot push the buttons or move the scroll-bars.
i try also after the first command:
mywindow.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);
and it change nothing.
can someone could show me a simple example how to add scroll-bar to this member?
thanks a lot,
Tal
Enabling the scroll bars isn't enough. You have to react to the window messages WM_HSCROLLand WM_VSCROLL. Using the GetScrollInfo method you get the position (value) of the scroll bars and then you draw your window content according to this position.
Look up some scroll bar tutorials such as http://www.codeproject.com/KB/dialog/scrolling_support.aspx . In essence, dwo's comment above is what you need to do - handle those messages and set the virtual client area size.
There must be some 'overflow' before scroll bars became active.
Write some 'sufficiently long' data in your view and the scrollbars will become active (at least, that was my experience time ago).
Usually scroll bars get handled 'automatically' from MFC components like (for instance) text editor or form view. I.e. will became visible when needed also without explicit call EnableScrollBarCtrl ...

Enable scrolling of Appcelerator window with vertical layout

I'm using Appcelerator mobile, and have a window with a vertical layout. The window contains an arbitrary number of stacked labels containing arbitrary text of various lengths. The total text may exceed the size of the window, and roll off the bottom of the screen.
I'd like to make the window scrollable, vertically, so the the user can continue reading to the end of the text. What is the best way to do this? Unless I'm missing it, KitchenSink doesn't demonstrate anything like this. I don't know the height of the various label, as it may vary from invocation to invocation, so absolute positioning won't work (or at least not easily).
I'm tempted to see if I can just stick it in a table.
My existing code looks something like this:
var win =Ti.UI.createWindow({layout: "vertical"});
win.add(Ti.UI.createLabel({text: "long text here", height: "auto"});
win.add(Ti.UI.createLabel({text: "more long text here", height: "auto"});
win.add(Ti.UI.createLabel({text: "even more long text here", height: "auto"});
What you want to do is add a ScrollView (use Ti.UI.createScrollView) to your window and add your labels to that ScrollView.
Documentation for the ScrollView object is here: http://developer.appcelerator.com/apidoc/mobile/1.0/Titanium.UI.ScrollView