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