Replies: 3 comments 2 replies
-
|
Minor Update: Working on adding a new widget makes me require the need for a new enum variant(say
I am not sure if I have explained well, please pardon for my explanation skills :) |
Beta Was this translation helpful? Give feedback.
-
|
I believe I see what you're saying. Something like: pub enum Tag {
Label(Label),
Box(Box),
Button(Button),
Revealer(Revealer),
Undefined,
}
...
match child {
Tag::Box(box_) => tag.set_child(Some(&box_)),
Tag::Label(label) => tag.set_child(Some(&label)),
Tag::Button(button) => tag.set_child(Some(&button)),
Tag::Revealer(revealer) => tag.set_child(Some(&revealer)),
_ => return Tag::Undefined,
}I can definitely see this being useful at scale. |
Beta Was this translation helpful? Give feedback.
-
|
@bhaumik-tripathi Here is an implementation of the safe way to update the state. pub fn show_hello(factory: &GtkApp) {
let state = Rc::new(Mutex::new(RevealerState { open: false }));
let button = tag_button("storage");
let text = tag_label("storage");
let revealbox = tag_revealer(
"storage",
text.clone(),
2,
RevealerTransitionType::SlideDown,
);
Internal::static_widget(&text, "Hello World");
let rev_clone = revealbox.clone();
Internal::static_button(&button, move || {
Internal::update_revealer(rev_clone.clone(), state.clone())
});
Internal::static_widget(&button, "Open hello world");
let boxx = tag_container("storage", Orientation::Vertical, 2, vec![button, revealbox]);
let margins = vec![(Edge::Top, 20), (Edge::Right, 160)];
let anchors = EdgeConfig::TOP_RIGHT.to_vec();
Chunk::new(
factory.clone(),
"Storage",
boxx,
margins,
anchors,
Layer::Top,
true,
)
.build();
}Using Rc<Mutex<...>> allows ownership of a mutual exclusion to be shared between multiple locations, and it seems to be important to handle it this way. I can't find any other solution other than the aforementioned, so for now, this will be how to handle state: let state = Rc::new(Mutex::new(RevealerState { open: false }));One thing I dont like is: let rev_clone = revealbox.clone(); // cloned once
Internal::static_button(&button, move || {
Internal::update_revealer(rev_clone.clone(), state.clone()) // cloned a second time
});Because I feel as if there may be a bottleneck by having to clone revealbox twice. But once again, it's the only way I could get it to work. This approach works so I'm done messing with it for now. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
hey @drkrssll , I think I might try my hand at trying to implement the reveler widget, though I don't know Gtk much, I was thinking to implement it by polling( continuous loop at every 2 secs), I don't know/haven't written any
asynccode, so I might change the implementation when I get more familiar withasync. Just wanted to know about your opinions, what do you thing, any heads up you would like to mention.Edit: Yup, I didn't look the gtk docs properly, I think it wouldn't require it, let me try before presumming anything further 🤗
Beta Was this translation helpful? Give feedback.
All reactions