-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
RFC: Toga API for style-related operations #302
Comments
I personally favor the CSS approach because I believe consistency and familiarity make API's easier to learn. Additionally, I think the complexity of the current API can be helped. If the CSS class implemented
The main purpose would just be to bring back some "simple utility" as well as making those familiar with CSS feel at home :) Of course, I would ultimately like to see stylesheets made possible, which includes having ids and class names for widgets. Maybe not so much for example apps, but for larger scale applications where many widgets will share the same theme colors etc., and most widgets will have custom padding/margin. This leads me to a question: should Toga widgets define their own default styles? For example, |
I really like that proposal @DariusMontez! One CSS style API, but with a simple and consistent syntax would really be optimal. |
I really prefer the "Python" way like. Although it is "odd" compared to commonly use toolkits, I think the whole point is to make Toga exploit Python constructs... setters and getters So 👍 and 👎 BUT, following this same line of reasoning
Or maybe this is just a convenience/exception Now I guess also someone would like to do something like to have this available:
Now regarding
Having used Qt and StyleSheets with Qt AND styling using the direct api I feel I would really like to have:
|
@DariusMontez That's already possible - I was just using the Default widget styles (and platform-specific default widget styles) are both entirely possible, as are style sheets. Default widget styles are a little easier, because we can define them directly on the widgets themselves; stylesheets require an implementation of the CSS selection and cascading module - which is entirely possible, just more work. But that's why I started Colosseum... :-) However, I agree that having default paddings and margins (just as you do in a browser - H1 has a default font, margin, padding, leading, etc) would be desirable. |
@goanpeca To be clear: Is your objection to:
i.e., is it to pushing all the style operations to the style object, or on the The Color approach you describe is already possible (or will be, once the Colosseum 0.2 is finalised). Colosseum 0.2 provides an However, for me, this is probably the biggest reason to stick to So, you could (theoretically) define a "CSS, but disallowing string assignment of colours" style module, and you wouldn't require any changes on Toga itself. You could even mix your CSS styles on one widget with your "no-strings-CSS" styles on a different widget in the same app. |
@freakboy3742 I guess Maybe
Yeah, something like what CSS provide, the
Yes, it makes sense now And feels more clean to do
Interesting and powerful but probably not something we should advice :-p, (or pursue) Are there any use cases in Custom Ahh... maybe we can have a All this talk, really makes me want to help on colosseum, I really want to be able to load and dump CSS files! On Qt you have stylesheets and normal Style objects and they do not update themselves but some things can only be changed via that Style object which is horrible and makes a custom app on Qt use both styles and stylesheets... and it just feels wrong... so wrong! |
@goanpeca I hadn't considered the API overlap with the Any help with Colosseum would be most gratefully accepted :-) The only use case I can think of for a custom style class is to use a completely different layout scheme - for example, someone who wants to do constraint-based layout for widgets, or have a really simple grid-based layout. I don't think it's a big use case, but if Django has taught me anything, it's that if you don't get your architecture clear to start with, you're gonna be fighting it for life. |
My $0.02: I'm in favor of the As a bonus, we can make the properties on All of the above is my opinion, but it seems to be in keeping with the group. |
I support @DariusMontez , it shold be made as simple as possible
|
Closing this on the basis that the "widget.style.{property} = {value}" approach has effectively been implemented in the 0.3 branch. |
This is a request for comment on a design decision we have to make about the APIs exposed by Toga for style-related operations.
The problem
What API should we expose for style-related changes to a widget? Consider the following operations:
These are all relatively common things for a widget toolkit to need to do. There will inevitably be an API on platform backends for supporting these operations.
However, what is the API that the Toga interface layer should expose? We use Colosseum to apply styles - however, the style API is deliberately abstracted so that you can pass in any style object you want. In theory, you could define your own style objects implementing a different layout approach (e.g., constraint-based layout?) I'm not sure if anyone will actually ever want to do this - but the option exists.
But should we force all style operations through the style API? Or should we also expose a more traditional functional interface for style operations? i.e., would you rather see:
label.style.set(font=toga.Font(face='Times New Roman', size=12*pt)
; orlabel.font = toga.Font(face='Times New Roman', size=12*pt)
box.style.set(background_color='#abcdef')
; orbox.background_color = '#abcdef'
box.style.set(display=None, visibility=False)
; orbox.hide()
andbox.visible = False
If we do provide both interfaces, we're faced with some questions:
Which one is the "canonical" definition. If I set the font with CSS, then change the font with a widget API, what happens?
hide()
on a widget, it callshide()
on the style object, which setsdisplay=None
on the style object, which pushes that down to the widget implementation.In documentation and examples, which API do we favour?
I've been going back and forth in my mind about this; I'm torn between the purity and internal consistency of using CSS for all style operations, and the simple utility of having methods like
hide()
available. I'm interested in hearing other opinions.The text was updated successfully, but these errors were encountered: