Losing functionality with iced::pure::widget::Scrollable compare to iced::widget::Scrollable #1435
-
I'm building a GUI with a log window where I want the scrollable to pin to bottom, with the regular Scrollable, this seems to be done via the scrollable::State struct. However, since the pure widget doesn't have a State struct that I manage, there doesn't seem to be way to pin the scrollable to the bottom Also since I implemented the iced::pure::Application trait, I tried to wrap a impure scrollable in some interior mutability and somehow return a iced::pure::Element, but there doesn't seem to be a way to make that conversion Please help, I'm new to iced. Is there a better alternative for what I'm trying to do? Or have I just missed something, and pin to bottom is actually doable with pure Scrollable? Here's my current scrollable code, it works, but it doesn't automatically scroll to bottom when new response is added #[derive(Debug, PartialEq, Eq, Clone)]
pub enum ResponseViewMessage {
AddResponse(Result<Response, Error>),
}
#[derive(Debug, Default, PartialEq, Eq, Clone)]
pub struct ResponseView {
responses: Vec<Result<Response, Error>>,
}
impl ResponseView {
pub fn view(&self) -> Element<ResponseViewMessage> {
let mut column =
Column::new().height(Length::Shrink).width(Length::Fill);
for resp in &self.responses {
column = match resp {
Ok(resp) => {
column.push(Text::new(resp.to_string()).color(Color::BLACK))
}
Err(err) => column.push(
Text::new(err.to_string())
.color(Color::from([1f32, 0f32, 0f32])),
),
}
}
Scrollable::new(column).into()
}
pub fn update(
&mut self,
msg: ResponseViewMessage,
) -> Command<ResponseViewMessage> {
match msg {
ResponseViewMessage::AddResponse(response) => {
self.responses.push(response);
}
}
Command::none()
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You will need to use the new widget operations (introduced in #1399). Specifically, the |
Beta Was this translation helpful? Give feedback.
You will need to use the new widget operations (introduced in #1399). Specifically, the
scrollable::snap_to
operation.