making some text_svg changes
This commit is contained in:
parent
44e8bc4683
commit
1a2ff0a4bc
|
@ -12,7 +12,15 @@ use tracing::error;
|
||||||
use super::songs::Song;
|
use super::songs::Song;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize,
|
Clone,
|
||||||
|
Copy,
|
||||||
|
Debug,
|
||||||
|
Default,
|
||||||
|
PartialEq,
|
||||||
|
Eq,
|
||||||
|
Serialize,
|
||||||
|
Deserialize,
|
||||||
|
Hash,
|
||||||
)]
|
)]
|
||||||
pub enum TextAlignment {
|
pub enum TextAlignment {
|
||||||
TopLeft,
|
TopLeft,
|
||||||
|
|
|
@ -29,6 +29,7 @@ use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
core::{service_items::ServiceItemModel, slide::Slide},
|
core::{service_items::ServiceItemModel, slide::Slide},
|
||||||
|
ui::text_svg::{self, Font as SvgFont},
|
||||||
BackgroundKind,
|
BackgroundKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -542,33 +543,39 @@ pub(crate) fn slide_view(
|
||||||
responsive(move |size| {
|
responsive(move |size| {
|
||||||
let width = size.height * 16.0 / 9.0;
|
let width = size.height * 16.0 / 9.0;
|
||||||
let font_size = scale_font(slide.font_size() as f32, width);
|
let font_size = scale_font(slide.font_size() as f32, width);
|
||||||
// let font = SvgFont::from(font).size(font_size.floor() as u8);
|
let font = SvgFont::from(font).size(font_size.floor() as u8);
|
||||||
let slide_text = slide.text();
|
let slide_text = slide.text();
|
||||||
// let text = text_svg::TextSvg::new()
|
|
||||||
// .text(&slide_text)
|
// SVG based
|
||||||
// .fill("#fff")
|
let text = text_svg::TextSvg::new()
|
||||||
// .shadow(shadow(2, 2, 5, "#000000"))
|
.text(&slide_text)
|
||||||
// .stroke(stroke(1, "#000"))
|
.fill("#fff")
|
||||||
// .font(font)
|
.shadow(text_svg::shadow(2, 2, 5, "#000000"))
|
||||||
// .view()
|
.stroke(text_svg::stroke(1, "#000"))
|
||||||
// .map(|m| Message::None);
|
|
||||||
// let text = text!("{}", &slide_text);
|
|
||||||
let lines = slide_text.lines();
|
|
||||||
let text: Vec<Element<Message>> = lines
|
|
||||||
.map(|t| {
|
|
||||||
rich_text([span(format!("{}\n", t))
|
|
||||||
.background(
|
|
||||||
Background::Color(Color::BLACK)
|
|
||||||
.scale_alpha(0.4),
|
|
||||||
)
|
|
||||||
.padding(1)])
|
|
||||||
.size(font_size)
|
|
||||||
.font(font)
|
.font(font)
|
||||||
.center()
|
.view()
|
||||||
.into()
|
.map(|m| Message::None);
|
||||||
})
|
|
||||||
.collect();
|
// let text = text!("{}", &slide_text);
|
||||||
let text = Column::with_children(text).spacing(6);
|
// text widget based
|
||||||
|
// let lines = slide_text.lines();
|
||||||
|
// let text: Vec<Element<Message>> = lines
|
||||||
|
// .map(|t| {
|
||||||
|
// rich_text([span(format!("{}\n", t))
|
||||||
|
// .background(
|
||||||
|
// Background::Color(Color::BLACK)
|
||||||
|
// .scale_alpha(0.4),
|
||||||
|
// )
|
||||||
|
// .padding(1)])
|
||||||
|
// .size(font_size)
|
||||||
|
// .font(font)
|
||||||
|
// .center()
|
||||||
|
// .into()
|
||||||
|
// })
|
||||||
|
// .collect();
|
||||||
|
// let text = Column::with_children(text).spacing(6);
|
||||||
|
|
||||||
|
//Next
|
||||||
let text_container = Container::new(text)
|
let text_container = Container::new(text)
|
||||||
.center(Length::Fill)
|
.center(Length::Fill)
|
||||||
.align_x(Horizontal::Left);
|
.align_x(Horizontal::Left);
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::fmt::Display;
|
use std::{
|
||||||
|
fmt::Display,
|
||||||
|
hash::{Hash, Hasher},
|
||||||
|
};
|
||||||
|
|
||||||
use colors_transform::Rgb;
|
use colors_transform::Rgb;
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
|
@ -7,7 +10,7 @@ use cosmic::{
|
||||||
Length,
|
Length,
|
||||||
},
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
widget::{container, responsive, svg::Handle, Svg},
|
widget::{container, lazy, responsive, svg::Handle, Svg},
|
||||||
};
|
};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
|
@ -23,7 +26,18 @@ pub struct TextSvg {
|
||||||
alignment: TextAlignment,
|
alignment: TextAlignment,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
impl Hash for TextSvg {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.text.hash(state);
|
||||||
|
self.font.hash(state);
|
||||||
|
self.shadow.hash(state);
|
||||||
|
self.stroke.hash(state);
|
||||||
|
self.fill.hash(state);
|
||||||
|
self.alignment.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
pub struct Font {
|
pub struct Font {
|
||||||
name: String,
|
name: String,
|
||||||
weight: Weight,
|
weight: Weight,
|
||||||
|
@ -92,6 +106,12 @@ impl Font {
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Color(Rgb);
|
pub struct Color(Rgb);
|
||||||
|
|
||||||
|
impl Hash for Color {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.0.to_css_hex_string().hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Color {
|
impl Color {
|
||||||
pub fn from_hex_str(color: impl AsRef<str>) -> Color {
|
pub fn from_hex_str(color: impl AsRef<str>) -> Color {
|
||||||
match Rgb::from_hex_str(color.as_ref()) {
|
match Rgb::from_hex_str(color.as_ref()) {
|
||||||
|
@ -128,7 +148,7 @@ impl Display for Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq, Hash)]
|
||||||
pub struct Shadow {
|
pub struct Shadow {
|
||||||
pub offset_x: i16,
|
pub offset_x: i16,
|
||||||
pub offset_y: i16,
|
pub offset_y: i16,
|
||||||
|
@ -136,7 +156,7 @@ pub struct Shadow {
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq, Hash)]
|
||||||
pub struct Stroke {
|
pub struct Stroke {
|
||||||
size: u16,
|
size: u16,
|
||||||
color: Color,
|
color: Color,
|
||||||
|
@ -226,12 +246,11 @@ impl TextSvg {
|
||||||
self.fill, stroke, text);
|
self.fill, stroke, text);
|
||||||
|
|
||||||
// debug!(final_svg);
|
// debug!(final_svg);
|
||||||
|
lazy(self.clone(), move |_s| Svg::new(Handle::from_memory(
|
||||||
Svg::new(Handle::from_memory(
|
Box::leak(<std::string::String as Clone>::clone(&final_svg).into_boxed_str()).as_bytes(),
|
||||||
Box::leak(final_svg.into_boxed_str()).as_bytes(),
|
|
||||||
))
|
))
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill))
|
||||||
.into()
|
.into()
|
||||||
})).width(Length::Fill).height(Length::Fill).into()
|
})).width(Length::Fill).height(Length::Fill).into()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue