Comments (6)
Hey sure I understand and I actually like the Elm Architecture very much, just find it a little overkill if you have to run everything through it. It's good that you can have internal states on widgets though.
from iced.
I'd also be interested in this to support the case where messages can't be cloned: I use an enum for my Message
type, and while the values yielded on button presses are unit variants, some of the other variants contain more complicated data that can't be copied. I could start wrapping things in Arc
, but that adds significantly more work.
from iced.
Thanks for the suggestion!
TextInput
and Slider
take a function so you can capture their new value. Have you tried something like this?
button.on_press(if some_context { Message::A } else { Message::B })
Is there any reason this may not work for your use case? Could you share a bit more about it? Why is a closure necessary?
from iced.
Hey hecrj, the other reason for having a closure is that non-iced functions can be triggered. For instance I could implement a counter like the below and keep all my state in the counter without having to store anything in the App model. Useful for encapsulation of local self contained state (i.e. React Hooks)
fn view(&mut self) -> Element<Message> {
let (count, count_access) = use_istate(|| 0);
Column::new()
.padding(20)
.push(
Button::new(Text::new("Increment"))
.on_press_callback(move || count_accesss.set(count + 1)),
)
.push(Text::new(count.to_string()).size(50))
.push(
Button::new(Text::new("Decrement"))
.on_press_callback(move || count_accesss.set(count - 1)),
)
.into()
}
from iced.
Iced is inspired by Elm and The Elm Architecture.
Basically, state mutations are centralized in update
and view
is a pure function producing a description of the GUI. The whole runtime is built based on the assumption that your view code is pure. This guarantee is what will allow us to build a time travelling debugger in the future!
Hooks (or any kind of mutable callback) are based on side-effects in view code, which is directly against the core foundations of the library.
That said, widgets themselves can have local state, and using something like hooks may be an interesting strategy to track internal state. This should be completely hidden from end-users, though.
from iced.
@dmarcuse After #155, it is possible to have non-cloneable messages by separating your UI interactions from your non-cloneable events. I detailed how to do this here: #155 (comment)
from iced.
Related Issues (20)
- Ctrl+X should cut the selected text to the clipboard HOT 1
- iced_widget no text_editor function HOT 1
- Error when setting a font in the settings of my application HOT 1
- Text in SVGs is not rendered when using wgpu
- iced::theme::Text does not have a function or field for custom themes
- Text truncation by toggling visibility of Text widgets after interaction with PickList HOT 1
- iced freeze for multiple seconds, if many image are added at the same time HOT 1
- no option to load image from memory with non static live time HOT 2
- WebGL Integration example text_input panic '`earlier` cannot be later than `self`'
- tiny-skia does not truncate long text outside of Element when it is inside a Column HOT 2
- border colors problem
- How to use skia at runtime? HOT 1
- `PickList`s inside `Component`s have missaligned popup menus HOT 2
- Widget helper function `scrollable( content )` panics at `tree.rs` ` fn downcast_ref<T>(&self) -> &T` HOT 2
- examples - todo - palette is ambiguous HOT 2
- Black rectangles instead of images when using the wgpu GLES backend HOT 1
- Web/Wasm targetted code does not render text HOT 1
- rust-analyzer never stops scanning the project files HOT 2
- Length::Fill steals all the available space from other widgets HOT 1
- Error when trying to use a custom Theme with the `text_editor` widget HOT 2
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 iced.