Simplify theming for Text widget
This commit is contained in:
parent
ce309db37b
commit
4130ae4be9
12 changed files with 116 additions and 122 deletions
|
|
@ -1,25 +1,26 @@
|
|||
use iced_wgpu::Renderer;
|
||||
use iced_widget::{slider, text_input, Column, Row, Text};
|
||||
use iced_winit::core::{Alignment, Color, Element, Length};
|
||||
use iced_widget::{column, container, row, slider, text, text_input};
|
||||
use iced_winit::core::alignment;
|
||||
use iced_winit::core::{Color, Element, Length};
|
||||
use iced_winit::runtime::{Command, Program};
|
||||
use iced_winit::style::Theme;
|
||||
|
||||
pub struct Controls {
|
||||
background_color: Color,
|
||||
text: String,
|
||||
input: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
BackgroundColorChanged(Color),
|
||||
TextChanged(String),
|
||||
InputChanged(String),
|
||||
}
|
||||
|
||||
impl Controls {
|
||||
pub fn new() -> Controls {
|
||||
Controls {
|
||||
background_color: Color::BLACK,
|
||||
text: String::default(),
|
||||
input: String::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,8 +39,8 @@ impl Program for Controls {
|
|||
Message::BackgroundColorChanged(color) => {
|
||||
self.background_color = color;
|
||||
}
|
||||
Message::TextChanged(text) => {
|
||||
self.text = text;
|
||||
Message::InputChanged(input) => {
|
||||
self.input = input;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,60 +49,48 @@ impl Program for Controls {
|
|||
|
||||
fn view(&self) -> Element<Message, Theme, Renderer> {
|
||||
let background_color = self.background_color;
|
||||
let text = &self.text;
|
||||
|
||||
let sliders = Row::new()
|
||||
.width(500)
|
||||
.spacing(20)
|
||||
.push(
|
||||
slider(0.0..=1.0, background_color.r, move |r| {
|
||||
Message::BackgroundColorChanged(Color {
|
||||
r,
|
||||
..background_color
|
||||
})
|
||||
let sliders = row![
|
||||
slider(0.0..=1.0, background_color.r, move |r| {
|
||||
Message::BackgroundColorChanged(Color {
|
||||
r,
|
||||
..background_color
|
||||
})
|
||||
.step(0.01),
|
||||
)
|
||||
.push(
|
||||
slider(0.0..=1.0, background_color.g, move |g| {
|
||||
Message::BackgroundColorChanged(Color {
|
||||
g,
|
||||
..background_color
|
||||
})
|
||||
})
|
||||
.step(0.01),
|
||||
slider(0.0..=1.0, background_color.g, move |g| {
|
||||
Message::BackgroundColorChanged(Color {
|
||||
g,
|
||||
..background_color
|
||||
})
|
||||
.step(0.01),
|
||||
)
|
||||
.push(
|
||||
slider(0.0..=1.0, background_color.b, move |b| {
|
||||
Message::BackgroundColorChanged(Color {
|
||||
b,
|
||||
..background_color
|
||||
})
|
||||
})
|
||||
.step(0.01),
|
||||
slider(0.0..=1.0, background_color.b, move |b| {
|
||||
Message::BackgroundColorChanged(Color {
|
||||
b,
|
||||
..background_color
|
||||
})
|
||||
.step(0.01),
|
||||
);
|
||||
})
|
||||
.step(0.01),
|
||||
]
|
||||
.width(500)
|
||||
.spacing(20);
|
||||
|
||||
Row::new()
|
||||
.height(Length::Fill)
|
||||
.align_items(Alignment::End)
|
||||
.push(
|
||||
Column::new().align_items(Alignment::End).push(
|
||||
Column::new()
|
||||
.padding(10)
|
||||
.spacing(10)
|
||||
.push(Text::new("Background color").style(Color::WHITE))
|
||||
.push(sliders)
|
||||
.push(
|
||||
Text::new(format!("{background_color:?}"))
|
||||
.size(14)
|
||||
.style(Color::WHITE),
|
||||
)
|
||||
.push(
|
||||
text_input("Placeholder", text)
|
||||
.on_input(Message::TextChanged),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into()
|
||||
container(
|
||||
column![
|
||||
text("Background color").color(Color::WHITE),
|
||||
text(format!("{background_color:?}"))
|
||||
.size(14)
|
||||
.color(Color::WHITE),
|
||||
text_input("Placeholder", &self.input)
|
||||
.on_input(Message::InputChanged),
|
||||
sliders,
|
||||
]
|
||||
.spacing(10),
|
||||
)
|
||||
.padding(10)
|
||||
.height(Length::Fill)
|
||||
.align_y(alignment::Vertical::Bottom)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,8 +184,7 @@ impl Sandbox for App {
|
|||
.style(theme::Button::Destructive);
|
||||
|
||||
row![
|
||||
text(&item.name)
|
||||
.style(theme::Text::Color(item.color.into())),
|
||||
text(&item.name).color(item.color),
|
||||
horizontal_space(),
|
||||
pick_list(Color::ALL, Some(item.color), move |color| {
|
||||
Message::ItemColorChanged(item.clone(), color)
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ impl Application for Example {
|
|||
let title = row![
|
||||
pin_button,
|
||||
"Pane",
|
||||
text(pane.id.to_string()).style(if is_focused {
|
||||
text(pane.id.to_string()).color(if is_focused {
|
||||
PANE_ID_COLOR_FOCUSED
|
||||
} else {
|
||||
PANE_ID_COLOR_UNFOCUSED
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use iced::futures;
|
||||
use iced::widget::{self, column, container, image, row, text};
|
||||
use iced::{
|
||||
Alignment, Application, Color, Command, Element, Length, Settings, Theme,
|
||||
};
|
||||
use iced::{Alignment, Application, Command, Element, Length, Settings, Theme};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Pokedex::run(Settings::default())
|
||||
|
|
@ -116,7 +114,7 @@ impl Pokemon {
|
|||
text(&self.name).size(30).width(Length::Fill),
|
||||
text(format!("#{}", self.number))
|
||||
.size(20)
|
||||
.style(Color::from([0.5, 0.5, 0.5])),
|
||||
.color([0.5, 0.5, 0.5]),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(20),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use iced::widget::{
|
|||
};
|
||||
use iced::window;
|
||||
use iced::{Application, Element};
|
||||
use iced::{Color, Command, Length, Settings, Size, Subscription};
|
||||
use iced::{Command, Length, Settings, Size, Subscription};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -209,7 +209,7 @@ impl Application for Todos {
|
|||
let title = text("todos")
|
||||
.width(Length::Fill)
|
||||
.size(100)
|
||||
.style(Color::from([0.5, 0.5, 0.5]))
|
||||
.color([0.5, 0.5, 0.5])
|
||||
.horizontal_alignment(alignment::Horizontal::Center);
|
||||
|
||||
let input = text_input("What needs to be done?", input_value)
|
||||
|
|
@ -467,7 +467,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
|
|||
.width(Length::Fill)
|
||||
.size(25)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.style(Color::from([0.7, 0.7, 0.7])),
|
||||
.color([0.7, 0.7, 0.7]),
|
||||
)
|
||||
.height(200)
|
||||
.center_y()
|
||||
|
|
|
|||
|
|
@ -474,7 +474,7 @@ impl<'a> Step {
|
|||
|
||||
let color_section = column![
|
||||
"And its color:",
|
||||
text(format!("{color:?}")).style(color),
|
||||
text(format!("{color:?}")).color(color),
|
||||
color_sliders,
|
||||
]
|
||||
.padding(20)
|
||||
|
|
|
|||
|
|
@ -82,7 +82,10 @@ impl Application for Example {
|
|||
row![
|
||||
text(label),
|
||||
horizontal_space(),
|
||||
text(value).font(Font::MONOSPACE).size(14).style(color),
|
||||
text(value)
|
||||
.font(Font::MONOSPACE)
|
||||
.size(14)
|
||||
.color_maybe(color),
|
||||
]
|
||||
.height(40)
|
||||
.align_items(Alignment::Center)
|
||||
|
|
@ -102,13 +105,12 @@ impl Application for Example {
|
|||
})
|
||||
.unwrap_or_default()
|
||||
{
|
||||
Color {
|
||||
Some(Color {
|
||||
g: 1.0,
|
||||
..Color::BLACK
|
||||
}
|
||||
.into()
|
||||
})
|
||||
} else {
|
||||
theme::Text::Default
|
||||
None
|
||||
},
|
||||
)
|
||||
};
|
||||
|
|
@ -120,7 +122,7 @@ impl Application for Example {
|
|||
Some(Point { x, y }) => format!("({x}, {y})"),
|
||||
None => "unknown".to_string(),
|
||||
},
|
||||
theme::Text::Default,
|
||||
None,
|
||||
),
|
||||
view_bounds("Outer container", self.outer_bounds),
|
||||
view_bounds("Inner container", self.inner_bounds),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use iced::widget::{
|
|||
button, column, container, row, scrollable, text, text_input,
|
||||
};
|
||||
use iced::{
|
||||
Application, Color, Command, Element, Length, Settings, Subscription, Theme,
|
||||
color, Application, Command, Element, Length, Settings, Subscription, Theme,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ impl Application for WebSocket {
|
|||
let message_log: Element<_> = if self.messages.is_empty() {
|
||||
container(
|
||||
text("Your messages will appear here...")
|
||||
.style(Color::from_rgb8(0x88, 0x88, 0x88)),
|
||||
.color(color!(0x888888)),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue