I write RSSReader in Smalltalk so I have two Model classes: RSSModel (title, entries) and EntryModel (title, image, content, date)
I have list of EntryView (inherits from UI.View) now I have RSSView and my displayOn method is going to display entries vertically with gap between each:
| dy iView gap |
gap := 5.
dy := 0.
1 to: model entries size
do:
[:i |
iView := EntryView model: (model entries at: i).
iView displayOn: aGC at: 0 # dy.
dy := dy + 89 + gap]
and the result is:
I am not sure if I do it right way so If you have better solution for display RSSView please tell me.
Questions:
How to get height of entry? Now I write dy:=dy+89+gap where 89 is hardcoded height of entry.
How to enable scrollbars to scroll entries in window?
How to get the height of the entry? Use:
"entry bounds height"
How to enable scrollbars?
To answer this, I'll first point out that the way you're getting the EntryView's displayed isn't really the best way. You want to create a custom control like I explained in your other question How to create a window in smalltalk. You can use a CompositeView for the view and add each of the EntryViews into the composite using add:at:.
Once you have that, you can go to the Details tab in the UIPainter property editor of the view and turn on Vertical scroll bars.
Related
I want to put the same legend top center of the chart. Legend items will be dynamic, likes sometimes 2,5 or 9, etc.
So, it should take space dynamically like how it is acting on the bottom.
I tried with inset functionality but it seems this is not looking better like the bottom one.
and there are few more complexity like I want it like a flat, so now if I define step size 3 then maybe, for now, it looks good for 9 items. but when there will be 2 items, it will show as a list!!
Although I solved that problem through the following solution:
// get parent elements
let parentEle = d3.selectAll("#chartID svg");
let childrenEle = parentEle
//Convert selection to selection representing the children
.selectAll(function () { return this.childNodes; })
.filter('g');
// putting legends position on TOP
d3.select(childrenEle._groups[0][2]).attr('transform', 'translate(0, 5)');
you have to keep eye on chart width - height and according to this, you may have to control padding in TOP for the chart.
might be this is not a good solution but it works fine for me :D
I use Autolayout for a fairly complex Menu and really need it. All Buttons, UIViews etc. of my Menu are in a separate UIView called "menuSubview".
If the user presses a button the whole "menuSubview" shifts to another position to reveal other parts of the menu. Sometimes the buttons in the menuSubview move as well. I always save the "Menu State" (with Userdefaults in the get-set variable "lastMenu") and have a function to set the alphas and centers according to the saved "Menu State".
I tried calling the "openLastMenu" function in viewDidAppear, viewDidLayoutSubview - all the "viewDid" functions of the ViewController. The "menuSubview" center and alphas of the buttons always behave as expected... but the centers of the buttons simply won't - no matter what "viewDid" I call the function in.
(the code is a lot more complex - I boiled it down to debug and state my point)
override func viewDidAppear(animated: Bool) {
if lastMenu != nil {openLastMenu()}
}
func openLastMenu(){
menuSubview.center.x = view.center.x //works
menuSubview.center.y = view.center.y + 200 //works
button1.center.x = view.center.x - 50 //why you no behave???
button2.center.x = view.center.x + 50 //why you no behave???
button3.alpha = 0 //works
button4.alpha = 0 //works
}
For debugging I even made a button Subclass to fetch the "center" values with a "didSet" if they change. Seems like after taking the correct values they change once more to their Autolayout-Position.
...oh and ignoring the constraints with "translatesAutoresizingMaskIntoConstraints" on the buttons always fucks up the whole menu. I'm starting to get crazy here :)
If you position views using autolayout, any changes to the frame, like what you do here with the center property, will be ignored.
What you need to do is identify the constraints that are you need to change to move the views in the desired position. Example:
You want to move button1 50 points to the left of view.center. Assuming view is the superview of menuSubview, you would
1) deactivate the the constraint responsible for button1's horizontal placement. How you do this mainly depends on whether you created the constraints in code or Interface Builder. The latter will require you to create outlets for some of the constraints.
2) create a new constraint between button1's centerX anchor and view's centerX anchor with a constant of -50, like so (iOS 9 code)
button1.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor, constant: -50.0).active = true
I'd like to increase the size of an SVG icon that's displayed inside of a PySide/Qt table cell
icon = QtGui.QIcon('icon.svg')
entry = QtGui.QTableWidgetItem()
entry.setIcon(icon)
entry.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
table.setItem(row_index, column_index, entry)
Absolutely nothing I try increases the size of the displayed SVG. It is currently displayed as a very small icon and also seems to ignore the alignment. The QIcon docs say that items can be scaled, so there must be a way.
What am I doing wrong?
You should add table.setIconSize(QSize(w, h) (if you use QTableWidget) and entry.setSizeHint(QSize(w, h), docs here, like so:
table.setIconSize(QSize(50, 50))
icon = QtGui.QIcon('icon.svg')
entry = QtGui.QTableWidgetItem()
entry.setSizeHint(QSize(50, 50))
entry.setIcon(icon)
entry.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
table.setItem(row_index, column_index, entry)
The alignment cannot be changed I'm afraid (maybe is doable customizing QTableWidget class). If alignment is a must maybe you can use QTableWidget.setCellWidget(), see this answer.
I have a case where I have to add figures in another figure, i.e., nested figures.
My figure which will contain other figure extends org.eclipse.draw2d.Figure.
I want to change the height of this figure when it contains more than 4 figures, so that all the nested figures are visible at once.
So, in the paintFigure(Graphics graphics) method, I do this:
Rectangle r = getBounds();
if( getChildren().size() > 4 ) {
setBounds(new Rectangle(r.x, r.y, r.width, r.height + getChildren().size()-4)*10));
}
But this doesn't change the height. Well it does change it, for the time being, but when it is called again the next time, it again has the previous height, not the updated one.
Hence, visually the figure height doesn't change at all.
Any ideas on what am I doing wrong?
Or to do this in a different and/or better way?
I was updating the height in the paintFigure(), it was changing to previous height because it was taking values from the model. I changed the height in the model, and it worked fine.
I'd like to have the same behavior of special items as it's done in the Things application. I mean Logbook and Trash items in the bottom part of the Sidebar:
Logbook and Trash items are in the most bottom http://tinyurl.com/lhctza
Please advise any way to implement the same functionality in the sidebar tree.
I feel that special ‘spacer’ tree item should be used together with outlineView:heightOfRowByItem: method.
However, I can't find how to calculate the total height of all visible items (incl. space between groups).
You might try simply having two outline views: One of fixed height, pinned to the bottom of their superview, and the other of variable height, with its bottom immediately above the top of the first. The fixed-height outline view would contain those Logbook and Trash items, and the variable-height outline view would contain all the others.
The tricky part would be making this play nice with a scroll view, but I think you could do it. I imagine you'd put them both in a fully-resizable NSView and make that the scroll view's document view.
I've decided to hardcode the solution by adding 8 pixels of height for every root item in group style.
So, the code looks like this:
- (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item;
{
if (![item isSpacer]) return [ov rowHeight];
static const CGFloat ADDITIONAL_SPACE = 8.0f;
NSUInteger numberOfRootGroups = 2;
CGFloat heightOfRows = [ov rowHeight] * ([ov rowForItem:item] + 1)
+ ADDITIONAL_SPACE * numberOfRootGroups;
CGFloat heightOfSidebar = [[ov superview] frame].size.height;
return MAX(0.0f, heightOfSidebar - heightOfRows);
}
Thanks to everybody for support!