Comments (9)
Ah, sorry. I haven't read through all of it yet.
Maybe it makes sense to add a sentences that other cases than the default implementation will be described later.
from relm4.
I think this is what you're looking for: https://aaronerhardt.github.io/relm4-book/book/widget_macro_reference.html#functions
from relm4.
Maybe can you elaborate a little how I can do this in detail? The explanation in the documentation did not help me.
Maybe a concrete example could help. That would be great.
from relm4.
If you want to use a function to initialize a widget you just need to use
property_name = gtk::Scale::with_range(gtk::Orientation::Vertical, 0.0, 100.0, 1.0) { ... }
instead of
property_name = gtk::Scale { ... }
I think gtk::Scale
has no proper setter and getter methods for min and max values so you need to use the constructor function.
from relm4.
Was that explanation helpful or is it still unclear?
from relm4.
Actually it was very easy, after trying it. Probably, I was just a little be confused as it is described in the back with some little text.
For me at least, it would have helped, even more, if there would be something in the running code.
The whole thing is simple enough to be added in the first example.
What about changing the creation of one of the buttons in the first example like this:
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt};
use relm4::{send, AppUpdate, Model, RelmApp, Sender, WidgetPlus, Widgets};
#[derive(Default)]
struct AppModel {
counter: u8,
}
enum AppMsg {
Increment,
Decrement,
}
impl Model for AppModel {
type Msg = AppMsg;
type Widgets = AppWidgets;
type Components = ();
}
impl AppUpdate for AppModel {
fn update(&mut self, msg: AppMsg, _components: &(), _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Increment => {
self.counter = self.counter.wrapping_add(1);
}
AppMsg::Decrement => {
self.counter = self.counter.wrapping_sub(1);
}
}
true
}
}
#[relm4_macros::widget]
impl Widgets<AppModel, ()> for AppWidgets {
view! {
gtk::ApplicationWindow {
set_title: Some("Simple app"),
set_default_width: 300,
set_default_height: 100,
set_child = Some(>k::Box) {
set_orientation: gtk::Orientation::Vertical,
set_margin_all: 5,
set_spacing: 5,
append = >k::Button {
set_label: "Increment",
connect_clicked(sender) => move |_| {
send!(sender, AppMsg::Increment);
},
},
append = >k::Button::with_label("Decrement") {
connect_clicked(sender) => move |_| {
send!(sender, AppMsg::Decrement);
},
},
append = >k::Label {
set_margin_all: 5,
set_label: watch! { &format!("Counter: {}", model.counter) },
}
},
}
}
}
fn main() {
let model = AppModel::default();
let app = RelmApp::new(model);
app.run();
}
And then explain it directly there?
from relm4.
Sounds like a good idea. I will add this to the book. Thanks a lot for your feedback!
from relm4.
I added your example to the book and added some headings to make it more clear: https://aaronerhardt.github.io/relm4-book/book/widget_macro.html
What do you think?
from relm4.
Looks good! Thanks.
from relm4.
Related Issues (20)
- `transient_for` errors in child component HOT 2
- Missing Trait Implementations for `FlowBox` and Potential Conflicts HOT 2
- Resizeable and expandable columns with TypedColumnView HOT 2
- Replace `this` with `model` in factory
- Support `match` at the top root of the widget
- Make #[local_ref] support expressions
- Just tested, weird behavior HOT 1
- OpenDialog : how to select file in root of disk HOT 1
- Add `extend` method for `FactoryVecDeque`
- Add option to disable RelmAction
- GLib-GIO-CRITICAL **: 23:02:38.707: This application can not open files. HOT 1
- Support for `libadwaita::ToolbarView`? HOT 3
- ProgressBar did not show up as expected. HOT 4
- [email protected] depends still on [email protected] HOT 1
- gtk::MessageDialog is deprecated in favor of gtk::AlertDialog HOT 2
- FactoryVecDeque will eventually crash due to memory leaks HOT 5
- All versions after 0.6.2 include libadwaita by default HOT 5
- Allow customizing stack properties
- i want to override window exit event but how can i do HOT 1
- GLib-GObject-CRITICAL on shutdown of app with root SimpleAsyncComponent and AsyncController with adw::PreferencesWindow HOT 1
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 relm4.