Text is stretching to a new page rather weirdly - prawn

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

Related

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).

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.

How do I draw a line on a Lazarus form?

I often use a TPanel or TGroupBox to group my form controls.
Now I need to draw just a straight line like the border of a Panel or GroupBox.
How do I do this on LAZARUS?
Thanks in advance!
Note: The technique must work on both Linux and Windows
As an optical line separator you should use either the TBevel component with Shape property set to one of the following values bsTopLine, bsBottomLine, bsLeftLine or bsRightLine depending on which line you currently need and resize it to a smaller size (in your case you can use bsTopLine or bsBottomLine and resize the bevel vertically):
Or you can use a special component called TDividerBevel which except the single line adds to this optical divider also a caption:
Here's what I've finally done but I'm not sure if this is the RIGHT way so I won't accept my answer. If there's someone else who can point out any issues with this, please let me know. I found this pretty straightforward as well :)
Place a TGroupBox on the form.
Leave the Caption property blank. Now it should look like a panel with only borders.
Use the mouse and drag the bottom border towards the top. Now it looks like a line.
Well, I personally think this method is NOT efficient as it would take up more memory space than just a real straight line. Anyway, so far it seems to work for me :)
Here's the screenshot - look towards the bottom (just above the last text box). The only issues is that on the sides of the line, it shows the lines bending. I think I should set the properties correctly than dragging with the mouse.

Setting 100% height on an absolutely positioned element when the content expands past the window size

So after reading Stack Overflow and the web, I've gathered that there are two main tricks to achieving 100% height:
Set height:100% on both the HTML and BODY
Set your element to have either:
height:100%, or
top:0, bottom:0, position:absolute
However, even with those tricks I'm having difficulty setting the height of an absolutely positioned DIV to a true 100%. I can get 100% of the viewport size, but if the user scrolls down at all it becomes apparent that the div doesn't truly have 100% height.
I've made a simple JS Fiddle of the situation here:
http://jsfiddle.net/9FEne/
My question is: does anyone know any further tricks to get a true (ie. content-height, not viewport-height) 100% height absolutely positioned div?
Sorry, I missed the real question before and thought you wanted the window filled. If the issue is that the contents are longer than the window then what you need is to add position:relative to the body. http://jsfiddle.net/9FEne/7/
What is happening is that when you absolutely position something it positions (and sizes) relative to the nearest positioned element. If you don't tell it to position to the body then it will position to the window.
You can use jQuery to achieve this trick
var h = $(window).height();
$('#yourdiv').height(h);
I would use javascript to assign the height and width equal to document's height and window's width respectively; I've modified your jsfiddle to demonstrate it here:
http://jsfiddle.net/9FEne/1/