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

@ -1,17 +1,16 @@
use iced::alignment::{self, Alignment};
use iced::executor;
use iced::keyboard;
use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::{
button, column, container, responsive, row, scrollable, text,
};
use iced::{
Application, Color, Command, Element, Length, Settings, Size, Subscription,
Theme,
};
use iced::{Color, Element, Length, Size, Subscription};
pub fn main() -> iced::Result {
Example::run(Settings::default())
iced::sandbox(Example::update, Example::view)
.subscription(Example::subscription)
.title("Pane Grid - Iced")
.run()
}
struct Example {
@ -35,30 +34,18 @@ enum Message {
CloseFocused,
}
impl Application for Example {
type Message = Message;
type Theme = Theme;
type Executor = executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Message>) {
impl Example {
fn new() -> Self {
let (panes, _) = pane_grid::State::new(Pane::new(0));
(
Example {
panes,
panes_created: 1,
focus: None,
},
Command::none(),
)
Example {
panes,
panes_created: 1,
focus: None,
}
}
fn title(&self) -> String {
String::from("Pane grid - Iced")
}
fn update(&mut self, message: Message) -> Command<Message> {
fn update(&mut self, message: Message) {
match message {
Message::Split(axis, pane) => {
let result =
@ -132,8 +119,6 @@ impl Application for Example {
}
}
}
Command::none()
}
fn subscription(&self) -> Subscription<Message> {
@ -209,6 +194,12 @@ impl Application for Example {
}
}
impl Default for Example {
fn default() -> Self {
Example::new()
}
}
const PANE_ID_COLOR_UNFOCUSED: Color = Color::from_rgb(
0xFF as f32 / 255.0,
0xC7 as f32 / 255.0,