Draw proper checkmark for Checkbox in iced_wgpu

This commit is contained in:
Héctor Ramón Jiménez 2019-11-14 03:34:41 +01:00
parent 66bb2f7cbf
commit 2c8ba652a7
4 changed files with 20 additions and 12 deletions

View file

@ -357,7 +357,7 @@ fn empty_message(message: &str) -> Element<'static, Message> {
// Fonts // Fonts
const ICONS: Font = Font::External { const ICONS: Font = Font::External {
name: "Icons", name: "Icons",
bytes: include_bytes!("./resources/icons.ttf"), bytes: include_bytes!("resources/icons.ttf"),
}; };
fn icon(unicode: char) -> Text { fn icon(unicode: char) -> Text {

View file

@ -74,14 +74,15 @@ impl checkbox::Renderer for Renderer {
( (
Primitive::Group { Primitive::Group {
primitives: if checkbox.is_checked { primitives: if checkbox.is_checked {
// TODO: Draw an actual icon let check = Primitive::Text {
let (check, _) = text::Renderer::draw( content: crate::text::CHECKMARK_ICON.to_string(),
self, font: crate::text::BUILTIN_ICONS,
&Text::new("X") size: checkbox_bounds.height * 0.7,
.horizontal_alignment(HorizontalAlignment::Center) bounds: checkbox_bounds,
.vertical_alignment(VerticalAlignment::Center), color: [0.3, 0.3, 0.3].into(),
checkbox_layout, horizontal_alignment: HorizontalAlignment::Center,
); vertical_alignment: VerticalAlignment::Center,
};
vec![checkbox_border, checkbox_box, check, label] vec![checkbox_border, checkbox_box, check, label]
} else { } else {

View file

@ -5,6 +5,13 @@ use crate::Transformation;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
pub const BUILTIN_ICONS: iced_native::Font = iced_native::Font::External {
name: "iced_wgpu icons",
bytes: include_bytes!("text/icons.ttf"),
};
pub const CHECKMARK_ICON: char = '\u{F00C}';
pub struct Pipeline { pub struct Pipeline {
draw_brush: RefCell<wgpu_glyph::GlyphBrush<'static, ()>>, draw_brush: RefCell<wgpu_glyph::GlyphBrush<'static, ()>>,
draw_font_map: RefCell<HashMap<String, wgpu_glyph::FontId>>, draw_font_map: RefCell<HashMap<String, wgpu_glyph::FontId>>,
@ -91,10 +98,10 @@ impl Pipeline {
// TODO: This is a bit hacky. We are loading the debug font as the // TODO: This is a bit hacky. We are loading the debug font as the
// first font in the `draw_brush`. The `measure_brush` does not // first font in the `draw_brush`. The `measure_brush` does not
// contain this font, hence we subtract 1. // contain this, hence we subtract 1.
// //
// This should go away once we improve the debug view and integrate // This should go away once we unify `draw_brush` and
// it as just another UI app. // `measure_brush`.
font_id: wgpu_glyph::FontId(font_id - 1), font_id: wgpu_glyph::FontId(font_id - 1),
..Default::default() ..Default::default()
}; };

BIN
wgpu/src/text/icons.ttf Normal file

Binary file not shown.