Introduce Program API

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 05:33:47 +01:00
parent 0524e9b457
commit c22269bff3
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
43 changed files with 1141 additions and 831 deletions

View file

@ -147,51 +147,35 @@ mod rainbow {
}
use iced::widget::{column, container, scrollable};
use iced::{Element, Length, Sandbox, Settings};
use iced::{Element, Length};
use rainbow::rainbow;
pub fn main() -> iced::Result {
Example::run(Settings::default())
iced::run("Custom 2D Geometry - Iced", |_, _| {}, view)
}
struct Example;
impl Sandbox for Example {
type Message = ();
fn new() -> Self {
Self
}
fn title(&self) -> String {
String::from("Custom 2D geometry - Iced")
}
fn update(&mut self, _: ()) {}
fn view(&self) -> Element<()> {
let content = column![
rainbow(),
"In this example we draw a custom widget Rainbow, using \
fn view(_state: &()) -> Element<'_, ()> {
let content = column![
rainbow(),
"In this example we draw a custom widget Rainbow, using \
the Mesh2D primitive. This primitive supplies a list of \
triangles, expressed as vertices and indices.",
"Move your cursor over it, and see the center vertex \
"Move your cursor over it, and see the center vertex \
follow you!",
"Every Vertex2D defines its own color. You could use the \
"Every Vertex2D defines its own color. You could use the \
Mesh2D primitive to render virtually any two-dimensional \
geometry for your widget.",
]
.padding(20)
.spacing(20)
.max_width(500);
]
.padding(20)
.spacing(20)
.max_width(500);
let scrollable =
scrollable(container(content).width(Length::Fill).center_x());
let scrollable =
scrollable(container(content).width(Length::Fill).center_x());
container(scrollable)
.width(Length::Fill)
.height(Length::Fill)
.center_y()
.into()
}
container(scrollable)
.width(Length::Fill)
.height(Length::Fill)
.center_y()
.into()
}