There is a CTreeCtrl in an arbitrary position on a fixed size CDialog.
Could you please advice how to position this CTreeCtrl in OnInitDialog so that its left, right and bottom sides were touched to the dialog sides, and there was an indent N on top?
I've been experimenting for several hours now, but it doesn't stick correctly to right and bottom:
CRect rect;
GetWindowRect(&rect);
rect.top = N;
m_Tree.MoveWindow(&rect);
I also tried GetClientRect.
I need to get the following:
By far the easiest solution in this case it to just use the inbuilt Dynamic Layout functionality:
Select the control in the IDE.
Set the Sizing Type property to Both.
Set Sizing X and Sizing Y to 100.
Then, as long as your dialog Border property is set to Resizing the tree control will stretch as you wanted:
No coding required as you can see:
Much easier!
Manual Method
But, if you do things manually you need to be sure that you understand what type of coordinates the API calls provide you. Coordinates can be relative:
Screen Coordinates
Client Coordinates
For example:
CWnd::GetWindowRect:
The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.
CWnd::GetClientRect:
The client coordinates specify the upper-left and lower-right corners of the client area. Since client coordinates are relative to the upper-left corners of the CWnd client area, the coordinates of the upper-left corner are (0,0).
CWnd::MoveWindow:
For a top-level CWnd object, the x and y parameters are relative to the upper-left corner of the screen. For a child CWnd object, they are relative to the upper-left corner of the parent window's client area.
Your tree control is a child so when you move it, the coordinates need to be relative to the upper-left corner of the parent window's client area.
Note, there is a handy CWnd::ScreenToClient API to translate from one system to the other. But this is not required in this instance.
Manual Method — Example
Putting it all together:
CRect rct;
GetClientRect(&rct); // The client area of your window (in client coordinates)
rct.top += N; // Adjust the top margin as required
myTree.MoveWindow(&rct); // Now move the child control
Please note that I have not debugged this to verify the code but it conveys the ideas.
Where possible I use the built in dynamic resizing, althought it can be very tricky to work out the sizing values. But in your case it is simple - 100.
I should point out that the above code will manually get it to the right place. But then you have to resize it as the window resizes. Try the Dynamic Layout approach instead.
Related
Is it possible to have the vtkAxesActor small in a corner of the window?
Here is a image of what I currently got and what I would like to have. The colorful axes are the standard axesActor. But I would like the axes in a corner of the window and only there (bottom left in black). They shouldn't move around the window when the view is rotated. Only around their origin.
Is this possible? And if yes, how?
A possible solution is to put the vtkAxesActor into an orientation widget:
widget = vtk.vtkOrientationMarkerWidget()
widget.SetOrientationMarker(axisActor)
widget.SetInteractor(interactor)
widget.SetViewport(0, 0, size, size)
widget.InteractiveOff()
widget.EnabledOn()
The vtkAxesActor location is functional and it's location has a purpose. The anchor point of the AxesActor is the anchor point of the model. This provides context of where any transformations or translations would be calculated from.
Unfortunately the example of the axisActor in the corner you have proposed would only provide context of the orientation of the model and so not part of the standard options.
I find myself in the situation of having to manually draw a rectangle with rounded edges as a background for a horizontal stack view. To create the classic ios "bubble" effect, such as whatsapp chats, where the text is surrounded by a green shape.
I am attaching the code:
var BackgroundStack = new UIView();
BackgroundStack.Frame = new CGRect(0, -20, TopSchedaStack.Bounds.Width,
TopSchedaStack.Layer.Bounds.Height+40);
BackgroundStack.BackgroundColor = UIColor.TertiarySystemGroupedBackgroundColor;
BackgroundStack.Layer.CornerRadius = 20;
TopSchedaStack.InsertSubview(BackgroundStack, 0);
the perplexity lies in "BackgroundStack.Frame ...", I need to wrap the generated element in the "TopSchedaStack" storyboard of the UIHorizontalStackView type, with a gray rectangle. So I create it with the CGRect function but when I have to position it precisely under the object it is horizontally and vertically constrained to the view and centered. I am struggling, I cannot get the width I expect from the stack. In the storyboard file it is positioned one way but when I go to recover its width with:
TopSchedaStack.Bounds.Width or TopSchedaStack.Frame.Width
The value obtained is not what I expect. I expect the stack to be long from the left edge to the right edge of the view, taking away the guidelines. therefore it is an object constrained to the right and left respectively at point 0.
I would like the gray rectangle to cover the portion of the blue rectangle depicted in the image containing the storyaboard project. I'm pretty much going randomly changing values until it comes back, I'm sure I'll succeed sooner or later but I'm convinced it's not the right way to do this. Can you help me?
I have a large triangle that is on top of a small rect. How can I select the rect without first moving the triangle out of the way.
I made a demo here:
https://codesandbox.io/s/w6wr7pmrx5
You need to enable perPixelTargetFind: true on your triangle so that the object's clickable area is determined by the actual object path rather than its bounding box.
http://fabricjs.com/docs/fabric.Object.html#perPixelTargetFind
By default, the anchor for the text element in SVG is at the bottom left, but I want it to be at the top left, since I am also creating a rectangle to act as the background for the text, but it is displayed incorrectly since the text is higher than the rectangle (because rectangle anchor/offset is at the top left). Is there a way to fix this, so both text and rectangle can be drawn at same coordinates and be displayed in the same location.
The dominant-baseline property/attribute worked for me:
svg {
dominant-baseline: hanging;
}
The coordinates (x and y) you supply for text elements is used as the baseline of the text. This makes sense because if there is text with varying font sizes on the same line, you would want their baselines to line up.
There is no "automatic" way to do what you want. SVG elements are always absolutely positioned.
You will just have to move the text down a bit by making the y coordinate a bit larger.
Alternatively, you could add a dy attribute to shift the text down a bit. Or even use a transform attribute to do the same. But using either of those methods wouldn't really be simplifying the process for you.
I am trying to display mouse position on timer. I use winfo_pointerxy(), here is part of the code from my_func():
curr_x, curr_y = mouseFrame.winfo_pointerxy()
curr_x = mouseFrame.canvasx(curr_x)
curr_y = mouseFrame.canvasy(curr_y)
mouseFrame.create_oval(curr_x, curr_y, curr_x + 5, curr_y + 5, fill='green')
start_btn.after(time_interval, my_func)
It seems like I use canvasx() wrong cause it still returns position counted from the left-up corner of the screen.
According to this tkinter reference (which I use constantly)
Because the canvas may be larger than the window, and equipped with
scrollbars to move the overall canvas around in the window, there are
two coordinate systems for each canvas:
The window coordinates of a point are relative to the top left
corner of the area on the display where the canvas appears.
The canvas coordinates of a point are relative to the top left
corner of the total canvas.
If your canvas is against the upper left corner of the window (display) and you have not scrolled the canvas, the two sets of coordinates should be the same.