Replies: 4 comments
-
If you decide to use a custom theme, you do need to define stylesheets for all widgets you're using (but you can use default appearance options when available, or take a look at Iced's default theme and copy things from there). fn view(&self) -> Element<Message, iced::Renderer<theme::MyOwnTheme>> { And use Iced widgets as usual. In case you really just need to style the |
Beta Was this translation helpful? Give feedback.
-
Hello @brianch, thanks for the response! I had started using a custom theme, then I saw the size of the StyleSheet implementation of text_input 😧 I defined the implementation of Application this way:
But I don't see when applying the method As shown above, I modified the view function with my custom theme. But this way obliges me to modify all the types of the widgets that I use, because otherwise, the return type Also, how to define a style in an individual way ?
But how to do the same thing without touching the |
Beta Was this translation helpful? Give feedback.
-
Oh, if you're only adding a custom style for one widget, you don't need to create a new Correcting myself, I guess a better way to achieve what you want would be to wrap everything in a This is a full example: use iced::widget::{container, text};
use iced::{executor, Length};
use iced::{Application, Color, Element, Settings, Command};
#[derive(Default)]
struct ContainerExample;
#[derive(Debug, Clone, Copy)]
enum Message {
}
#[derive(Default)]
struct MyContainerStyle;
impl iced::widget::container::StyleSheet for MyContainerStyle {
type Style = iced::Theme;
fn appearance(&self, _style: &Self::Style) -> iced::widget::container::Appearance {
iced::widget::container::Appearance {
background: Some(iced::Background::Color(iced::Color::BLACK)),
text_color: Some(Color::WHITE),
..Default::default()
}
}
}
impl Application for ContainerExample {
type Executor = executor::Default;
type Flags = ();
type Message = Message;
type Theme = iced::Theme;
fn new(_flags: ()) -> (ContainerExample, Command<Self::Message>) {
(ContainerExample::default(), Command::none())
}
fn title(&self) -> String {
String::from("Container Style Example")
}
fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
Command::none()
}
fn view(&self) -> Element<Self::Message> {
let hello = text("Hello world").size(40.);
container(hello)
.style(iced::theme::Container::Custom(Box::new(MyContainerStyle)))
.width(Length::Fill)
.height(Length::Fill)
.center_x()
.center_y()
.into()
}
}
pub fn main() -> iced::Result {
ContainerExample::run(Settings::default())
} |
Beta Was this translation helpful? Give feedback.
-
This is what helped me understand how themes work so I'll just post it here, despite the other answers. Just check out the following source code: https://github.com/veloren/Airshipper/blob/master/client/src/gui/widget.rs https://github.com/veloren/Airshipper/tree/master/client/src/gui/style Their code is pretty simple to understand, I think. |
Beta Was this translation helpful? Give feedback.
-
I want to set a background color to my app and set some colors.
Right now, I have a module theme and widget to handle this:
But I get error, and I want to know if there is a better way to do this, because it's not very practical to rewrite all types, even those which don't have custom theme.
Beta Was this translation helpful? Give feedback.
All reactions