Wrap text around the image - list

Can a list of Label objects and picture be aligned such a way that if the label has space in the right side it should make use of the full length before wrapping to the next line.
This is because of that fact that I may not have pictures of full height of the pane always.
For shorter images I want to make use of the space at the bottom.Note that the text is a nodelist of label nodes.

Related

how to put text at random position in xaringan

I'm trying to put some text in the slides at certain position on top of other stuffs/plots, is that possible? Here is one scenario, the slide is occupied by pictures and texts, but I like to give one sentence conclusion by a different color on top of them, the text just like a stamp to the slide, it's better if I also can adjust the text orientation, just like in powerpoint or keynote, you can add text at any position and style.

How to check if the length or width of Row in a window is greater than the width of its parent window C++

I wanted to wrap the existing text of checkbox into multiline if the width of row exceeds the width of its parent window. I am not really sure how to do that.
The image I want to show the checkbox string
The image where the string is cropped and only shows if window is resized or maximized
You are going to have a problem with this I am afraid.
The setting for making a checkbox multiline is ES_MULTILINE and if you look here you will see that it states:
To create an edit control using the CreateWindow or CreateWindowEx function, specify the EDIT class, appropriate window style constants, and a combination of the following edit control styles. After the control has been created, these styles cannot be modified, except as noted.
So, it would seem to me that you have three ways forward, depending on what you feel is the best or most elegant for you.
Set your control in the resource editor as multiline anyway. Then it doesn't matter and will wrap. No need to have to change the setting.
Implement the needed functionality to limit the size the window can be reduced to. I can show you how if you are interested. This way, if you set the control resize properties correctly it can resize larger but only reduce down the a known dimension (ie: the dimensions you created it in the resource editor).
Possibly have two controls in the same place, one as multiline and one as single. And when you decide which you want to show, swap the visibility. But I think this is a bad idea, bit of a headache, and not worth the hassle.
IMHO I would do both ideas 1 and 2 and I would happily extend my answer to provide more information.
Update
Having looked at your images and the comments about translations then there is a fourth idea. If you use a third party application to manage the translations and use satellite DLL files then you can adjust the resources on a language by language basis. I sometimes have to make the default width for some windows wider due to their verbose nature.
I have set BS_MULTILINE for the checkbox. The minimum size of the window is fixed but I just want the checkbox to fit in that. I expect it to show at least one word in the same line as other labels and remaining words in second line. So I am checking if the total width of the first row is greater than the width of window then show the string with \r\n in it else show normal string. However, I want to align first line or the first word of the checkbox with the checkbox and remaining words should come below the first word. Currently, the checkbox is in between two lines which looks weird. Is there anyway I can do this?

How to make Tkinter.Label justify correctly

I am having an issue getting the text inside a label to left justify in Tkinter. I have tried using the justify=Tkconstants.LEFT but that doesn't seem to work. I have also tried anchor=Tkcontants.W but that doesn't seem to help either. The text always appears in the center of the label. Here is what I have regarding the label:
LookupOutput = Tkinter.Label(UI,textvariable=User,justify=Tkconstants.LEFT)
LookupOutput.grid(row=5, column=0, columnspan=5, padx=5)
I assume it has something to do with my columnspan but I don't know how to fix it. Does anyone have an idea on how to get this thing to left justify the text?
The proper way to have the text in a label aligned to the left of the widget is with the anchor attribute. A value of "w" (or by using the Tkinter constant W) stands for "west".
LookupOutput = Tkinter.Label(UI,textvariable=User,anchor=Tkconstants.W)
The justify attribute only affects text that wraps.
If that isn't working, the problem might not be with the text in the label. It might be that your label doesn't occupy the space you think it does. An easy way to check this is to give the label a distinctive background color so that you can distinguish the label from its parent.
I notice that you aren't using the sticky attribute when you call grid -- that may also cause problems. By default grid will align a widget in the center of the space allocated to it. If you want it to "stick" to the left side of the space that was given to it, use sticky="w" (or, again, use the Tkinter constant).

Text is stretching to a new page rather weirdly

Not sure if I am missing something but I am wrapping blocks of text around a bounding box. However, when it stretches to a new page, the text continues in the lower middle of the page instead of the top bit.
Not quite sure why and not sure if this is the default behavior of bouncing box since I am specifying x,y coordinates; although I couldn't find such thing in the docs
The code below reflects more or less what I have
pdf.bounding_box([absolute_bounds_left, pdf.cursor], width: absolute_bounds_right) do
pdf.text('Something')
pdf.text('Something else')
if something
pdf.text('Another thing')
...
end
...
end
I realised that if you specify a height option, the overflowing text will flow to the next page at [x,y]. So I realised that the if you do not supply a height, the only thing different is that it will stretch until the end of the page and then behave exactly the same, start at position [x, y].
I searched a bit more into the docs to validate this and indeed there is an example. Sorry no permalink so you have to search for it: http://prawnpdf.org/manual.pdf -> [text/free_flowing_text.rb]
If you notice there is another method, span which solved my free flowing text issue. It also comes with a position which amongst the standard :left, :right and :center it takes a numeric value as an offset on the y axis. See here

How to get correct position in the std::string?

I am creating a custom single line edit control, with a custom font in win32 api on windows 7, the font is not a fixed width font, and I need to move caret according to the mouse click, The edit control is not empty and if I know the horizontal position of the mouse click within the window, how do I calculate the number of characters after which I need to move caret to ?
I really am out of ideas, if it was a fixed width font, I would have divided the horizontal mouse click position with average character width, that would have been simpler, doing the same with not a fixed width font, is prone to errors.
Given that it's a single-line control, you probably don't plan on working with immensely long input (at least normally). That being the case, one possibility would be to just store the character positions in an array (or vector, etc.) Then you can use (for example) a binary search in that array to find character positions. Of course, you can do the same even for longer strings--though it can increase storage requirements quite a bit.
This is a familiar problem. You are in essence trying to do hit testing on text and for that you need the location on the screen of each character of the text.
My preferred strategy is to calculate an array of RECT, one for each character of displayed text. The array needs to be updated when text is added or deleted, but it easily handles single or multiple lines. The function GetCharWidth32 retrieves all the widths for a string of text in a particular font selected into a DC. For single line one call is enough, and calculating the array of RECTs is simple. It's not much harder to do multiline.
Handle the mouse down message, loop through the array and find the right character. A brute force search is plenty fast enough.
This method is simple and easily generalises to a range of similar problems.