Hi,
I'm using Iced for an application and having trouble getting text to show on Buttons
mod capture;
use capture::{capture_screenshot, screenshot_to_iced_image};
use iced::widget::container::Appearance;
use iced::widget::image::viewer;
use iced::widget::image::Handle;
use iced::widget::{
button, column, container, row, text, Button, Column, Container, Image, Row, Text,
};
use iced::window::Position::Specific;
use iced::{window, Alignment, Application, Command, Element, Length, Sandbox, Settings};
use std::rc::Rc;
pub fn main() -> iced::Result {
let (width, height, raw_pixels_u32) = capture_screenshot().unwrap();
let screenshot = screenshot_to_iced_image(width, height, raw_pixels_u32);
let settings = Settings {
id: Default::default(),
window: window::Settings {
size: (width as u32, height as u32),
position: Specific(0, 0), // Default::default(),
min_size: None,
max_size: None,
visible: true,
resizable: true,
decorations: false,
transparent: false,
always_on_top: false,
icon: None,
platform_specific: Default::default(),
},
flags: screenshot,
antialiasing: Default::default(),
exit_on_close_request: true,
default_font: Default::default(),
default_text_size: Default::default(),
text_multithreading: Default::default(),
try_opengles_first: Default::default(),
};
Counter::run(settings)
}
struct Counter {
value: i32,
screenshot: Handle,
}
#[derive(Debug, Clone, Copy)]
enum Message {
IncrementPressed,
DecrementPressed,
}
impl Counter {
fn new_with_screenshot(screenshot: Handle) -> Self {
Self {
value: 0,
screenshot,
}
}
}
impl Application for Counter {
type Executor = iced::executor::Default;
type Message = Message;
type Theme = iced::Theme;
type Flags = Handle;
fn new(flags: Self::Flags) -> (Self, Command<Message>) {
(
Self {
value: 0,
screenshot: flags,
},
Command::none(),
)
}
fn title(&self) -> String {
String::from("Counter - Iced")
}
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
match message {
Message::IncrementPressed => {
self.value += 1;
}
Message::DecrementPressed => {
self.value -= 1;
}
}
Command::none()
}
fn view(&self) -> Element<Message> {
// let viewer = viewer(self.screenshot.clone())
// .width(Length::Fill)
// .height(Length::Fill);
// let inc_button = Button::new("Incremenet").width(Length::Fixed(20 as f32)).height(Length::Fixed(20 as f32));
// let button = button("Click me to increment")
// .on_press(Message::IncrementPressed);
column![
button("Increment").on_press(Message::IncrementPressed),
text("Test").size(50),
//viewer,
row![
button("Increment")
.on_press(Message::IncrementPressed)
.width(Length::Fixed(80 as f32))
.height(Length::Fixed(30 as f32)),
// inc_button
]
]
.padding(20)
// .width(Length::Fill)
// .height(Length::Fill)
.align_items(Alignment::Center)
.into()
}
}
Regardless of how I initialize the button it looks like this
button("Increment").on_press(Message::IncrementPressed),
text("Test").size(50),
//viewer,
row![
button("Increment")
.on_press(Message::IncrementPressed)
.width(Length::Fixed(80 as f32))
.height(Length::Fixed(30 as f32)),
// inc_button
]
Any idea what I could be doing wrong here?
Thanks!