libgdx - DragAndDrop objects in a scrollable area - drag-and-drop

This is my scenario: I have a scrollable panel full of pieces, and then the rest of the window. I have to be able to scroll up/down this panel and then drag and drop each piece into the main window.
Something like this:
----------------------
| X | |
| X | |
| X | |
| X | |
| | X |
----------------------
X is a piece. Originally they are in the scrollable area and then they'll be dropped on the right view.
I have created an actor for the left panel.
And each piece is another type of actor.
The left panel actor will be a scrollable background full of pieces. My problem is that the drag is always taken by the left panel but I cannot move the piece as all the inputs are taken by the panel.
My left panel actor implements InputProcessor for allowing the scroll and it has a DragAndDrop, but the drag is only recognised by the panel.

Related

Grid with negative margin (top) break my UI

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.

Scroll view with dynamic spacing

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.

Tableau Unable to create Stacked Area Chart

I am trying to create Stacked Area Chart in Tableau.
Workbook is on Public Tableau
Data is left joined via CUSIP, i.e
- excel sheet of CUSIP with interest rates
- excel sheet of CUSIP with date and index ratios
Workbook is filtered by CUSIP, and has a parameter called Principal (integer) which the user can input via adjusting slider, and has calculated field Inflation-Adjusted Principal which is
[Principal] * [Index Ratio]
Now, I am trying to create this type of Area Map from this webpage
But my chart ends up like this (refer tab Inflation-Adjusted Trend). It just adds up everything together.
And if I try to deliberately create an Area Chart, it looks like a bunch of color blocks (refer tab Inflation-Adjusted Trend 2) ... How to fix?
I did a quick check on the range of your [Index Ratio]s:
MAX([Index Ratio]) - MIN([Index Ratio])
For every CUSIP, it's 0.00007.
+-----------+------------------+------------------+
| Cusip | Max. Index Ratio | Min. Index Ratio |
+-----------+------------------+------------------+
| 912828H45 | 1.00760 | 1.00753 |
| 912828TE0 | 1.03779 | 1.03772 |
| 912828SA9 | 1.05443 | 1.05436 |
| 912828QV5 | 1.05888 | 1.05881 |
| 912828PP9 | 1.09097 | 1.09090 |
| 912828NM8 | 1.09431 | 1.09424 |
+-----------+------------------+------------------+
For any line, if your scale is too large, it's going to look like a straight line. Here's a line chart of a single CUSIP's [Inflation-Adjusted Principal]:
Here's that same line chart if I change the axis to not show zero:
The axis now spans from approximately the min to the max, so we can see the detail easily.
All of your [Index Ratio]s are pretty far apart from one another, considering the scale. Here's a shot of another line chart, but this time with a line per CUSIP:
If you're going to group by [CUSIP], your scale is going to be too large to see the detail in the lines in this type of view. This isn't a Tableau problem, it's just the nature of your data. Looks like you're going to need to find another creative way to visualize this, or choose a different aspect of the data to visualize that can tell the same story.

How do I keep a CALayer, sublayer of a CATiledLayer, from changing it's scale after a zoom?

I have a CATiledLayer that is used to display a PDF page (this CATiledLayer is the layer type of my UIView which is a subview of a UIScrollView). I want to add overlay markers on this page. So I add a sublayer to my CATiledLayer. This sublayer again hosts the different marker's layers and acts as a grouping layer.
So graphically, I have: (keep in mind that I have multiple markers which are CALayers also, this is ascii art after all)
pdf page (CATiledLayer)
----------------------
| CALayer |
| +---------+ |
| | +----+ | |
| | |mker| | |
| | +----+ | |
| +---------+ |
| |
----------------------
I have set up the canonical drawLayer:inContext: in my view for drawing the pdf.
When I zoom to have more detail, the pdf gets rendered correctly, but the markers get scaled. No matter what I do to the bounds of the CALayer, my markers always become bigger and appear jagged.
I would like to have the markers always the same size, as when they were initialized and first shown when the view was drawn. Is this possible ? or am I using a wrong approach ? Should I do special drawing for my contained CALayer in the drawLAyer:inContext: message ?
As you see, there are things that I am missing to resolve my problem. Thank you for any help you provide.
The marker is scaling because it inherits the transforms of the superlayer. Create another top level CALayer that contains the markers and other objects you don't want scaled and overlay it on top of CATiledLayer.

Fast, 2 Dimensional Table View

I'm implementing a view for displaying tabular information with 2 axis, but I'm starting to run into performance issues with rendering all the cells.
The view looks something like this:
+------------+-------------+------------+------------+------------+
| | 12.00am | 1.00am | 2.00am | 3.00am |
+------------+---------+---+---+--------+--------+---+-+---+------+
| Category 1 | x | x | x | x | x | |
+------------+---------+-------+-----+-----------+-----+---+------+
| Category 2 | | x | x |
+------------+---------+-------+----+--+--------------------------+
| Category 3 | | x | x | x |
+------------+--+---------------+-------+-------------------------+
Each x marks the center of a cell, or a piece of data in a category that's placed on the timeline. The cell will contain a single text label. When the cell is pressed, I need to know that it was pressed. The x axis will contain 24 markers, and there will be anywhere between 5 & 30 rows of data.
At the moment, I've implemented it using 3 main UIScrollViews; one across the top, one down the side, and then a large one for all the cells. When the large scrollview is scrolled, it updates the contentOffsets of the top and side scrollviews. This seems to work quite well, and it's quite intuitive.
The large scrollView has a number of row views, aligned with the headers in the sidebar on the left. The cells are then slotted into their respective row views, and shifted across the x axis to align relative to the time markers. The data cells do not necessarily line up precisely with the hourly time increments of the x axis.
I've encountered two problems:
It seems to be really slow. In some of these tables, there can be up to 2500 cells. This implies I might need some kind of view re-use strategy.
When two cells are next to each other there's a 2px border, but when it's a single cell on its' own there's a 1px border (The CALayer of each row and cell view has a 1px border drawn).
Some possible naïve solutions to the first problem:
Create one large view for the data cells, throw it into the main UIScrollView and draw everything using Quartz (possibly in a background thread).
Implement a view-reuse strategy and deal with having blank space when the user scrolls around quickly.
Does anyone have any high-level input on the best way to approach this problem? I've not dealt with large amounts of data/views before, so any input would be greatly appreciated.
I created something called DTGridView (available as part of DTKit), intended for this exact purpose (it was for an electronic programming guide for an app over here). So it allows differing widths of cells like you've shown in your diagram.
DTGridView uses one single UIScrollView and calculates the needed positions. It also implements cell reuse (in the same way that UITableView does). In fact if you know how to use a table view, then a DTGridView is pretty similar; It uses a dataSource to collect the data and views, and provides delegate methods (using a gridDelegate property) to notify of certain events.
DTKit contains an example project, which should help you understand how to set a grid up.
Give me a shout if you need any help. I understand the kit as a whole needs some better documenting. :)