add markdown widget
This commit is contained in:
parent
80b7049584
commit
433d64a254
9 changed files with 840 additions and 0 deletions
10
examples/markdown-widget/src/main.rs
Normal file
10
examples/markdown-widget/src/main.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
mod window;
|
||||
|
||||
use cosmic::app::Settings;
|
||||
use window::Window;
|
||||
|
||||
fn main() -> cosmic::iced::Result {
|
||||
let settings = Settings::default();
|
||||
|
||||
cosmic::app::run::<Window>(settings, ())
|
||||
}
|
||||
45
examples/markdown-widget/src/window.rs
Normal file
45
examples/markdown-widget/src/window.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use cosmic::{app::Core, widget, Application, Command};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {}
|
||||
|
||||
pub struct Window {
|
||||
core: Core,
|
||||
markdown_text: String,
|
||||
}
|
||||
|
||||
impl Application for Window {
|
||||
type Executor = cosmic::executor::Default;
|
||||
|
||||
type Flags = ();
|
||||
|
||||
type Message = Message;
|
||||
|
||||
const APP_ID: &'static str = "io.github.elevenhsoft.Markdown";
|
||||
|
||||
fn core(&self) -> &Core {
|
||||
&self.core
|
||||
}
|
||||
|
||||
fn core_mut(&mut self) -> &mut Core {
|
||||
&mut self.core
|
||||
}
|
||||
|
||||
fn init(core: Core, _flags: Self::Flags) -> (Self, cosmic::app::Command<Self::Message>) {
|
||||
let markdown_text = include_str!("../markdown.md").to_string();
|
||||
|
||||
(
|
||||
Self {
|
||||
core,
|
||||
markdown_text,
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn view(&self) -> cosmic::prelude::Element<Self::Message> {
|
||||
let md = widget::text::markdown(self.markdown_text.clone());
|
||||
|
||||
widget::row().push(widget::scrollable(md)).into()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue