Introduce StyleSheet for Text widget

This commit is contained in:
Héctor Ramón Jiménez 2022-06-29 10:51:01 +02:00
parent c807abdfd7
commit 1dd1a2f97f
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
28 changed files with 183 additions and 87 deletions

View file

@ -54,7 +54,7 @@ mod numeric_input {
use iced_native::text;
use iced_native::widget::button::{self, Button};
use iced_native::widget::text_input::{self, TextInput};
use iced_native::widget::{Row, Text};
use iced_native::widget::{self, Row, Text};
use iced_native::{Element, Length};
pub struct NumericInput<'a, Message> {
@ -95,7 +95,9 @@ mod numeric_input {
for NumericInput<'a, Message>
where
Renderer: 'a + text::Renderer,
Renderer::Theme: button::StyleSheet + text_input::StyleSheet,
Renderer::Theme: button::StyleSheet
+ text_input::StyleSheet
+ widget::text::StyleSheet,
{
type Event = Event;
@ -173,7 +175,9 @@ mod numeric_input {
where
Message: 'a,
Renderer: text::Renderer + 'a,
Renderer::Theme: button::StyleSheet + text_input::StyleSheet,
Renderer::Theme: button::StyleSheet
+ text_input::StyleSheet
+ widget::text::StyleSheet,
{
fn from(numeric_input: NumericInput<'a, Message>) -> Self {
component::view(numeric_input)

View file

@ -89,13 +89,13 @@ impl Program for Controls {
.spacing(10)
.push(
Text::new("Background color")
.color(Color::WHITE),
.style(Color::WHITE),
)
.push(sliders)
.push(
Text::new(format!("{:?}", background_color))
.size(14)
.color(Color::WHITE),
.style(Color::WHITE),
),
),
)

View file

@ -100,13 +100,13 @@ impl Program for Controls {
.spacing(10)
.push(
Text::new("Background color")
.color(Color::WHITE),
.style(Color::WHITE),
)
.push(sliders)
.push(
Text::new(format!("{:?}", background_color))
.size(14)
.color(Color::WHITE),
.style(Color::WHITE),
)
.push(TextInput::new(
t,

View file

@ -180,7 +180,7 @@ impl Application for Example {
pin_button.into(),
Text::new("Pane").into(),
Text::new(content.id.to_string())
.color(if is_focused {
.style(if is_focused {
PANE_ID_COLOR_FOCUSED
} else {
PANE_ID_COLOR_UNFOCUSED

View file

@ -2,7 +2,7 @@ use iced::button;
use iced::futures;
use iced::image;
use iced::{
Alignment, Application, Button, Column, Command, Container, Element,
Alignment, Application, Button, Color, Column, Command, Container, Element,
Length, Row, Settings, Text, Theme,
};
@ -143,7 +143,7 @@ impl Pokemon {
.push(
Text::new(format!("#{}", self.number))
.size(20)
.color([0.5, 0.5, 0.5]),
.style(Color::from([0.5, 0.5, 0.5])),
),
)
.push(Text::new(&self.description)),

View file

@ -89,8 +89,9 @@ mod numeric_input {
impl<Message, Renderer> Component<Message, Renderer> for NumericInput<Message>
where
Renderer: text::Renderer + 'static,
Renderer::Theme:
widget::button::StyleSheet + widget::text_input::StyleSheet,
Renderer::Theme: widget::button::StyleSheet
+ widget::text_input::StyleSheet
+ widget::text::StyleSheet,
{
type State = ();
type Event = Event;
@ -161,8 +162,9 @@ mod numeric_input {
where
Message: 'a,
Renderer: 'static + text::Renderer,
Renderer::Theme:
widget::button::StyleSheet + widget::text_input::StyleSheet,
Renderer::Theme: widget::button::StyleSheet
+ widget::text_input::StyleSheet
+ widget::text::StyleSheet,
{
fn from(numeric_input: NumericInput<Message>) -> Self {
pure::component(numeric_input)

View file

@ -168,7 +168,7 @@ impl Application for Example {
let title = row()
.push(pin_button)
.push("Pane")
.push(text(pane.id.to_string()).color(if is_focused {
.push(text(pane.id.to_string()).style(if is_focused {
PANE_ID_COLOR_FOCUSED
} else {
PANE_ID_COLOR_UNFOCUSED

View file

@ -6,7 +6,7 @@ use iced::pure::{
};
use iced::theme::{self, Theme};
use iced::window;
use iced::{Command, Font, Length, Settings};
use iced::{Color, Command, Font, Length, Settings};
use serde::{Deserialize, Serialize};
pub fn main() -> iced::Result {
@ -155,7 +155,7 @@ impl Application for Todos {
let title = text("todos")
.width(Length::Fill)
.size(100)
.color([0.5, 0.5, 0.5])
.style(Color::from([0.5, 0.5, 0.5]))
.horizontal_alignment(alignment::Horizontal::Center);
let input = text_input(
@ -406,7 +406,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
.width(Length::Fill)
.size(25)
.horizontal_alignment(alignment::Horizontal::Center)
.color([0.7, 0.7, 0.7]),
.style(Color::from([0.7, 0.7, 0.7])),
)
.width(Length::Fill)
.height(Length::Units(200))

View file

@ -433,7 +433,7 @@ impl<'a> Step {
.padding(20)
.spacing(20)
.push("And its color:")
.push(text(format!("{:?}", color)).color(color))
.push(text(format!("{:?}", color)).style(color))
.push(color_sliders);
Self::container("Text")
@ -576,7 +576,7 @@ impl<'a> Step {
.push(if cfg!(target_arch = "wasm32") {
Element::new(
text("Not available on web yet!")
.color([0.7, 0.7, 0.7])
.style(Color::from([0.7, 0.7, 0.7]))
.horizontal_alignment(alignment::Horizontal::Center),
)
} else {

View file

@ -1,7 +1,8 @@
use iced::qr_code::{self, QRCode};
use iced::text_input::{self, TextInput};
use iced::{
Alignment, Column, Container, Element, Length, Sandbox, Settings, Text,
Alignment, Color, Column, Container, Element, Length, Sandbox, Settings,
Text,
};
pub fn main() -> iced::Result {
@ -48,7 +49,7 @@ impl Sandbox for QRGenerator {
fn view(&mut self) -> Element<Message> {
let title = Text::new("QR Code Generator")
.size(70)
.color([0.5, 0.5, 0.5]);
.style(Color::from([0.5, 0.5, 0.5]));
let input = TextInput::new(
&mut self.input,

View file

@ -4,8 +4,8 @@ use iced::scrollable::{self, Scrollable};
use iced::text_input::{self, TextInput};
use iced::theme::{self, Theme};
use iced::{
Application, Checkbox, Column, Command, Container, Element, Font, Length,
Row, Settings, Text,
Application, Checkbox, Color, Column, Command, Container, Element, Font,
Length, Row, Settings, Text,
};
use serde::{Deserialize, Serialize};
@ -155,7 +155,7 @@ impl Application for Todos {
let title = Text::new("todos")
.width(Length::Fill)
.size(100)
.color([0.5, 0.5, 0.5])
.style(Color::from([0.5, 0.5, 0.5]))
.horizontal_alignment(alignment::Horizontal::Center);
let input = TextInput::new(
@ -453,7 +453,7 @@ fn empty_message<'a>(message: &str) -> Element<'a, Message> {
.width(Length::Fill)
.size(25)
.horizontal_alignment(alignment::Horizontal::Center)
.color([0.7, 0.7, 0.7]),
.style(Color::from([0.7, 0.7, 0.7])),
)
.width(Length::Fill)
.height(Length::Units(200))

View file

@ -584,7 +584,7 @@ impl<'a> Step {
.padding(20)
.spacing(20)
.push(Text::new("And its color:"))
.push(Text::new(format!("{:?}", color)).color(color))
.push(Text::new(format!("{:?}", color)).style(color))
.push(color_sliders);
Self::container("Text")
@ -766,7 +766,7 @@ impl<'a> Step {
.push(if cfg!(target_arch = "wasm32") {
Element::new(
Text::new("Not available on web yet!")
.color([0.7, 0.7, 0.7])
.style(Color::from([0.7, 0.7, 0.7]))
.horizontal_alignment(alignment::Horizontal::Center),
)
} else {

View file

@ -92,7 +92,7 @@ impl Application for WebSocket {
let message_log = if self.messages.is_empty() {
Container::new(
Text::new("Your messages will appear here...")
.color(Color::from_rgb8(0x88, 0x88, 0x88)),
.style(Color::from_rgb8(0x88, 0x88, 0x88)),
)
.width(Length::Fill)
.height(Length::Fill)