I have a live code illustration of the issue here, as you can see, there is no space between the h1 and the Grid bellow (i was expecting 12px as i asked for a 24px spacing). If you open the console, you can see that a negative margin put the Grid above the h1, that's what i need to fix.
Am i doing something wrong here? What is the right way to patch it if i want the 24px spacing to be applied correctly with the h1?
I hope we don't have to encapsulate the h1 in a Grid container > Grid item itself.
The spacing attribute sets the spacing between the Grid items inside the Grid container, but not between the item and contaianer sides. So, you end up with:
--------------------------
|---------- ----------|
|| item |<-->| item ||
|---------- ----------|
| ^ ^ |
| | | |
| v v |
|---------- ----------|
|| item |<-->| item ||
|---------- ----------|
--------------------------
But the items are not offset from the sides of the container (depending on the justify and alignItems|Content values of course). This is accomplished by adding padding to the items and a negative margin to the container and adjusting the container width.
The easiest thing to do would be to add a marginBottom to the title style as shown here.
Because of the negative margin and width manipulation, nesting Grid containers can be tricky, though there are some recommendations for how to deal with it. For fine-control, I often set spacing={0} and use the MUI spacing API to implement the spacing between the items when nesting Grids.
Related
Trying to use spacing in a grid that have full width. I'm assuming it should work like gap in css-grid however it gives me extra padding to the right and a horizontal scroll.
It also gives me padding bottom on the last row.
Not sure if gap is supported in Grid2 but that breaks even more.
https://codesandbox.io/s/busy-gwen-yhb7ho?file=/src/App.tsx
The spacing prop works in different ways.
Let me explain it a little bit:
If you add a spacing prop in the Grid component you will add padding on the bottom, right, and left in the first row or top row you can check it by opening the developer tool.
But add padding on every side on the other rows except the top row or first row.
So to add space horizontal or vertical you can use the following props to manipulate spacing.
rowGap
columnGap
rowSpacing
columnSpacing
NOTE: Remember one thing before using gap props and spacing props: gap, rowGap and columnGap will add spaces between divs, rows, columns, and others on the other hand spacing, rowSpacing, and columnSpacing adds spaces on every side top, right, bottom, and left.
These props will allow you to add spcese in your prefered way.
To learn more about the Grid V2 (Grid2) Head over to the Documentation
I'm using ag-grid-community v.25.1.0 with 2-rows header and 5 pinned bottom rows.
I want the grid header to be always at fixed position - even when I scroll to the last data rows of my grid (which are often far below the screen bottom).
Unfortunately this forces me to set 'height = 100vh' for the grid - but then the 5 pinned bottom rows also occupy screen area, so there's too small height left for the data rows (about 10 data rows left when I'm using my 13-inch laptop). See demo #1 at https://codesandbox.io/s/aggrid-issue-demo-j9ls9
And if I do not limit grid height with 100vh - then the pinned bottom rows go ouside the screen together with the data rows (because AgGrid's OWN vertical scrollbar is no more shown) which is OK except for... scrolling down the vertical scrollbar of the grid's container (body tag) moves grid's header outside the screen (although "I want header to be always at fixed position" - see this requirement above!). See demo #2 at https://codesandbox.io/s/aggrid-issue-demo-2-52bo3 - it would be OK if header stayed at fixed position.
If there were no pinned bottom rows - the problem would not exist. But these pinned rows are really necessary in my app; however the fact that they occupy ~33% of the grid's height - is a real problem. Yes, I can make row height smaller (together with the font used to paint the cells) - but that's an ugly workaround, not a real solution. I can also provide users with a possibility to show/hide some of the pinned bottom rows (using several checkboxes) - but this "solution" also smells (besides, in most cases all 5 pinned rows are needed).
Is there any solution? maybe I can adjust header's CSS so that it's Y-coordinate stays strictly fixed? in such case removing 'height = 100vh' would solve my problem...
UPD: maybe it makes sense to describe the difference between demos #1 and #2:
App.css:
added this file to override the ".ag-root-wrapper-body.ag-layout-normal" style - because it had height set to zero
App.tsx:
added import for App.css (see above)
removed div style "height: '100vh'"
index.html:
removed body style "overflow-y: hidden;" (to enable vertical scrollbar which is needed to access last rows after we removed '100vh' above)
I have a label with many lines of text. I want to have 20px of margin on left and right if the screen is small but I do not want it to be bigger than 300px if the screen is big.
What I have tried:
- I choose a label as I want the text to be not scrollable and not selectable
- I have given it Attributes > Lines > 0. To adapt to many lines
- I have given it constraints to top, left and right
I am very new to Xcode. In html I would use something like that css:
.text {
with:90%;
max-width:300px;
}
How could I create a similar effect in Xcode and Swift?
(The left and right constrains works well for me to give a similar effect to the width:90% in a small screen. What I am asking now is how to limit the width of the label if the screen is big. Please, be aware that I am very new to Xcode)
This is where you'd want to use less than and greater than constraints.
Set the following constraints:
width ≤ 300
left ≥ safe area left + 20
right ≥ safe area right - 20
horizontally in container = 0
top = 20
You can add a ≤ or ≥ constraint by selecting the constraint and using the drop down that says "Relation" in the property inspector:
I am trying to create a scrollable dialog box with text and buttons. If the content of the dialog is taller than the scroll viewport, I want the content to all be aligned at the top of the viewport. If all of the content is able to fit within the viewport without scrolling, I want it to be aligned in the center of the viewport.
Img1 : example of how the content should be aligned vertically in the center if the content can fit within the scroll viewport.
Img2: example of how the content should be aligned vertically at the top if the content is too large to all fit within the scroll viewport.
This is the structure of my canvas
Canvas
|
|---Scroll View (contains Scroll Rect component)
|
|---Viewport
| |
| |---Content (contains Vertical Layout Group, Content Size Fitter)
| |
| |---Text (contains Horizontal Layout Group component)
| |
| |---Button (contains Horizontal Layout Group component)
| | |
| | |---Text
| |
| |---Text (contains Horizontal Layout Group component)
|
|---Scrollbar Vertical
I am trying to handle vertical positioning by dynamically calculating the padding in the Vertical Layout Group that is attached to the Content element. When everything should be top-aligned, I set the padding to 10. When everything should be center-aligned, I determine the height of each UI element and set the padding appropriately to cause everything to appear center.
The dialog's text is set by a SetText method which is part of the script that is attached to the canvas. SetText assigns the text for each control in the dialog, and then does all the padding calculations.
The problem is that Unity doesn't seem to calculate each control's dimensions immediately after I assign text. For example, if I set a breakpoint in my code after I assign text to one of the Text controls for the first time, all of the size-related properties are still 0. Then when I assign a new text value, the size-related properties have their values from the first text value that I assigned.
What's the best way to solve this?
I figured out a solution. I changed the pivot's y-value in the Content element from 1 to 0.5. Now Unity centers when necessary and top-aligns when necessary without me having to figure out how to get that code to work.
I'm building a welcome editor for my eclipse rcp application. I want to have two ScrolledComposites sit side by side with a label above each.
Label 1 Label 2
Scrollable 1 Scrollable 2
Now I'm stuck in how to box.
This seems right but now I can't get the layouts and listeners right.
Composite A
Composite A1
Label 1
Scrollable S1
Composite A2
Label 2
Scrollable S2
A1 should set the min Size of Scrollable S1 right? But who sets the size of S1 so that it fills the excess space? The examples I found didn't work right.
BTW putting everything in a GridLayout didn't work either since I couldn't get the cell size.
BTW putting everything in a GridLayout didn't work either since I couldn't get the cell size.
Why would you need the cell size? Just set GridLayoutdata for S1 and S2 to fill the cell. It's simplest to use GridLayoutFactory:
import org.eclipse.jface.layout.GridLayoutFactory;
...
GridLayoutFactory.fillDefaults().applyTo(s1);
GridLayoutFactory.fillDefaults().applyTo(s2);
...
UPDATE: See examples at http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/custom/ScrolledComposite.html
Let's say content of s1 is a Composite c1. Then you use s1.setMinSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT)). Size of A1 is irrelevant.
Have a look at the SWT Snippet for "fixed first column horizontal scroll remaining columns" - although this example is for Tables, it can easily be translated to ScrolledComposites.