Cool way to manage navbar state
This commit is contained in:
parent
e94905c9e6
commit
b26067e531
2 changed files with 24 additions and 10 deletions
|
|
@ -30,7 +30,7 @@ pub fn user_interface() -> iced::Result {
|
||||||
app.run()
|
app.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug,PartialEq)]
|
||||||
pub enum Page {
|
pub enum Page {
|
||||||
Home,
|
Home,
|
||||||
FeedView,
|
FeedView,
|
||||||
|
|
@ -41,12 +41,12 @@ pub enum Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
page: Page,
|
pub page: Page,
|
||||||
current_feed: usize,
|
pub current_feed: usize,
|
||||||
pub current_item: Option<FeedItem>,
|
pub current_item: Option<FeedItem>,
|
||||||
pub item_description: Vec<Content>,
|
pub item_description: Vec<Content>,
|
||||||
pub item_content: Vec<Content>,
|
pub item_content: Vec<Content>,
|
||||||
feed_input: String,
|
pub feed_input: String,
|
||||||
}
|
}
|
||||||
impl Default for State {
|
impl Default for State {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|
|
||||||
|
|
@ -100,12 +100,26 @@ pub fn media_view(state: &'_ ui::State) -> Element<'_, Message> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn navbar (state: &'_ ui::State) -> Element<'_,Message>{
|
pub fn navbar (state: &ui::State) -> Element<Message>{
|
||||||
row!(
|
match state.page {
|
||||||
button("Home").on_press(Message::ChangePage(Page::Home)),
|
Page::Home => {
|
||||||
button("All Items").on_press(Message::ChangePage(Page::AllItems)),
|
row::Row::new().push(
|
||||||
button("Categories").on_press(Message::ChangePage(Page::CategoryView))
|
button("All Items").on_press(Message::ChangePage(Page::AllItems))
|
||||||
).spacing(5).padding(5).width(iced::Fill).into()
|
).push(button("Categories").on_press(Message::ChangePage(Page::CategoryView)))
|
||||||
|
.spacing(5).padding(5)
|
||||||
|
},
|
||||||
|
Page::FeedView => {
|
||||||
|
row::Row::new().push(button("Home").on_press(Message::ChangePage(Page::Home))).spacing(5).padding(5)
|
||||||
|
},
|
||||||
|
Page::AllItems => {
|
||||||
|
row::Row::new().push(button("Home").on_press(Message::ChangePage(Page::Home))).spacing(5).padding(5)}
|
||||||
|
Page::CategoryView => {
|
||||||
|
row::Row::new().push(button("Home").on_press(Message::ChangePage(Page::Home))).spacing(5).padding(5)}
|
||||||
|
Page::Testing => {
|
||||||
|
row::Row::new().push(button("Home").on_press(Message::ChangePage(Page::Home))).spacing(5).padding(5)}
|
||||||
|
Page::ItemView => {
|
||||||
|
row::Row::new().push(button("Home").on_press(Message::ChangePage(Page::Home))).spacing(5).padding(5)}
|
||||||
|
}.into()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue