compile in asset bytes for widgetry assets

This commit is contained in:
Michael Kirk 2021-01-22 08:53:38 -06:00
parent 7bc9145ce9
commit 4e48de6185
14 changed files with 70 additions and 30 deletions

View File

@ -1,3 +0,0 @@
<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.25 0.5L4 4.25L7.75 0.5H0.25Z" fill="#F2F2F2"/>
</svg>

Before

Width:  |  Height:  |  Size: 158 B

View File

@ -645,12 +645,12 @@ fn make_side_panel(
let up_button = ctx
.style()
.btn_primary_light_icon("system/assets/tools/arrow_up.svg")
.btn_primary_light_icon("../widgetry/icons/arrow_up.svg")
.disabled(idx == 0);
let down_button = ctx
.style()
.btn_primary_light_icon("system/assets/tools/arrow_down.svg")
.btn_primary_light_icon("../widgetry/icons/arrow_down.svg")
.disabled(idx == canonical_signal.stages.len() - 1);
let stage_controls = Widget::row(vec![

View File

@ -191,7 +191,7 @@ pub fn trips(
},
{
let mut icon =
GeomBatch::load_svg(ctx.prerender, "system/assets/tools/arrow_drop_down.svg")
GeomBatch::load_svg(ctx.prerender, "../widgetry/icons/arrow_drop_down.svg")
.autocrop()
.color(RewriteColor::ChangeAll(Color::WHITE))
.scale(1.5);

View File

Before

Width:  |  Height:  |  Size: 210 B

After

Width:  |  Height:  |  Size: 210 B

View File

@ -1 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M7 10l5 5 5-5z"/></svg>
<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.25 0.5L4 4.25L7.75 0.5H0.25Z" fill="#F2F2F2"/>
</svg>

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 158 B

View File

Before

Width:  |  Height:  |  Size: 247 B

After

Width:  |  Height:  |  Size: 247 B

View File

Before

Width:  |  Height:  |  Size: 214 B

After

Width:  |  Height:  |  Size: 214 B

View File

Before

Width:  |  Height:  |  Size: 211 B

After

Width:  |  Height:  |  Size: 211 B

View File

Before

Width:  |  Height:  |  Size: 209 B

After

Width:  |  Height:  |  Size: 209 B

View File

@ -87,6 +87,9 @@ pub trait StyledButtons<'a> {
fn btn_plain_light_icon(&self, image_path: &'a str) -> ButtonBuilder<'a> {
icon_button(self.btn_plain_light().image_path(image_path))
}
fn btn_plain_light_icon_bytes(&self, image_bytes: (&'a [u8], &'a str)) -> ButtonBuilder<'a> {
icon_button(self.btn_plain_light().image_bytes(image_bytes))
}
fn btn_plain_light_icon_text(&self, image_path: &'a str, text: &'a str) -> ButtonBuilder<'a> {
self.btn_plain_light()
.label_text(text)
@ -302,7 +305,10 @@ fn back_button<'a>(builder: ButtonBuilder<'a>, title: &'a str) -> ButtonBuilder<
fn dropdown_button<'a>(builder: ButtonBuilder<'a>) -> ButtonBuilder<'a> {
builder
.image_path("system/assets/tools/arrow_drop_down.svg")
.image_bytes((
include_bytes!("../../icons/arrow_drop_down.svg"),
"../../icons/arrow_drop_down.svg",
))
.image_dims(12.0)
.stack_spacing(12.0)
.label_first()

View File

@ -268,9 +268,11 @@ impl<'b, 'a: 'b> ButtonBuilder<'a> {
/// Set the image for the button. If not set, the button will have no image.
///
/// This will replace any image previously set by [`image_path`].
///
/// `bytes`: utf-8 encoded bytes of the svg
/// `name`: a label to describe the bytes for debugging purposes
pub fn image_bytes(mut self, bytes: &'a [u8], cache_key: &'a str) -> Self {
pub fn image_bytes(mut self, bytes_and_cache_key: (&'a [u8], &'a str)) -> Self {
let (bytes, cache_key) = bytes_and_cache_key;
// Currently we don't support setting image for other states like "hover", we easily
// could, but the API gets more verbose for a thing we don't currently need.
let mut image = self.default_style.image.take().unwrap_or_default();

View File

@ -43,10 +43,16 @@ impl Checkbox {
let off_button = buttons
.clone()
.image_path("../widgetry/icons/toggle_off.svg")
.image_bytes((
include_bytes!("../../icons/toggle_off.svg"),
"../../icons/toggle_off.svg",
))
.build(ctx, label);
let on_button = buttons
.image_path("../widgetry/icons/toggle_on.svg")
.image_bytes((
include_bytes!("../../icons/toggle_on.svg"),
"../../icons/toggle_on.svg",
))
.build(ctx, label);
Checkbox::new(enabled, off_button, on_button).named(label)
@ -80,10 +86,14 @@ impl Checkbox {
buttons = buttons.hotkey(hotkey);
}
let false_btn = buttons
.clone()
.image_path("../widgetry/icons/checkbox_unchecked.svg");
let true_btn = buttons.image_path("../widgetry/icons/checkbox_checked.svg");
let false_btn = buttons.clone().image_bytes((
include_bytes!("../../icons/checkbox_unchecked.svg"),
"../../icons/checkbox_unchecked.svg",
));
let true_btn = buttons.image_bytes((
include_bytes!("../../icons/checkbox_checked.svg"),
"../../icons/checkbox_checked.svg",
));
Checkbox::new(
enabled,
@ -122,10 +132,14 @@ impl Checkbox {
buttons = buttons.hotkey(hotkey);
}
let false_btn = buttons
.clone()
.image_path("../widgetry/icons/checkbox_unchecked.svg");
let true_btn = buttons.image_path("../widgetry/icons/checkbox_checked.svg");
let false_btn = buttons.clone().image_bytes((
include_bytes!("../../icons/checkbox_unchecked.svg"),
"../../icons/checkbox_unchecked.svg",
));
let true_btn = buttons.image_bytes((
include_bytes!("../../icons/checkbox_checked.svg"),
"../../icons/checkbox_checked.svg",
));
Checkbox::new(
enabled,
@ -140,14 +154,20 @@ impl Checkbox {
let false_btn = buttons
.clone()
.image_path("../widgetry/icons/checkbox_unchecked.svg")
.image_bytes((
include_bytes!("../../icons/checkbox_unchecked.svg"),
"../../icons/checkbox_unchecked.svg",
))
.image_color(
RewriteColor::Change(Color::BLACK, color.alpha(0.3)),
ControlState::Default,
);
let true_btn = buttons
.image_path("../widgetry/icons/checkbox_checked.svg")
.image_bytes((
include_bytes!("../../icons/checkbox_checked.svg"),
"../../icons/checkbox_checked.svg",
))
.image_color(
RewriteColor::Change(Color::BLACK, color),
ControlState::Default,
@ -172,7 +192,10 @@ impl Checkbox {
) -> Widget {
let mut toggle_left_button = ctx
.style()
.btn_plain_light_icon("../widgetry/icons/toggle_left.svg")
.btn_plain_light_icon_bytes((
include_bytes!("../../icons/toggle_left.svg"),
"../../icons/toggle_left.svg",
))
.image_dims(ScreenDims::new(40.0, 40.0))
.padding(4)
.image_color(RewriteColor::NoOp, ControlState::Default);
@ -181,9 +204,10 @@ impl Checkbox {
toggle_left_button = toggle_left_button.hotkey(hotkey);
}
let toggle_right_button = toggle_left_button
.clone()
.image_path("../widgetry/icons/toggle_right.svg");
let toggle_right_button = toggle_left_button.clone().image_bytes((
include_bytes!("../../icons/toggle_right.svg"),
"../../icons/toggle_right.svg",
));
let left_text_button = ctx
.style()

View File

@ -38,11 +38,17 @@ impl Spinner {
let up = button_builder
.clone()
.image_path("system/assets/tools/arrow_up.svg")
.image_bytes((
include_bytes!("../../icons/arrow_up.svg"),
"../../icons/arrow_up.svg",
))
.build(ctx, "increase value");
let down = button_builder
.image_path("system/assets/tools/arrow_down.svg")
.image_bytes((
include_bytes!("../../icons/arrow_down.svg"),
"../../icons/arrow_down.svg",
))
.build(ctx, "decrease value");
let dims = ScreenDims::new(

View File

@ -101,10 +101,13 @@ impl<A, T, F> Table<A, T, F> {
if self.sort_by == col.name {
ctx.style()
.btn_primary_dark_icon_text("tmp", &col.name)
.image_path(if self.descending {
"system/assets/tools/arrow_down.svg"
.image_bytes(if self.descending {
(
include_bytes!("../../icons/arrow_down.svg"),
"arrow_down.svg",
)
} else {
"system/assets/tools/arrow_up.svg"
(include_bytes!("../../icons/arrow_up.svg"), "arrow_up.svg")
})
.label_first()
.build_widget(ctx, &col.name)