Arrangement of items in HStack from left to right in SwiftUI - swiftui

For my current SwiftUI project, I need to roll my own time pickers, and I want to put three or four ordinary Pickers one after the other in order to let the user choose hours, minutes, seconds, and (locale requiring) AM/PM (and variations on this which are unimportant to my question). My first thought on this is to put the pickers in an HStack. E.g.,
HStack {
Text("H")
Text("M")
Text("S")
}
(And, yes, the Text views are just placeholders.) One problem: HStack orders everything from leading to trailing. For right-to-left languages, this is a problem, since this would result in the pickers being in the wrong order (S M H rather than H M S). How can I force the order items in an HStack to always be from left to right?
Note: I did think of the flipsForRightToLeftLayoutDirection(_:) view modifier, but trying to use this flipped over text, which is definitely not what I want.
Thanks in advance for any help anyone can provide.

It is possible to fix layout direction by explicit environment value
HStack {
Text("H")
Text("M")
Text("S")
}.environment(\.layoutDirection, .leftToRight)

Related

SwiftUI DatePicker and Date wrong timezone, not using the local one

I am implementing a DatePicker in SwiftUI.
#State var dateTime = Date()
DatePicker("Date and time, selection: $dateTime)
However, when I select a date & time there and try to print the result I get a different time.
print(self.dateTime.description(with: .current))
print(self.dateTime)
The idea is that if I select 10:28 PM, the first line with .current returns the selected value, but as a String and the second one returns a completely different value, usually with some hours added which I think it takes by default UTC+0 or something, I am now in GMT+3.
I think I have read a lot of answers in the past hour but nothing exactly about this. Any idea is much appreciated.

How to display long list in SwiftUI?

After noticing that my problem is not a database specific problem, but an UI problem I'm creating this new question here.
I have a SearchBar (source) that is used to filter a dataset from a realm database. This works so far well and fast. But when I want to display the result in a list it's pretty slow.
I've tried different approaches to display the elements. I thought the LazyVGrid could be a good solution for this use case since it doesn't create the view for each element but only when I scroll down and need to display them.
ScrollView {
LazyVGrid{
ForEach(...)
}
}
But this approach was veeeery slow and sometimes my app crashed.
So I switched to the classic approach with List{ ForEach(...){ } }.id(UUID()) that is my current solution. The performance is okay. ~2-3 second for 15.000 elements. Additionally my CPU and memory is increasing extremely for the 2-3 seconds. I'm not using any animations or other stuff. For testing I just used a single line text to represent each element.
I'm looking more for a solution like: Display the first n results immediately. And when I scroll down and really need the other results the view for each element should be created only then.

Unable to make the x-zoom to work when xAxes type is different from 'time'

I'm trying to apply the zooming function on a chart I have on my website.
More or less, the actual code of the chart is the one I added in the following CodePen: https://codepen.io/leonardodaga/pen/eYNZdVV
This example works, but I'm trying to use a different xAxis type (not "time") and to format the xAxis ticks with a callback (now commented in the CodePen):
callback: function (value, index, values) {
return Math.floor(value).toFixed(0) + '.' + (((value - Math.floor(value)) * 12).toFixed(0));
},
Removing type: "time" the zoom ends to work.
Is there something wrong with what I'm doing?
It was my mistake, I was passing the data with a wrong format.
In codepen code above, X and Y data were passed using two different array (the first as labels). I should have passed the XY data as a single, two components array.
There is another codepen in my dashboard (Chart.js Linear Zoom example) that shows the way to beginners like me :-)
Callback for ticks was definitely not the problem.

How to apply conditional formatting (if cell is in another range) to a range of cells

