How to measure the width of a string using Fable or Feliz in an Elmish app? - f#

In an Elmish app (using Fable and Feliz), I'm trying to create a container (a div) with the exact width as an arbitrary string. Is there a way to measure the width of a string ahead of time (before displaying it)?

Related

iOS Localize/Internationalize Stopwatch or Timer Label

In my iOS app, I have a UILabel representing a stopwatch (ie the label reads 0:00 when it's reset, 0:01 a second after that, 1:01 a minute after that, etc.). I manually format the label so it reads as HH:MM:SS. But, I'm not sure if this format is extensible to all internationalizations; for example, in right-to-left layouts I'm assuming the correct layout would be SS:MM:HH.
I was able to find Apple's internationalization guidelines here and a guide to formatting dates and times here, but neither of those guides say anything about the format of a stopwatch/timer (only the format of a clock time). Are there any specific guidelines (or better yet, APIs) for internationalizing the format of a stopwatch/timer in iOS?

MathJax overarrow too short

I am trying to place an overarrow over a piece of text in MathJax.
I am using a custom font that I declare in the code-
\(\overrightarrow{\style{font-family: mysans, TeX, Arial, sans-serif;}{\text{" + tString + "}}}\)"
It works ok for most letters- for capital W or M , using a couple in a row like "WWW" the overbar is too short.
For lowercase i , using a couple in a row, ie "iii" it is too long. My hunch is that MathJax is using a standard character width size to figure out the length of the overarrow and when the character is much longer or shorter than that size, it calculates the overarrow incorrectly. Is there any way around this?
Thanks!
First off, you generally cannot use custom fonts with MathJax. As the documentation says
Since browsers do not provide APIs to access font metrics, MathJax has to ship with the necessary font data; this font data is generated during development and cannot be generated on the fly. In addition, most fonts do not cover the relevant characters for mathematical layout. Finally, some fonts (e.g. Cambria Math) store important glyphs outside the Unicode range, making them inaccessible to JavaScript.
However, if you are only looking to use custom fonts in text elements, then there is a way to work around this: style the surrounding context and set mtextFontInherit:true for the output jax, cf. e.g. here for HTML-CSS.
Unfortunately, this won't actually help you right now. There's a minor regression in MathJax 2.5 (see this discussion leading to the result you describe). This will be fixed in 2.5.1 and in the mean time you could set noReflows:false for the HTML-CSS output.

Display long text in fixed frame in Corona

so at the moment I have to do an assignment at school which requires me to create a Calculator for mobile devices using Corona, ive got the buttons and display classes to work.
In the display class, Ive created 2 frame (one to display the method and the others for result). The final result im looking for is something like a handheld graphical calculator's UI (Casio fx series..).
Which means you can type in a long and continuous method (the whole text will move toe the left and always show you the END of the method) as you press "=" the calculator will give you the result.
What I've got up to so far is that I created a frame which can fit 2 lines of text for displaying the method, but once you've filled up the frame with numbers, Corona will crop out the end of the string .
so what i'm going to do is by having 2 strings, the 1st one is the main one to store what the user type in (the whole method) I will select the last 10 characters from the main string and save it in the second string and display the second string.
So do you know if there's any code that i can use to select a number of characters from a string ?
You can use the built in LUA method
string.sub (yourString, startIndex , endIndex )
http://pgl.yoyo.org/luai/i/string.sub`

Xterm terminal and resize code

I am in progress of converting a really old 25+ year old application .
It sends an escape sequence to make the SCREEN 132 characters wide...
However it didnt work and i put the XTERM equilivment that seems to work in most cases..
It is
"\x1B[8;50;132t"
Although the screen resizes with success there is an issue
Here is the code that the COBOL program uses to execute the command
pg -f FILETOSHOW
using CALL "SYSTEM" USING BY CONTENT DS-REC
where DS-REC is the above command....
The problem is that although screen resizes data are printed with the previous settings... Calling again the program solves the issue and prints correctly...
Doesnt anybody knows whether i should send another escape code also?
The escape sequence is documented in XTerm Control Sequences, in the "Functions using CSI , ordered by the final character(s)" section, under this line:
CSI Ps ; Ps ; Ps t
It is one of the controls adapted from dtterm, and in particular
Ps = 8 ; height ; width
Resize the text area to given
height and width in characters. Omitted parameters reuse the
current height or width. Zero parameters use the display's
height or width.
It was implemented in xterm in 1996 (patch #18).
Because some users view operations of this sort as a security problem (including resizing the font), a resource windowOps was added in 2003 (patch #174) to allow packagers to change the default behavior. That resource can be modified at runtime using a menu entry, as well as set directly in a user's X resources.
In short, the feature is present in xterm, but may require (simple) configuration changes to use it.
The control sequence to resize the xterm window is a request to the window manager. The window manager may not honor the request, e.g., for tiling window managers it would always fail. Also, because xterm does not change the font-size dynamically, it may fail if the font size is too large to permit 132 columns on the screen. The fixed font probably works for modern large displays (my 1280x1024 monitor can display 60x210 with some slack), but large fonts may not.
When it fails to resize as large as requested, it is the window manager which handles the request: xterm has forgotten by the time the request is completed, and will accept whatever the window manager does.
Do not rely on these escape codes. xterm will not set itself to a size greater than the screen. So given the user has a large-enough font and/or a small-enough screen, he will not get his 132x50 terminal automatically, much less will the automatic sizing do it.
(E.g. lucida console at 15pt on 1024x600 minus a taskbar and WM deco gives me room for 85x28 cells.)
If your program requires such an awkward vt size of 132x50, request it of the user as a prerequisite. Or just make your program actually run on any variable size.

XNA drawing text on screen

Is there a way to draw a long text on the screen using SpriteBatch.DrawString? I mean inserts new lines when comes to the end of the screen.
I'd suggest looking at XNAwiki - TextRendering.
Inserting new lines is something you'd have to calculate yourself it's not something you an do automatically with the XNA framework, but yes it's possible to write code to do that.
One way to do it would be to take the string want to write and to move through it a word at a time an measure it until you get enough words to fill the width of whatever area it is you want to fill. Once you've found that width, you'd either change the Y Position of the string you want to draw and move onto the next line or insert a new line character into the string at that point and start calculating the amount of words that should be on the next line.
A thing to pay attention to is that string manipulation is expensive and generates a lot of garbage so you should try and minimize the amount of times you do something like that. If the text is static and never changes it would be ideal to do this one and never again while the game is running.

Resources