From fdfa2dbe8c2bf0cc8e4d120af856f7b1a60010bc Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sat, 26 Dec 2020 21:31:51 -0800 Subject: [PATCH] Bundle some of the widgetry SVG assets in directly, so other users don't need to copy part of the data/ directory. [rebuild] [release] --- widgetry/src/event_ctx.rs | 5 ++- widgetry/src/widgets/button.rs | 11 +++--- widgetry/src/widgets/checkbox.rs | 68 +++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/widgetry/src/event_ctx.rs b/widgetry/src/event_ctx.rs index 51f0ba3adb..8f6278026d 100644 --- a/widgetry/src/event_ctx.rs +++ b/widgetry/src/event_ctx.rs @@ -140,7 +140,10 @@ impl<'a> EventCtx<'a> { Widget::custom_col(vec![ Widget::draw_batch( self, - GeomBatch::load_svg(self, "system/assets/map/dont_walk.svg").scale(5.0), + GeomBatch::from_svg_contents( + include_bytes!("../../data/system/assets/map/dont_walk.svg").to_vec(), + ) + .scale(5.0), ) .container() .bg(Color::BLACK) diff --git a/widgetry/src/widgets/button.rs b/widgetry/src/widgets/button.rs index 2c53e30a55..1524f64967 100644 --- a/widgetry/src/widgets/button.rs +++ b/widgetry/src/widgets/button.rs @@ -201,11 +201,12 @@ impl Btn { let icon_container = Polygon::rectangle(20.0, 30.0); icon_batch.push(Color::INVISIBLE, icon_container); - let path = "system/assets/widgetry/arrow_drop_down.svg"; - let icon = GeomBatch::load_svg(ctx, &path) - .color(RewriteColor::ChangeAll(ctx.style().outline_color)) - .autocrop() - .centered_on(icon_batch.get_bounds().center()); + let icon = GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/arrow_drop_down.svg").to_vec(), + ) + .color(RewriteColor::ChangeAll(ctx.style().outline_color)) + .autocrop() + .centered_on(icon_batch.get_bounds().center()); icon_batch.append(icon); diff --git a/widgetry/src/widgets/checkbox.rs b/widgetry/src/widgets/checkbox.rs index 5741280928..230be1ba06 100644 --- a/widgetry/src/widgets/checkbox.rs +++ b/widgetry/src/widgets/checkbox.rs @@ -35,16 +35,20 @@ impl Checkbox { ) -> Widget { let label = label.into(); let (off, hitbox) = Widget::row(vec![ - GeomBatch::load_svg(ctx, "system/assets/widgetry/toggle_off.svg") - .batch() - .centered_vert(), + GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/toggle_off.svg").to_vec(), + ) + .batch() + .centered_vert(), label.clone().batch_text(ctx), ]) .to_geom(ctx, None); let (on, _) = Widget::row(vec![ - GeomBatch::load_svg(ctx, "system/assets/widgetry/toggle_on.svg") - .batch() - .centered_vert(), + GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/toggle_on.svg").to_vec(), + ) + .batch() + .centered_vert(), label.clone().batch_text(ctx), ]) .to_geom(ctx, None); @@ -118,18 +122,22 @@ impl Checkbox { pub fn colored(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget { let (off, hitbox) = Widget::row(vec![ - GeomBatch::load_svg(ctx, "system/assets/widgetry/checkbox.svg") - .color(RewriteColor::ChangeAll(color.alpha(0.3))) - .batch() - .centered_vert(), + GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/checkbox.svg").to_vec(), + ) + .color(RewriteColor::ChangeAll(color.alpha(0.3))) + .batch() + .centered_vert(), label.batch_text(ctx), ]) .to_geom(ctx, None); let (on, _) = Widget::row(vec![ - GeomBatch::load_svg(ctx, "system/assets/widgetry/checkbox.svg") - .color(RewriteColor::Change(Color::BLACK, color)) - .batch() - .centered_vert(), + GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/checkbox.svg").to_vec(), + ) + .color(RewriteColor::Change(Color::BLACK, color)) + .batch() + .centered_vert(), label.batch_text(ctx), ]) .to_geom(ctx, None); @@ -172,20 +180,32 @@ impl Checkbox { let left_label = left_label.into(); let right_label = right_label.into(); let hotkey = hotkey.into(); + let right = GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/toggle_right.svg").to_vec(), + ); + let left = GeomBatch::from_svg_contents( + include_bytes!("../../../data/system/assets/widgetry/toggle_left.svg").to_vec(), + ); + let hitbox = right.get_bounds().get_rectangle(); + Widget::row(vec![ left_label.clone().draw_text(ctx), Checkbox::new( enabled, - Btn::svg_def("system/assets/widgetry/toggle_right.svg").build( - ctx, - left_label, - hotkey.clone(), - ), - Btn::svg_def("system/assets/widgetry/toggle_left.svg").build( - ctx, - right_label.clone(), - hotkey, - ), + Btn::custom( + right.clone(), + right.color(RewriteColor::ChangeAll(ctx.style().hovering_color)), + hitbox.clone(), + None, + ) + .build(ctx, left_label, hotkey.clone()), + Btn::custom( + left.clone(), + left.color(RewriteColor::ChangeAll(ctx.style().hovering_color)), + hitbox, + None, + ) + .build(ctx, right_label.clone(), hotkey), ) .named(label), right_label.draw_text(ctx),