Comments (7)
Is there any way to use this in the current version, even if it's an ugly hack? Just trying to change button background colors.
from relm.
Yes, you can always use GTK directly.
Please look here to see an example from the mg
crate.
from relm.
That seems to be working. For whatever reason it would only work if the style_context was for the specific Widget (a gtk::Button) and the name was used to identify the style:
impl Widget for BusButton {
fn init_view(&self, model: &mut BusButtonModel) {
let style_context = self.bus_button.get_style_context().unwrap();
let style = include_str!("../style/bus_button.css");
let provider = CssProvider::new();
provider.load_from_data(style).unwrap();
style_context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
if model.active {
self.add_class("active")
}
}
...
view! {
gtk::Box {
orientation: Vertical,
gtk::ToggleButton {
active: model.active,
sensitive: false,
}
#[name="bus_button"]
gtk::Button {
clicked => Request,
label: &(&model.channel_id + 1).to_string(),
visible: true,
sensitive: model.enabled,
name: "bus-button",
}
}
}
And css:
#bus-button.active {
background-color: #ffa0a0;
}
If I tried using just button
for the CSS selector it didn't work. Is that to be expected?
It would be cool if attribute addition/removal could be bound directly to model attributes. Maybe something like:
view! {
gtk::Button {
class-active: model.active
}
}
So if the boolean is true, the class is added.
from relm.
It is expected that button
does not work: it should be button > label
.
Run with the environment variable GTK_DEBUG=interactive
set to be able to inspect the widgets.
In the Objects tab, click of "Show details" (the bulb icon), choose CSS node
and you'll see a tree of nodes that you can use in your selectors.
Also, the idea of conditional class is interesting, even thought I'll probably use another syntax.
from relm.
Oy. I completely forgot that GTK buttons have a label as their child.
The conditional class bindings was heavily based on how Ember.js handles classes in components. I'm not particular to the syntax, just hoping to cut down on some boiler-plate.
from relm.
Noob here
Yes, you can always use GTK directly.
Please look here to see an example from themg
crate.
I tried following that. However, I couldn't get it to compile with the get_style_context()
method in the init_view
method (I'm pretty sure the api has changed?) so I haven't found out how to finish this aspect
Any tips?
Also, when I use the same entries under the gtk::Entry{<entries>}
I get an error on each of them
I'm using the latest version of rust gtk, and going back a few versions might be difficult
from relm.
@syntapy: The gtk-rs API indeed changed: when that's the case, please ask the questions to gtk-rs people (here's the place for relm questions only).
Anyway, that should work:
fn init_view(&mut self) {
use gtk::{CssProviderExt, StyleContextExt};
let style_context = self.button.get_style_context();
let style = include_bytes!("../style.css");
let provider = gtk::CssProvider::new();
provider.load_from_data(style).unwrap();
style_context.add_provider(&provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
}
from relm.
Related Issues (20)
- Add CI for Windows and OS X
- Bad error message when misusing nested views
- destroy event never called HOT 11
- Confusing error message on empty view! macro
- Why fragile crate is copy in src/vendor? HOT 2
- Comparison to vgtk HOT 1
- Can't run the examples HOT 2
- support for virtualized widget lists? HOT 4
- EventStream panics on emit from another thread HOT 1
- unexpected behavior of nested views in embedded separated component HOT 2
- relm's event don't work when in a busy loop in the gtk GUI thread even if calling process_events HOT 1
- How does one use relm with a TextView? HOT 2
- Create a new instance of a Relm widget HOT 2
- [RFC] Planning the transition to GTK4 (relm4) HOT 7
- 100% cpu use in Widget::run? HOT 1
- Broken description on crates.io HOT 1
- Dynamically create new widgets HOT 2
- Compilation error when using non-Copy types in messages HOT 7
- Nested view! macros use inner view as outer root HOT 1
- Make a clearer error message for View Macro
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 relm.