-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Classlib: GUI: Support "has-a" GUI objects by calling asView within Layouts #2188
Classlib: GUI: Support "has-a" GUI objects by calling asView within Layouts #2188
Conversation
This would also mean that any ObjectGui subclass can also be placed directly in layouts. |
This breaks usage of nil and numbers to create constant size or flexible spacing between elements. I believe this would be better off as something like:
|
Oh crikey, you're right. I guess, to do it properly, we need an interface for things that can belong to a layout, perhaps |
Nah, it seems overboard to add another "as****" method to support one narrow case. Seems like the logic is just fine being "if we can turn it into a view, then do so, else pass it along". |
If the layout should support numbers, too, then we also need |
It's hard coded into our implementation of the layout classes: https://github.com/supercollider/supercollider/blob/master/QtCollider/layouts/layouts.hpp#L74 I don't really love having that kind of generic typing pushed down to the C++ level, as it's much better done in sclang-lang - but there's not much to be gained by fiddling with it. However: I definitely don't think we can do I suppose the MOST clear way to express this in the Layout code would be something that made explicit the types that were expected, and allowed a chance for trivial .asSomething conversions for each. Something like:
It's a bit pedantic, but it seems like it's the most correct..... |
I would tend to see this as an indication of the message |
@scztt re your "pedantic" variant: it looks like there should be a better and more idiomatic OOP solution. Testing for those properties is a bit upside down. You'd rather implement a message in each of those classes that returns the appropriate thing. e.g. |
I quote: jamshark70 |
@jamshark70
(The last only because making non-View subclasses respond to asView is a common use case) |
maybe add
If that makes sense. |
It's required: arrays are used to attach stretch factors and alignment to views, according to http://doc.sccode.org/Classes/LineLayout.html#*new Oh, that means we'll need Symbol as well. And, Array or SequenceableCollection? |
best is General rule, perhaps:
|
Currently, it is needlessly difficult to use subclasses of
SCViewHolder
in Qt layouts.Qt layouts expect all of the member views to be Qt-native objects. However, "has-a" (rather than "is-a") is a standard way to extend the behavior of an object and there is no compelling reason why Qt layouts should rule this out.
This PR adds
.asView
to the items added into a layout. Normal Qt GUI objects simply return themselves. An SCViewHolder returns the view that is being wrapped. (I also had to add anasView
method to the abstract Layout class, as layouts may be used within other layouts.)Example: See https://github.com/jamshark70/ddwGUIEnhancements/blob/master/LayoutValueSlider.sc
Without the PR, you have to do
LayoutValueSlider().asView
by hand, which is a bit silly.