How to get touch pointer inside a specific Grid - windows-phone-7

I have a layout like the following:
grid-1
grid-2
grid-3
...
one nested inside of another.
Within Grid-3, there are 10x10 matrix of images. What I'd like to know is how do I know a touch is within grid-3 and which image is touched? I read the example from eBook and code:
primaryTouchPoint.TouchDevice.DirectlyOver == txtblk
I tries to use it with my grid-3 name, the touch pointer only at the very top line of grid-3. And I don't want to write 100 line of if-else statement for each image. And also when I use
grid-3.Width, actualWidth, these method all return 0. How do I know the size of this grid-3 on screen?
-Henry

One way would be to wrap each image inside a control that has a click event, like a button. Point all the click event handlers to a single method and grab the child image from this.

Related

Draggable and swipable container in flutter

I'm new to flutter and I'm looking for a way to implement a simple feature. A draggable container.
I have two groups of UI elements wrapped in a Container widget. I want to be able to go from one group to another by dragging or swiping in different directions.
How would I go about doing this?
Here are sample images of my UI design to help you understand what I want to achieve:
Image #1
Image #2
As you can see, Image #1 and Image #2 are only different in the bottom part of my design. I have already created all the necessary UI elements and wrapped them in the Container widget. Now the only thing I need is the ability to go from one group to another. It would also be nice if there was a callback method that could update the buttons above upon transitioning from one group to another.
Thanks in advance!
There are many possibilities to achieve this, depends on your exact wishes, here are 3 ideas:
Using a TabBarView to swipe the entire screen, Tab1 will be the first screen you showed, and Tab2 will be second screen - only the contents. (you probably did not want that, but just putting it out there).
Dividing the container into 2 pieces (vertically), and placing the TabBarView on the bottom part, having 2 tabs: 1 with the Today part and one with the Weekly part. (there are a few examples out there, for instance: divide screen into two equal parts in flutter).
You can also customize the build method to change anything (for example the top indicator) based on the current tab index (as asked and answered here: How to get current tab index in Flutter)
For a more custom solution you can use:
GestureDetector wrapped around your container, and handle OnHorizontalDragX (where X is Start, End etc.) to do any custom stuff - maybe changing the state and trigger a rebuild with the new image

How to fix overlapping objects on the stage in AS3

I have a flash game where I have a picture designed to be the textbox for a prompt and textbox inside with the relevant text but the textbox is being hidden by the image. Anyone know how to make is so that the textbox is guaranteed to be on top or whatever I need to do to keep this from happening?
The other answer using setChildIndex will definitely work, however, I think a different design approach is really what you should be doing to remove the headache altogether.
For example in a game I might have different layers such as :
backgroundLayer
gameLayer
interfaceLayer
Those 3 Sprite layers would get added to the stage in that order. I would then add display objects to the appropriate layers. So anything I added to the backgroundLayer or gameLayer would ALWAYS be 'behind' my user interface on the interfaceLayer.
That allows you to not have to worry about the layering constantly. The answer with setChildIndex will fix the problem for that moment, but should something else be added to the container it will overlap your textbox, which is something I don't assume you want.
here's an example :
var backgroundLayer:Sprite = new Sprite;
var gameLayer:Sprite = new Sprite;
var interfaceLayer:Sprite = new Sprite;
addChild(backgroundLayer);
addChild(gameLayer);
addChild(interfaceLayer);
now, whatever you add to interfaceLayer, will ALWAYS be on top of objects you add to gameLayer or backgroundLayer.
So in the case of your text box, just add it to your interfaceLayer and any other objects you want behind it, you add to the gameLayer or backgroundLayer.
The order of adding display objects to display object containers effect their z-order, in other words the front to back order. The last added display object becomes the frontmost. So the child index of the children of a display object container is important for drawing of overlapped children.
If you put picture and text on the same DisplayObjectContainer such as a MovieClip:
Lets say your DisplayObjectContainer is mc.
And your textbox is txt
Please try this:
mc.setChildIndex(txt, mc.numChildren-1);

Any way to trigger a callback function while hovering over a point in Matlab?

