Comments (7)
Do you have a proposal how this should look like in the end, i.e. how code using it would ideally look like? The main problem here seems to be that it's not a direct property of the widget, but you need to get a reference to its style context and then add the class to that.
from gtk3-rs.
I see two approaches:
In-Builder
Widget builders could inherit a trait that configures an internally-managed Option<StyleContextBuilder>
. The builder could contain a SmallVec<[GString; 4]>
for storing each class added.
let widget = WidgetBuilder::new()
.add_class("class1");
.add_class("class2")
.build();
In-Widget-Builder
And/or widgets could provide a method with the following signature:
Fn(&self, mut func: FnMut(&StyleContext)) -> &Self
Which would allow it to be used like so, in combination with similar methods (ContainerExt::add).
widget
.style_context(|ctx| {
ctx.add_class("class1");
ctx.add_class("class2");
})
.add(&widget1)
.add(&widget2)
from gtk3-rs.
The problem with directly adding it on the builder (option 1) is that it then moves methods of contained objects to the top-level object. Sooner or later that's going to cause problems with naming conflicts :)
The second option sounds reasonable to me. @antoyo ?
from gtk3-rs.
I like that idea very much (actually, I thought of something similar for a relm
rewrite).
However, I think it's out of scope of the builders though: they were meant to add type safety for constructing objects, not to go declarative everywhere (even though I would like that).
So, I think it should be outside gtk-rs
.
One idea I had was to create and implement traits on the builders themselves to add such kind of feature.
That trait would need its own build()
method that would call the original builder's build()
method.
I think this would work, but I did not test that idea.
@sdroege:
please tell me if I'm wrong: that's my own conception of the builders, but maybe we want to go declarative or something (I'd like that, actually).
from gtk3-rs.
I think you're right and this seems to go too far away from plain bindings to a higher-level API. The builders as they are seem acceptable as they only expose the concept of construct-only properties that already exists in GObject. Making them more generic to also allow for arbitrary other "construction operations" seems to be too much for bindings.
from gtk3-rs.
I guess it can be closed then?
from gtk3-rs.
GTK4 has a add_css_class
, remove_css_class
, set_css_classes
& has_css_class
at Widget level and I don't think as well that the bindings should offer more than the bindings themselves
from gtk3-rs.
Related Issues (20)
- Unexpected plug-added event for socket realized HOT 2
- could not find system library 'gio-2.0' required by the 'gio-sys' crate HOT 6
- [BUG] Wrong return turn (u32 vs gint) for GtkNotebook append_page HOT 3
- Update to wayland-client 0.30
- [HELP] Using GTK_STOCK_REMOVE HOT 2
- the procedure entry point _divmoddi4 could not be located in the dynamic link library D:\msys32\mingw32\bin\libglib-2.0-0.dll HOT 1
- [HELP] STATUS_ACCESS_VIOLATION when right clicking an Entry widget HOT 3
- [BUG] gtk fails to compile on mispel HOT 1
- [HELP] What is best way to show error message and then close application on panic?
- Quoting C documentation regarding the use of Rust methods is not helpful HOT 2
- [BUG] Dialog and clipboard examples are dead links
- Gtk::Inhibit has been removed in very recent versions. Documentation says it's still there. HOT 5
- [HELP] How do I get the width and height of the current screen? HOT 3
- [BUG] window.rs has two fn "screen" HOT 2
- [HELP] Clipboard: missing connect_owner_change function?
- [HELP] Make a desktop widget using GTK3 bindings
- [HELP] Why doesn't the merge PRs? HOT 1
- [HELP] Access gtk_sys::GtkWidget from gtk::GtkToggleButton HOT 2
- [BUG] Unexpected lines in `cairo_threads` example running on HiDPI display
- [BUG] The examples don't compile due compilation error on atk v0.19.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtk3-rs.