Adapt to iced pure (stateless widgets)
Signed-off-by: fab <fab@pop-os.localdomain>
This commit is contained in:
parent
23a3102df0
commit
d91f44e410
@ -13,7 +13,7 @@ use iced_native::renderer;
|
|||||||
use iced_native::{Color, Element, Length, Point, Rectangle, Size, Widget};
|
use iced_native::{Color, Element, Length, Point, Rectangle, Size, Widget};
|
||||||
use iced_native::text;
|
use iced_native::text;
|
||||||
use iced_native::alignment;
|
use iced_native::alignment;
|
||||||
|
use iced_native::widget::Tree;
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -262,6 +262,7 @@ where
|
|||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
|
_state: &Tree,
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
_theme: &Renderer::Theme,
|
_theme: &Renderer::Theme,
|
||||||
_style: &renderer::Style,
|
_style: &renderer::Style,
|
||||||
|
25
src/main.rs
25
src/main.rs
@ -4,11 +4,15 @@ mod calendar;
|
|||||||
use calendar::{CalendarMonthView, CalendarParams };
|
use calendar::{CalendarMonthView, CalendarParams };
|
||||||
|
|
||||||
use iced::{
|
use iced::{
|
||||||
Alignment, Column, Row,
|
Alignment,
|
||||||
Container, Element, Length, Sandbox, Settings,
|
Element, Length, Sandbox, Settings,
|
||||||
|
};
|
||||||
|
use iced::widget::{
|
||||||
|
Column, Row,
|
||||||
|
Container,
|
||||||
Button, Text,
|
Button, Text,
|
||||||
};
|
};
|
||||||
use iced::button;
|
//use iced::button;
|
||||||
use iced::theme;
|
use iced::theme;
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
@ -29,28 +33,27 @@ enum Message {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Controls {
|
struct Controls {
|
||||||
prev_button: button::State,
|
|
||||||
next_button: button::State,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Controls {
|
impl Controls {
|
||||||
fn view(&mut self, month_name: &str) -> Element<Message> {
|
fn view(&self, month_name: &str) -> Element<Message> {
|
||||||
Row::new()
|
Row::new()
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.push(
|
.push(
|
||||||
Button::new(&mut self.prev_button, Text::new("<<"))
|
Button::new(Text::new("<<"))
|
||||||
.on_press(Message::PrevMonth)
|
.on_press(Message::PrevMonth)
|
||||||
.style(theme::Button::Secondary),
|
.style(theme::Button::Secondary),
|
||||||
)
|
)
|
||||||
.push(
|
.push(
|
||||||
Text::new(month_name)
|
Text::new(month_name)
|
||||||
.width(Length::Shrink)
|
.width(Length::Fill)
|
||||||
|
.horizontal_alignment(iced_native::alignment::Horizontal::Center)
|
||||||
.size(50),
|
.size(50),
|
||||||
)
|
)
|
||||||
.push(
|
.push(
|
||||||
Button::new(&mut self.next_button, Text::new(">>"))
|
Button::new(Text::new(">>"))
|
||||||
.on_press(Message::NextMonth)
|
.on_press(Message::NextMonth)
|
||||||
.style(theme::Button::Secondary),
|
.style(theme::Button::Secondary),
|
||||||
)
|
)
|
||||||
@ -84,7 +87,7 @@ impl Sandbox for CalendarApp {
|
|||||||
println!("month={}", self.month);
|
println!("month={}", self.month);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
const MONTH_NAMES: [&str;12] = [
|
const MONTH_NAMES: [&str;12] = [
|
||||||
"January",
|
"January",
|
||||||
"February",
|
"February",
|
||||||
@ -96,7 +99,7 @@ impl Sandbox for CalendarApp {
|
|||||||
"August",
|
"August",
|
||||||
"September",
|
"September",
|
||||||
"October",
|
"October",
|
||||||
"Novemeber",
|
"November",
|
||||||
"December",
|
"December",
|
||||||
];
|
];
|
||||||
let content = Column::new()
|
let content = Column::new()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user