I am using a while loop and within that I add ginput in MATLAB to capture the positions of mouse. I check every time if the returned position is within some area so I will plot some curve on the current figure. But the problem is, by using ginput, I have to press enter before the positions are returned. Is that any way to capture the mouse event such that when the current cursor hover over some points, a callback function will be triggered? Thanks.
Since you already have a figure you're using, you could set the listening property for the figure:
set(gcf,'WindowButtonMotionFcn', #mouseMoveListener);
But now you have to create a function called 'mouseMoveListener' (if you want to name it something else, change the words after the # sign to whatever name you want, and make sure the actual event function is named that too).
Within your function mouseMoveListener you can now get the mouse coordinates:
MousePos = get(mainAxis,'CurrentPoint');
Which tells the current point of the mouse with respect to the axes coordinates. From there, you can have whatever if statement check that the position is where you want it and perform whatever tasks you want based on that information.

How to retrieve a mean number into matlab GUI from cell string?

I am building a matlab GUI to retrieve an average PnL number from a 1047*1 double cell string called pnl_P1 into edit text window called (function Average_PnL_Pair_1_Callback(hObject, eventdata, handles)). What is the simplest or very simple way to do this?
Do you want mean(cellfun(#str2double, pnl_P1))?
If I understand your problem correctly I'd do the following.
Do not store numbers in cell string array, but if you must, use mean(cell2mat(pnl_P1)) to get the mean value. Create a value under handles so you can reach your pnl_P1 vector from anywhere.
handles.pnl_P1 = pnl_P1;
Make sure you always update your handles after each function in your GUI. It is strongly recommended.
% Update handles structure
guidata(hObject, handles);
Insert value into edit box:
set(handles.edit1,'String',mean(cell2mat(handles.pnl_P1)));
handles.edit1 is the tag handle for the edit box you want to update.
What is the tag for your edit box?
Simple: in guide right-click on your edit box, select properties inspector, scroll down to Tag. If it says edit1 then use handles.edit1 and so on.
If you are new to Matlab GUIs I recommend this. They have stopped updating it but it's a great learning source.
I hope this helps.

How do you add UI inside cells in a google spreadsheet using app script?

I'd like to add buttons to specific cells in Google docs spreadsheet. The apps script UI documentation talks about how to add a new panel, but it's not clear how UI in that panel could be attached to specific rows or cells.
Is it possible to add UI to particular cells, or are we limited to adding new panels?
The apps UI only works for panels.
The best you can do is to draw a button yourself and put that into your spreadsheet. Than you can add a macro to it.
Go into "Insert > Drawing...", Draw a button and add it to the spreadsheet.
Than click it and click "assign Macro...", then insert the name of the function you wish to execute there. The function must be defined in a script in the spreadsheet.
Alternatively you can also draw the button somewhere else and insert it as an image.
More info: https://developers.google.com/apps-script/guides/menus
Status 2018:
There seems to be no way to place buttons (drawings, images) within cells in a way that would allow them to be linked to Apps Script functions.
This being said, there are some things that you can indeed do:
You can...
You can place images within cells using IMAGE(URL), but they cannot be linked to Apps Script functions.
You can place images within cells and link them to URLs using:
=HYPERLINK("http://example.com"; IMAGE("http://example.com/myimage.png"; 1))
You can create drawings as described in the answer of #Eduardo and they can be linked to Apps Script functions, but they will be stand-alone items that float freely "above" the spreadsheet and cannot be positioned in cells. They cannot be copied from cell to cell and they do not have a row or col position that the script function could read.
Use checkboxes(say, in F1) instead of buttons/Images. This is a intermediate to a full ui inside cells. Then hook your function, that is supposed to run on button click to onEdit() trigger function.
Sample script:
function onEdit(e){
const rg = e.range;
if(rg.getA1Notation() === "F1" && rg.isChecked() && rg.getSheet().getName() === "Sheet1"){
callFunctionAttachedToImage();
rg.uncheck();
}
}
References:
Class Range
Event Objects
Buttons can be added to frozen rows as images. Assigning a function within the attached script to the button makes it possible to run the function. The comment which says you can not is of course a very old comment, possibly things have changed now.
There is a silly trick to do something that might help you :
You can make the drawing object as tall as your sheet (To appear to every row in the sheet).
You can make the script affects the current cell value by the following code:
SpreadsheetApp.getActiveSpreadsheet().getActiveCell().setValue(cellValue);

Resources