So I have searched through several different questions related to this. None of them seem to be asking exactly what I'm looking for and none of the solutions I've found have worked for me thus far.
I have several columns of data (Player names) where each column's values are generated from a formula in the 2nd row of that column. The 1st row is a header (Game name). This whole range is the collection of which players are willing to play which games. These are columns D-J(ish, the list is dynamically generated with another formula, based on form responses)
I have another range of data where the 1st column is the Player and the 2nd is the player's PREFERRED game. This data is also generated with a formula based on form responses. These are columns A-B.
Here's what I'm trying to do
Using conditional formatting in columns D-J, I want to highlight the player's name if this game (in row 1 of this column) is their preferred game (range A2:B).
I've tried several different variations of VLOOKUPS, MATCHES, and FILTERS in the conditional formatting, but so far nothing has worked. The problem I run into every time is that I can't figure out how to reference the cell that the formatting is applying to, but still have it reference each individual cell over the whole range.
I know I could do this if I applied an individual conditional formatting to each individual cell. However that is a very time consuming and inelegant solution to this issue considering I'm expecting my data range to be much larger in the future. I need a conditional formatting formula that will work across the whole range or , at the very least, for an entire column.
This is a mock of what I'm trying to accomplish:
This is a link to a mock of my sheet so that you can clearly see the data layout and specific formulas I'm using:
https://docs.google.com/spreadsheets/d/1wy1T6dWJwNC_EfdCAbkuxtkJH7y4Cg3x4IyEk6R567M/edit?usp=sharing
use:
=REGEXMATCH(D3, TEXTJOIN("|", 1, FILTER($A$3:$A, $B$3:$B=D$2)))

Applying a formula to all cells in a column, not just one at a time?

In OpenOffice.org Calc, I would like to apply a formula to a column that references a cell from the same row but in a different column. I.e., =C1*48 in cell D1, but I want all cells in column D to do this without having to copy the formula to each one manually. Or another way of saying it, for each cell in C that has a number, I want to fill in the corresponding row-cell in D with a formula value based on that number. So far, all I can see from the documentation is that I'd have to copy/adjust the formula for every new row in the spreadsheet. And since I have 4 such columns that need calculation, this will get to be tiresome. I have little experience with spreadsheets at all, so I'm hoping that my problem is actually very simple, and that I just am looking at the wrong parts of the documentation.
I don't have OpenOffice in front of me, but it tries really hard to be Excel like in many ways, so usually assumptions about Calc based on Excel are fairly close to reality.
In Excel, a formula in cell D1, that points to a cell in C1, is treated as a relative reference - that is, one column back from where I am now. So when that formula is filled into other cells (either by Fill Down, or dragging the little handle in the corner of the cell outline, or by copy-pasting the formula into a range of selected cells) the new formulas are similarly treated, by default, as referring to the cell that is one column back from them, in the same row.
To force a formula to use an absolute reference, one specifies the cell address with a dollar sign - $C$1 will always point to (use) the contents of cell C1, regardless of where the formula ends up. ($C1 and C$1 are alternates that allow one parameter of the address to change in the usual relative sense while fixing the other half in place... this probably isn't important to you yet).
In other words, I'd expect that you can type the formulas in the first row of your OpenOffice Calc sheet and copy them down to the rest of the row, and things will just work.
If you want to extend your range down you can do this by calculating the first 2 cells with your formula and then highlighting them. You now grab the little square on the bottom right of the highlighted area and drag that down, across or both.
If you have a specific cell (e.g. D2) which you wish to have remain in all the cells you extend your range to, then in your 2 initial cell calculations use the following:
Extending Down
=G2*D$2
=G3*D$2
Extending Across
=G2*$D2
=H2*$D2
Extending Down and Across
Use $D$2
From your question it seems that you are trying to apply the same formula on whole row (or column) of cells and show the result on another row (or column).
The best way to do this is to use something called array formulas or array functions (in libre office). This link has very good explanation - https://help.libreoffice.org/Calc/Array_Functions
The way you would implement this in your case is
Type this formula in cell D1
=C1:C30 *48
and press ctrl + shift + enter
The formula now looks like this with the flower braces {..}
={C1:C30 *48}
and the formula gets applied all the way from D1 to D30.
You can even extrapolate the same concept to a whole matrix (for example: A1:C10)
(The way to tell excel/open office/ libre office that you wrote an array formula is to press ctrl + shift + enter. Never press enter as that will break the array function and convert it to a regular function)