diff --git a/data/system/assets/tools/arrow_drop_down.svg b/data/system/assets/tools/arrow_drop_down.svg deleted file mode 100644 index 55042af7e2..0000000000 --- a/data/system/assets/tools/arrow_drop_down.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/game/src/edit/traffic_signals/mod.rs b/game/src/edit/traffic_signals/mod.rs index f5cd696d61..c9001771bb 100644 --- a/game/src/edit/traffic_signals/mod.rs +++ b/game/src/edit/traffic_signals/mod.rs @@ -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![ diff --git a/game/src/info/person.rs b/game/src/info/person.rs index ef5f965dac..97c5b8b81b 100644 --- a/game/src/info/person.rs +++ b/game/src/info/person.rs @@ -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); diff --git a/data/system/assets/tools/arrow_down.svg b/widgetry/icons/arrow_down.svg similarity index 100% rename from data/system/assets/tools/arrow_down.svg rename to widgetry/icons/arrow_down.svg diff --git a/widgetry/icons/arrow_drop_down.svg b/widgetry/icons/arrow_drop_down.svg index e8b16b3404..55042af7e2 100644 --- a/widgetry/icons/arrow_drop_down.svg +++ b/widgetry/icons/arrow_drop_down.svg @@ -1 +1,3 @@ - \ No newline at end of file + + + diff --git a/data/system/assets/tools/arrow_keys.svg b/widgetry/icons/arrow_keys.svg similarity index 100% rename from data/system/assets/tools/arrow_keys.svg rename to widgetry/icons/arrow_keys.svg diff --git a/data/system/assets/tools/arrow_left.svg b/widgetry/icons/arrow_left.svg similarity index 100% rename from data/system/assets/tools/arrow_left.svg rename to widgetry/icons/arrow_left.svg diff --git a/data/system/assets/tools/arrow_right.svg b/widgetry/icons/arrow_right.svg similarity index 100% rename from data/system/assets/tools/arrow_right.svg rename to widgetry/icons/arrow_right.svg diff --git a/data/system/assets/tools/arrow_up.svg b/widgetry/icons/arrow_up.svg similarity index 100% rename from data/system/assets/tools/arrow_up.svg rename to widgetry/icons/arrow_up.svg diff --git a/widgetry/src/style/buttons.rs b/widgetry/src/style/buttons.rs index 6f9efe2d09..af1ad62e94 100644 --- a/widgetry/src/style/buttons.rs +++ b/widgetry/src/style/buttons.rs @@ -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() diff --git a/widgetry/src/widgets/button.rs b/widgetry/src/widgets/button.rs index b7c04186d3..0b7a76b6ec 100644 --- a/widgetry/src/widgets/button.rs +++ b/widgetry/src/widgets/button.rs @@ -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(); diff --git a/widgetry/src/widgets/checkbox.rs b/widgetry/src/widgets/checkbox.rs index 9c6b985f0d..17f84023f9 100644 --- a/widgetry/src/widgets/checkbox.rs +++ b/widgetry/src/widgets/checkbox.rs @@ -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() diff --git a/widgetry/src/widgets/spinner.rs b/widgetry/src/widgets/spinner.rs index 3d57c99432..f16fddc4da 100644 --- a/widgetry/src/widgets/spinner.rs +++ b/widgetry/src/widgets/spinner.rs @@ -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( diff --git a/widgetry/src/widgets/table.rs b/widgetry/src/widgets/table.rs index cc78d48fb6..5e927ac783 100644 --- a/widgetry/src/widgets/table.rs +++ b/widgetry/src/widgets/table.rs @@ -101,10 +101,13 @@ impl Table { 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)