Comments (5)
Based on the error message, I assume you have a problem with the message types. It expects an Element<Message>
but you are pushing an Element<TimePlotMessage>
. The Message
type of the container, you are pushing your plot to, is from type FerrisMessage
not TimePlotMessage
(If replacing the adding of the ferris image with the plot is the only thing you have changed). The tabs example contains of different message types for each part in the application. These types build a hierarchically structure. You have to wrap your message to the higher message type once your message is bubbling up the structure.
You could add a variant like Plot(TimePlotMessage)
to the FerrisMessage
enum like this:
#[derive(Debug, Clone)]
pub enum FerrisMessage {
ImageWidthChanged(u16),
Plot(TimePlotMessage),
}
Than wrap the message the plot produces in a FerrisMessage
with the map
method of the Element
type like this:
.push(self.chart.view().map(FerrisMessage::Plot))
from iced_aw.
Thanks. That's moved me on a lot, but I forgot to mention that I'd renamed Ferris and everything in it to TimePlot, so the structure looks like this:
pub enum TimePlotMessage {
ImageWidthChanged(u16),
}
It is referenced in update
:
pub fn update(&mut self, message: TimePlotMessage) {
match message {
TimePlotMessage::ImageWidthChanged(value) => self.timeplot_width = value,
}
}
and then in fn content
, where the problem occurs. I think I'm using map wrong:
fn content(&mut self) -> Element<'_, Self::Message> {
let content = Column::new()
. . .
.push(self.chart.view().map(TimePlotMessage::ImageWidthChanged));
and the other step is here:
fn view(&mut self) -> Element<Message> {
let chart = ChartWidget::new(self)
.width(Length::Fill)
.height(Length::Fill);
chart.into()
}
I'm now getting an error about how a function is expected, but what is passed isn't a function. I'm still getting used to passing functions around, and to map
. Many thanks for your help so far, can you help further?
from iced_aw.
Thanks. That's moved me on a lot, but I forgot to mention that I'd renamed Ferris and everything in it to TimePlot, so the structure looks like this:
Than it might be the other side around. What type of message is the element producing, that is created by self.chart.view()
? You have to make sure, that all the elements of the surrounding element (like the column in this example) are producing the same type of message.
fn view(&mut self) -> Element<Message> { ... }
Is this the method signature of your plot view? If so, than it produces the wrong kind of message. Your TimePlotMessage
is part of Message
but Message
is not part of TimePlotMessage
. Therefore you cant wrap a Message
in a TimePlotMessage
which is than wrapped again in a Message
. (Well you could if the TimePlotMessage
has a variant Message::(Message)
, but this adds a nasty loop while processing the message and I wouldn't recommend this).
You could of cause handle every message of your application in only one enum type. But I wouldn't recommend this, as your enum and the update
method of your application will get bigger and bigger over time and becomes nearly unreadable once you have a very large application. Therefore, the tabs
example splits the message into different enums, one for each part of the application.
and then in fn content, where the problem occurs. I think I'm using map wrong:
The map function takes an Fn(A) -> B
as an argument. In other words, you have to provide a function that can map one kind of message to another one. This line of the example:
content.map(Message::Ferris)
Is nothing else than a shorthand of the compiler and is equivalent to (see here):
content.map( |ferris_message| Message::Ferris(ferris_message) )
as the enum variant with unnamed fields can act like a function that creates the enum value.
from iced_aw.
Thanks for that. I'm currently implementing what I want to see in a non-tabbed environment, and will get back to tabs once that's done. But your explanation has helped a lot.
from iced_aw.
The mapping to appropriate messages helped. It is a lot to get my head around, but is working nicely now.
from iced_aw.
Related Issues (20)
- Can't use a PickList on a modal HOT 4
- index out of bounds in Tabs HOT 6
- Grid breaks Scrollable HOT 3
- fail to compile on the newest commit HOT 1
- A way to disable on scroll behavior in number_input HOT 1
- Card close_size extends down right when made larger HOT 2
- Grid is not scrolled together with scrollable content HOT 1
- [BUG] `tabs` panic if placed at application root HOT 3
- Numberinput requires mouse hover for keyboard input HOT 4
- number_input, unable to type non-integer numbers. HOT 4
- Number input doesn't prevent overflow and underflow of the contained value
- Is there anyway to move add margins around a modal's overlay? HOT 3
- Dependabot update to 0.9.1 fails HOT 5
- font_loading example display error
- color_picker、date_picker cannot show button icon HOT 3
- Performance of rust-analyzer HOT 1
- Floating element is drawn higher than main menu HOT 2
- card head_text_color doesn't seem to change color HOT 3
- [Feature Request] Transition animations when switching between tabs HOT 1
- Why does Grid insert spaces between narrow columns to the right of a wider column? (and how to avoid) 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 iced_aw.