mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
make Filler responsive to window resizing
This commit is contained in:
parent
8ce2568280
commit
bc4c1eaea6
@ -5,13 +5,20 @@ use crate::{EventCtx, GfxCtx, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOu
|
||||
pub struct Filler {
|
||||
top_left: ScreenPt,
|
||||
dims: ScreenDims,
|
||||
|
||||
square_width_pct: f64,
|
||||
}
|
||||
|
||||
impl Filler {
|
||||
pub fn new(dims: ScreenDims) -> Widget {
|
||||
/// Creates a square filler, always some percentage of the window width.
|
||||
pub fn square_width(ctx: &EventCtx, pct_width: f64) -> Widget {
|
||||
Widget::new(Box::new(Filler {
|
||||
dims,
|
||||
dims: ScreenDims::new(
|
||||
pct_width * ctx.canvas.window_width,
|
||||
pct_width * ctx.canvas.window_width,
|
||||
),
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
square_width_pct: pct_width,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -25,6 +32,13 @@ impl WidgetImpl for Filler {
|
||||
self.top_left = top_left;
|
||||
}
|
||||
|
||||
fn event(&mut self, _: &mut EventCtx, _: &mut WidgetOutput) {}
|
||||
fn event(&mut self, ctx: &mut EventCtx, _: &mut WidgetOutput) {
|
||||
if ctx.input.is_window_resized() {
|
||||
self.dims = ScreenDims::new(
|
||||
self.square_width_pct * ctx.canvas.window_width,
|
||||
self.square_width_pct * ctx.canvas.window_width,
|
||||
);
|
||||
}
|
||||
}
|
||||
fn draw(&self, _g: &mut GfxCtx) {}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use crate::layer::PickLayer;
|
||||
use abstutil::clamp;
|
||||
use ezgui::{
|
||||
hotkey, Btn, Checkbox, Color, Composite, EventCtx, Filler, GeomBatch, GfxCtx,
|
||||
HorizontalAlignment, Key, Outcome, ScreenDims, ScreenPt, Spinner, VerticalAlignment, Widget,
|
||||
HorizontalAlignment, Key, Outcome, ScreenPt, Spinner, VerticalAlignment, Widget,
|
||||
};
|
||||
use geom::{Distance, Polygon, Pt2D, Ring};
|
||||
|
||||
@ -364,7 +364,6 @@ fn make_minimap_panel(ctx: &mut EventCtx, app: &App, zoom_lvl: usize) -> Composi
|
||||
.margin_above(26)
|
||||
};
|
||||
|
||||
let square_len = 0.15 * ctx.canvas.window_width;
|
||||
let minimap_controls = Widget::col(vec![
|
||||
Btn::svg_def("system/assets/minimap/up.svg")
|
||||
.build(ctx, "pan up", None)
|
||||
@ -373,7 +372,7 @@ fn make_minimap_panel(ctx: &mut EventCtx, app: &App, zoom_lvl: usize) -> Composi
|
||||
Btn::svg_def("system/assets/minimap/left.svg")
|
||||
.build(ctx, "pan left", None)
|
||||
.centered_vert(),
|
||||
Filler::new(ScreenDims::new(square_len, square_len)).named("minimap"),
|
||||
Filler::square_width(ctx, 0.15).named("minimap"),
|
||||
Btn::svg_def("system/assets/minimap/right.svg")
|
||||
.build(ctx, "pan right", None)
|
||||
.centered_vert(),
|
||||
|
@ -6,8 +6,7 @@ use crate::sandbox::dashboards::DashTab;
|
||||
use crate::sandbox::SandboxMode;
|
||||
use abstutil::prettyprint_usize;
|
||||
use ezgui::{
|
||||
Btn, Checkbox, Composite, EventCtx, Filler, GfxCtx, Line, Outcome, ScreenDims, Text, TextExt,
|
||||
Widget,
|
||||
Btn, Checkbox, Composite, EventCtx, Filler, GfxCtx, Line, Outcome, Text, TextExt, Widget,
|
||||
};
|
||||
use geom::Duration;
|
||||
use sim::{TripEndpoint, TripID, TripPhaseType};
|
||||
@ -285,11 +284,7 @@ fn make(ctx: &mut EventCtx, app: &App, opts: &Options) -> Composite {
|
||||
Line("since the time spent driving off-map isn't shown here."),
|
||||
])
|
||||
.draw(ctx),
|
||||
Filler::new(ScreenDims::new(
|
||||
0.15 * ctx.canvas.window_width,
|
||||
0.15 * ctx.canvas.window_width,
|
||||
))
|
||||
.named("preview"),
|
||||
Filler::square_width(ctx, 0.15).named("preview"),
|
||||
])
|
||||
.evenly_spaced(),
|
||||
);
|
||||
|
@ -9,7 +9,7 @@ use crate::sandbox::SandboxMode;
|
||||
use abstutil::prettyprint_usize;
|
||||
use ezgui::{
|
||||
Btn, Checkbox, Color, Composite, EventCtx, Filler, GeomBatch, GfxCtx, Line, Outcome,
|
||||
RewriteColor, ScreenDims, ScreenPt, Text, TextExt, Widget,
|
||||
RewriteColor, ScreenPt, Text, TextExt, Widget,
|
||||
};
|
||||
use geom::{Distance, Duration, Polygon, Pt2D, Time};
|
||||
use sim::{TripEndpoint, TripID, TripMode};
|
||||
@ -413,12 +413,9 @@ fn make(ctx: &mut EventCtx, app: &App, opts: &Options) -> Composite {
|
||||
0.88 * ctx.canvas.window_width,
|
||||
));
|
||||
col.push(
|
||||
Filler::new(ScreenDims::new(
|
||||
0.15 * ctx.canvas.window_width,
|
||||
0.15 * ctx.canvas.window_width,
|
||||
))
|
||||
.named("preview")
|
||||
.centered_horiz(),
|
||||
Filler::square_width(ctx, 0.15)
|
||||
.named("preview")
|
||||
.centered_horiz(),
|
||||
);
|
||||
|
||||
Composite::new(Widget::col(col))
|
||||
|
Loading…
Reference in New Issue
Block a user