Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Aug 8, 2023
1 parent f8bdc68 commit b9de40a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
26 changes: 16 additions & 10 deletions gui/ui/examples/design-system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod section;

use iced::widget::{button, column, container, row, scrollable, text, Space};
use iced::{executor, Application, Command, Length, Settings, Subscription};
use liana_ui::{component::text::*, image, theme, widget::*};
use liana_ui::{component::text::*, font, image, theme, widget::*};

pub fn main() -> iced::Result {
let mut settings = Settings::with_flags(Config {});
Expand All @@ -21,11 +21,18 @@ struct DesignSystem {

#[derive(Debug, Clone)]
pub enum Message {
FontLoaded(Result<(), iced::font::Error>),
Event(iced::Event),
Section(usize),
Ignore,
}

impl From<Result<(), iced::font::Error>> for Message {
fn from(res: Result<(), iced::font::Error>) -> Message {
Message::FontLoaded(res)
}
}

impl Application for DesignSystem {
type Message = Message;
type Theme = theme::Theme;
Expand All @@ -49,6 +56,9 @@ impl Application for DesignSystem {
],
current: 0,
};
#[allow(unused_mut)]
let mut cmds: Vec<Command<Self::Message>> = font::loads();

#[cfg(target_arch = "wasm32")]
{
use iced_native::{command, window};
Expand All @@ -57,16 +67,12 @@ impl Application for DesignSystem {
(window.inner_width().unwrap().as_f64().unwrap()) as u32,
(window.inner_height().unwrap().as_f64().unwrap()) as u32,
);
(
app,
Command::single(command::Action::Window(window::Action::Resize {
width,
height,
})),
)
cmds.push(Command::single(command::Action::Window(
window::Action::Resize { width, height },
)));
}
#[cfg(not(target_arch = "wasm32"))]
(app, Command::none())

(app, Command::batch(cmds))
}

fn update(&mut self, message: Message) -> Command<Self::Message> {
Expand Down
18 changes: 16 additions & 2 deletions gui/ui/src/font.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
use iced::Command;
use iced::Font;

pub const BOLD: Font = Font::with_name("IBMPlexSans-Bold");
pub const BOLD: Font = Font::with_name("IBM Plex Sans");
pub const MEDIUM: Font = Font::with_name("IBMPlexSans-Medium");
pub const REGULAR: Font = Font::with_name("IBMPlexSans-Regular");
pub const REGULAR: Font = Font::with_name("IBM Plex Sans");

pub const BOLD_BYTES: &[u8] = include_bytes!("../static/fonts/IBMPlexSans-Bold.ttf");
pub const MEDIUM_BYTES: &[u8] = include_bytes!("../static/fonts/IBMPlexSans-Medium.ttf");
pub const REGULAR_BYTES: &[u8] = include_bytes!("../static/fonts/IBMPlexSans-Regular.ttf");

pub const ICONEX_ICONS_BYTES: &[u8] = include_bytes!("../static/icons/iconex/iconex-icons.ttf");
pub const BOOTSTRAP_ICONS_BYTE: &[u8] = include_bytes!("../static/icons/bootstrap-icons.ttf");

pub fn loads<T: From<Result<(), iced::font::Error>> + 'static>() -> Vec<Command<T>> {
vec![
iced::font::load(BOLD_BYTES).map(T::from),
iced::font::load(MEDIUM_BYTES).map(T::from),
iced::font::load(REGULAR_BYTES).map(T::from),
iced::font::load(ICONEX_ICONS_BYTES).map(T::from),
iced::font::load(BOOTSTRAP_ICONS_BYTE).map(T::from),
]
}
6 changes: 1 addition & 5 deletions gui/ui/src/icon.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::widget::*;
use iced::{alignment, Font, Length};

pub const BOOTSTRAP_ICONS_BYTE: &[u8] = include_bytes!("../static/icons/bootstrap-icons.ttf");

const BOOTSTRAP_ICONS: Font = Font::with_name("bootstrap-icons");

fn bootstrap_icon(unicode: char) -> Text<'static> {
Expand Down Expand Up @@ -117,9 +115,7 @@ pub fn previous_icon() -> Text<'static> {
bootstrap_icon('\u{F284}')
}

pub const ICONEX_ICONS_BYTES: &[u8] = include_bytes!("../static/icons/iconex/iconex-icons.ttf");

const ICONEX_ICONS: Font = Font::with_name("iconex-icons");
const ICONEX_ICONS: Font = Font::with_name("Untitled1");

fn iconex_icon(unicode: char) -> Text<'static> {
Text::new(unicode.to_string())
Expand Down

0 comments on commit b9de40a

Please sign in to comment.