WPF: Expanders stacked on top of each other where one should be expanded and take all remaining space - animation

I think this is pretty known control but I couldn't find an WPF example/blog on the web. What I need is collection of Expander WPF controls stacked on top of each other just like in StackPanel. Difference though is that Expanders should be collapsed by default and once one of them is expanded it should take all the remaining space. If expanded Expander is in the middle of the stack it should push items below it all the way down to the bottom edge of the parent element. Every expande/collapse action should be animated.
StackPanel as the parent panel for Expanders here is out of the question because it can't give "all remaining space" to its child(ren). DockPanel does this partially but it can do that only for the "last child" and I need to be able to do it for any child.
So what would be the best approach to implement this?

To answer my question, I just found out that controls like this is called Accordion. There are couple of implementations online but I think the most complete is that in WPF Toolkit http://wpf.codeplex.com/

Related

Embedding NSStackView as NSTableCellView in NSTableView

I'm currently working on a prototype for a todo type app. I have a table which contains the user tasks. What I want to do is only present the user with pertinent task information. But to edit additional information, they would click on a disclosure button to expand the cell.
I was thinking of two possible ways to handle this:
Expanding NSTableViewCell
Using an NSStackView as the contents of each cell
If using the NSTableViewCell, I would probably have two NSViews to represent the cell (top part and lower part).
If using the NSStackView, I'd have an easy means of encapsulating the parts.
I suppose another method could also be just building it entirely with NSStackView.
The more difficult aspect of this seems to be related to the actual expansion/collapse of the cell.
I understand this could be deemed the type of question that's asking for an opinion. I've never built a MacOS app. So I'm looking for some guidance as to the best method to approach the problem versus spinning my wheels on approaches that are destined to not be productive.
Thanks!
In the end, it looks like the best thing to do is use an NSTableCellView with two NSViews for the top and bottom half. I had the case of this as well as the NSStackView working. But in the end, I found that using NSStackView to collapse or expand requires a call to make noteHeightOfRows work anyways.
So it would initially seem that it's not worth the effort of expanding it unless I have a more complicated cell where say I wanted a top, middle, and bottom, where the middle could expand and contract. While I would still need to use noteHeightOfRows, it would allow for it.
However, there is one benefit of using the NSStackView. The animation is much smoother for the collapse. I've found the NSTableCellView method with a top and bottom NSView shows signs of "tearing" as it collapses. This is what appears in the bottom edge, while horizontal, jitters. This is particularly apparent if you either spam the button or if the cell is selected because the bottom of the outline can sometimes grow in height.
I also found that when using NSAnimationContext to help make it look a little smoother, I'd see strange behavior. Like the hide would happen at the wrong time (even though it was in the completionHandler. I think the root cause of that are what becomes overlapping animations.

Treeview control in Win32 API - how to display a single treeview item using different fonts?

I'm faced with a problem where I need to display some characters in a tree-view item (those belonging to the Symbol charset) using Symbol font while others in the default System font (Segoi UI on my Windows 7).
Custom draw allows us to draw different items using different fonts, but I would like to draw the same item string using different fonts as it applies to each character in the string as told above.
So, what I've done with not-so-pleasing results w.r.t. drawing performance upon a horizontal scroll when the number of items is more so far is this:
I disabled horizontal scrolling in my tree-view control using TVS_NOHSCROLL style (since I'm using my own scroll bar control inside the tree-view window to handle all horizontal scrolling)
I sub-classed the treeview control and in the sub-classed winproc, I handle the horizontal scroll notification and mouse notification (where I do my own hittesting and send message like TVM_EXPAND and TVM_SELECT as a result of mosue clicks/double-clicks). Also the scroll bar range is set based on how wide my custom drawn string is (the maximum length amongst all items).
I draw the string for each item upon receiving CDDS_ITEMPOSTPAINT using my own fonts for each character in the item.
The above approach (I left out some details for the sake of brevity) works BUT there are some problems which makes me post this question here and look for an alternare way:
Problems:
The horizontal scroll bar control I create is hosted "inside" the tree-view control at the bottom of the tree-view window. However, when the number of items goes beyond what the tree-view client area can accommodate vertically, the last visible tree-view item gets obscured by the scroll bar control. This can be solved by not making the scroll bar a child of the tree-view and hosting it outside the tree-view window just below it. But I don't want to do this since the scroll bar should typically be a child window of the tree-view.
This is the major one. Since I draw the items myself at each horizontal scroll, the drawing performance upon horizontal scrolling is very slow and also leads to flicker upon scrolling.
Any ideas will be much appreciated as I've been grappling with this for the last one week without success.
I can also post the relevant code here if you want to see the approach I took but I'm sure there shoould be a better approach to this and there must be some other people who would've faced this problem and solved it in the past.
Thanks in advance.
Custom-draw allows you to draw items however you want. You are not limited to a single font per item. When you receive the NM_CUSTOMDRAW notification, draw whatever you want on the provided HDC for the specified item. You can draw pieces of text in one font, pieces of text in a different font, etc. Be sure to return CDRF_SKIPDEFAULT so the TreeView itself will not try to draw anything on the item.
#Anurag S Sharma: I tried to edit this into Remy's answer. It's incomplete as is, but addresses your comment/concerns and answers this particularly vexing/useful question...
The problem is that ff I return CDRF_SKIPDEFAULT, Windows does not even draw the +/- buttons (expanding/collapsing) nor the indent lines in the control which I do want Windows to draw. – Anurag S Sharma
To retain the lines, buttons, and icons you can use ExcludeClipRect to mask only the text region and instead of returning CDRF_SKIPDEFAULT, return 0 as if you didn't draw anything. This itself would not be necessary if the text of the tree item was empty, except that the margins of the text will always be drawn by the default handler (note that Microsoft's controls do not always respect clipping shapes, but in this case they do.)
To replicate the classic TreeView label style in your custom draw procedure you need to do something like the following:
HTREEITEM item = (HTREEITEM)p->dwItemSpec;
TreeView_GetItemRect(p->hdr.hwndFrom,item,&p->rc,1);
RECT cr, rc = p->rc; GetClientRect(p->hdr.hwndFrom,&cr);
DrawTextW(p->hdc,text,-1,&rc,DT_CALCRECT|DT_NOPREFIX|DT_NOCLIP);
rc.right+=4; rc.bottom+=2; IntersectRect(&rc,&cr,&rc);
ExtTextOutW(p->hdc,rc.left+2,rc.top+1,ETO_CLIPPED|ETO_OPAQUE,&rc,text,wcslen(text),0);

Do 250 buttons slow the application in WP7?

I'm building a BattleShip game for WP7 that has board with 250 cells. I need to make each cell clickable, so I thought to put in each cell a button and handle each click as I need.
My question is: do 250 buttons slow the phone? If it does, so what are the alternatives?
Hell yes. 250 UI controls are complete utter madness. The alternative, and correct solution, is to use XNA instead, and developing your game as a real game, and not as a bunch of UI controls.
Yes, 250 buttons will make your application quite slow. Silverlight constructs a visual tree to represent your UI. Each button contains a template which generates various broders, rectangles etc ... for representing visual states.
A couple of alternatives are:
Use a more lightweight visual elements, for example Rectangle. These do not have a Click event, so you can handle MouseLeftButtonUp instead.
Probably the most lightweight approach is not to have an element for each cell at all. Simply handle mouse interactions on a parent element, then determine the grid cell from the click location. The MouseEventArgs contain a e.GetPosition() method that allows you to determine where the mouse click occurred.

How to make a Widget slide view with Qt4?

I currently display several widgets (quite large ones, almost screen-wide) on a QStackedLayout, let's call these widgets "pages". Switching from a page to another is done with buttons below (previous, index, next).
I would like pages to slide while switching, as if they were placed on a larger-than-screen row, moving left or right depending on what the user wants.
For this I thought the QScrollArea would be OK, but I can add only one widget to it and I cannot index sub-items to move accordingly nor can I force a per-item-scroll (I don't want the sliding movement to stop between two pages.)
Another option is the QListView or other derivate from QAbstractItemView, but I can't find how to pass a widget as a QListItemModel or other reimplemented QAbstractItemModel. Roles for data are quite limited, and none seem to allow QWidgets.
How can I proceed to achieve this?
It seems using a QScrollArea and scroll programmatically using the inherited scrollContentsBy() would do the trick. The viewport then would be an elongated widget, sliding left or right so one section could be seen at a time.

GTK# - Problem with components overlapping upon resize

I have a panel containing a form (elements such as labels and textboxes within a table) and 3 buttons (in an hbuttonbox) at the bottom-right. If I shorten the panel by dragging the bottom border upwards, the 3 buttons come with it, and lay on top of the other form components, causing messy graphics. I would like the panel to not resize smaller than the bottom edge of the last component within it. Due to employer restrictions, I am not able to show a screenshot of the GUI. I will try to make any clarifications that are asked.
This probably has something to do with some resizing or general size settings on the components, but there are so many options that I'm not sure where to start.
Any ideas for an easy fix to this without getting down into the complicated nest of components? If not, any ideas on where I should start messing with settings?
Thanks!
UPDATE:
Everything is contained in a VBox with 3 cells. Elements in cells (top to bottom): Table, ScrolledWindow, HButtonBox. The ScrolledWindow bottom edge also moves (resizes) with the bottom edge of the panel when resizing, until the panel bottom goes above the whole ScrolledWindow. Then the buttons keep moving up, staying in relation to the panel's bottom edge.
By "form" do you mean you are using a Gtk.Fixed to contain your table and buttonbox? Then that's probably what's going wrong - you should use vboxes and hboxes for your layout. These will resize properly. Fixed layouts are only for exceptional cases.
EDIT:
Other suggestions:
Perhaps the HButtonBox has pack type 'end' instead of 'start'?
You could try playing with the 'fill' and 'expand' packing properties of the VBox's children.
I ended up adding a Height Request to the container, just slightly longer than the part of the scrolled window. This now stops resizing to where the bottom buttons would overlap the components above it. The problem (before the fix) is shown below:

Resources