rust - Rust - Iced 应用程序上的多个页面
问题描述
Iced GUI 问题(针对多页结构):我有一个应用程序,可以说可能有 10 页。我想要松耦合。
mod login;
pub use login::Login;
use iced::{
button, executor, text_input, Application, Clipboard, Column, Command, Container, Element,
Length, Settings,
};
struct MyWindow {
page: Page,
}
#[derive(Debug)]
pub enum Page {
Login(Login),
}
impl Application for MyWindow {
type Executor = executor::Default;
type Flags = ();
type Message = Page;
fn new(_flags: ()) -> (MyWindow, Command<Page>) {
(
MyWindow {
page: Page::Login(Login {
username: String::from(""),
password: String::from(""),
login_button: button::State::new(),
register_button: button::State::new(),
forgotpass_button: button::State::new(),
}),
},
Command::none(),
)
}
fn title(&self) -> String {
String::from("Iced App")
}
fn update(&mut self, message: Page, clipboard: &mut Clipboard) -> Command<Self::Message> {
match self.page {
Page::Login(_) => Command::none(),
}
}
fn view(&mut self) -> Element<'_, Self::Message> {
match self.page {
Page::Login(_) => {
//adds login view logic
}
}
}
}
fn main() -> iced::Result {
MyWindow::run(Settings::default())
}
我的login.rs
样子:
use iced::button;
#[derive(Debug)]
pub struct Login {
//The username and password values
pub(crate) username: String,
pub(crate) password: String,
pub(crate) login_button: button::State,
pub(crate) register_button: button::State,
pub(crate) forgotpass_button: button::State,
}
pub enum LoginMessage {
LoginPressed,
RegisterPressed,
ForgotPassPresed,
}
我会构造它,以便在每个相应的页面上添加页面逻辑吗?在main.rs
underview()
的匹配项中,我只想调用一个公共函数(例如,init_login()
初始化该页面)。
谢谢
解决方案
推荐阅读
- javascript - TypeError:db.collection 不是函数(Firestore 和 Discord.js)
- winapi - 使用 TextOut char by char 与一次全部渲染水平线时的区别
- css - 如何显示这个 Scss/Sass 值?
- azure - 无法创建外部表
- c# - Word 互操作问题:字符串参数太长
- node.js - 如何在分页的最后一页显示剩余数据?
- python - 如何阻止我的所有项目重定向到特定 URL?
- javascript - React 组件在重新加载时运行 Fetch 调用
- python - 在 Python 中让我们的自定义类支持数组括号 []
- python - Cython 优化缓慢