mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 17:37:22 +03:00
more dpi fixes:
- margin and padding - Widget::draw_batch - trip timeline - custom buttons and finally enable automatically setting DPI based on the monitor!!! [rebuild]
This commit is contained in:
parent
2f1b274276
commit
fa1273bd34
@ -189,6 +189,14 @@ impl GeomBatch {
|
|||||||
self.fancy_push(color, poly.translate(dx, dy));
|
self.fancy_push(color, poly.translate(dx, dy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Scales the batch by some factor.
|
||||||
|
pub fn scale(mut self, factor: f64) -> GeomBatch {
|
||||||
|
for (_, poly) in &mut self.list {
|
||||||
|
*poly = poly.scale(factor);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RewriteColor {
|
pub enum RewriteColor {
|
||||||
|
@ -223,7 +223,12 @@ impl Widget {
|
|||||||
// TODO These are literally just convenient APIs to avoid importing JustDraw. Do we want this
|
// TODO These are literally just convenient APIs to avoid importing JustDraw. Do we want this
|
||||||
// or not?
|
// or not?
|
||||||
pub fn draw_batch(ctx: &EventCtx, batch: GeomBatch) -> Widget {
|
pub fn draw_batch(ctx: &EventCtx, batch: GeomBatch) -> Widget {
|
||||||
JustDraw::wrap(ctx, batch)
|
let scale = ctx.get_scale_factor();
|
||||||
|
if scale == 1.0 {
|
||||||
|
JustDraw::wrap(ctx, batch)
|
||||||
|
} else {
|
||||||
|
JustDraw::wrap(ctx, batch.scale(scale))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn draw_svg<I: Into<String>>(ctx: &EventCtx, filename: I) -> Widget {
|
pub fn draw_svg<I: Into<String>>(ctx: &EventCtx, filename: I) -> Widget {
|
||||||
JustDraw::svg(ctx, filename.into())
|
JustDraw::svg(ctx, filename.into())
|
||||||
@ -287,7 +292,13 @@ impl Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populate a flattened list of Nodes, matching the traversal order
|
// Populate a flattened list of Nodes, matching the traversal order
|
||||||
fn get_flexbox(&self, parent: Node, stretch: &mut Stretch, nodes: &mut Vec<Node>) {
|
fn get_flexbox(
|
||||||
|
&self,
|
||||||
|
parent: Node,
|
||||||
|
scale_factor: f32,
|
||||||
|
stretch: &mut Stretch,
|
||||||
|
nodes: &mut Vec<Node>,
|
||||||
|
) {
|
||||||
if let Some(container) = self.widget.downcast_ref::<Container>() {
|
if let Some(container) = self.widget.downcast_ref::<Container>() {
|
||||||
let mut style = self.layout.style.clone();
|
let mut style = self.layout.style.clone();
|
||||||
style.flex_direction = if container.is_row {
|
style.flex_direction = if container.is_row {
|
||||||
@ -298,7 +309,7 @@ impl Widget {
|
|||||||
let node = stretch.new_node(style, Vec::new()).unwrap();
|
let node = stretch.new_node(style, Vec::new()).unwrap();
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
for widget in &container.members {
|
for widget in &container.members {
|
||||||
widget.get_flexbox(node, stretch, nodes);
|
widget.get_flexbox(node, scale_factor, stretch, nodes);
|
||||||
}
|
}
|
||||||
stretch.add_child(parent, node).unwrap();
|
stretch.add_child(parent, node).unwrap();
|
||||||
return;
|
return;
|
||||||
@ -308,6 +319,32 @@ impl Widget {
|
|||||||
width: Dimension::Points(self.widget.get_dims().width as f32),
|
width: Dimension::Points(self.widget.get_dims().width as f32),
|
||||||
height: Dimension::Points(self.widget.get_dims().height as f32),
|
height: Dimension::Points(self.widget.get_dims().height as f32),
|
||||||
};
|
};
|
||||||
|
if scale_factor != 1.0 {
|
||||||
|
if let Dimension::Points(ref mut px) = style.padding.start {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.padding.end {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.padding.top {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.padding.bottom {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.margin.start {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.margin.end {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.margin.top {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
if let Dimension::Points(ref mut px) = style.margin.bottom {
|
||||||
|
*px *= scale_factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
let node = stretch.new_node(style, Vec::new()).unwrap();
|
let node = stretch.new_node(style, Vec::new()).unwrap();
|
||||||
stretch.add_child(parent, node).unwrap();
|
stretch.add_child(parent, node).unwrap();
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
@ -509,7 +546,12 @@ impl Composite {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut nodes = vec![];
|
let mut nodes = vec![];
|
||||||
self.top_level.get_flexbox(root, &mut stretch, &mut nodes);
|
self.top_level.get_flexbox(
|
||||||
|
root,
|
||||||
|
ctx.get_scale_factor() as f32,
|
||||||
|
&mut stretch,
|
||||||
|
&mut nodes,
|
||||||
|
);
|
||||||
nodes.reverse();
|
nodes.reverse();
|
||||||
|
|
||||||
// TODO Express more simply. Constraining this seems useless.
|
// TODO Express more simply. Constraining this seems useless.
|
||||||
|
@ -164,7 +164,7 @@ pub struct Settings {
|
|||||||
profiling_enabled: bool,
|
profiling_enabled: bool,
|
||||||
default_font_size: usize,
|
default_font_size: usize,
|
||||||
dump_raw_events: bool,
|
dump_raw_events: bool,
|
||||||
scale_factor: f64,
|
scale_factor: Option<f64>,
|
||||||
window_icon: Option<String>,
|
window_icon: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ impl Settings {
|
|||||||
profiling_enabled: false,
|
profiling_enabled: false,
|
||||||
default_font_size: text::DEFAULT_FONT_SIZE,
|
default_font_size: text::DEFAULT_FONT_SIZE,
|
||||||
dump_raw_events: false,
|
dump_raw_events: false,
|
||||||
scale_factor: 1.0,
|
scale_factor: None,
|
||||||
window_icon: None,
|
window_icon: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn scale_factor(&mut self, scale_factor: f64) {
|
pub fn scale_factor(&mut self, scale_factor: f64) {
|
||||||
self.scale_factor = scale_factor;
|
self.scale_factor = Some(scale_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_icon(&mut self, path: &str) {
|
pub fn window_icon(&mut self, path: &str) {
|
||||||
@ -224,7 +224,9 @@ pub fn run<G: 'static + GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings,
|
|||||||
assets: Assets::new(
|
assets: Assets::new(
|
||||||
settings.default_font_size,
|
settings.default_font_size,
|
||||||
settings.font_dir,
|
settings.font_dir,
|
||||||
settings.scale_factor,
|
settings
|
||||||
|
.scale_factor
|
||||||
|
.unwrap_or_else(|| prerender_innards.monitor_scale_factor()),
|
||||||
),
|
),
|
||||||
num_uploads: Cell::new(0),
|
num_uploads: Cell::new(0),
|
||||||
inner: prerender_innards,
|
inner: prerender_innards,
|
||||||
|
@ -402,12 +402,12 @@ impl BtnBuilder {
|
|||||||
}
|
}
|
||||||
BtnBuilder::Custom(normal, hovered, hitbox, maybe_t) => Button::new(
|
BtnBuilder::Custom(normal, hovered, hitbox, maybe_t) => Button::new(
|
||||||
ctx,
|
ctx,
|
||||||
normal,
|
normal.scale(ctx.get_scale_factor()),
|
||||||
hovered,
|
hovered.scale(ctx.get_scale_factor()),
|
||||||
key,
|
key,
|
||||||
&action_tooltip.into(),
|
&action_tooltip.into(),
|
||||||
maybe_t,
|
maybe_t,
|
||||||
hitbox,
|
hitbox.scale(ctx.get_scale_factor()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ fn make_timeline(
|
|||||||
normal.add_svg(
|
normal.add_svg(
|
||||||
ctx.prerender,
|
ctx.prerender,
|
||||||
"../data/system/assets/timeline/current_pos.svg",
|
"../data/system/assets/timeline/current_pos.svg",
|
||||||
Pt2D::new(p * phase_width, 7.5),
|
Pt2D::new(p * phase_width, 7.5 * ctx.get_scale_factor()),
|
||||||
1.0,
|
1.0,
|
||||||
Angle::ZERO,
|
Angle::ZERO,
|
||||||
RewriteColor::NoOp,
|
RewriteColor::NoOp,
|
||||||
@ -450,7 +450,7 @@ fn make_timeline(
|
|||||||
TripPhaseType::Remote => "../data/system/assets/timeline/delayed_start.svg",
|
TripPhaseType::Remote => "../data/system/assets/timeline/delayed_start.svg",
|
||||||
},
|
},
|
||||||
// TODO Hardcoded layouting...
|
// TODO Hardcoded layouting...
|
||||||
Pt2D::new(0.5 * phase_width, -20.0),
|
Pt2D::new(0.5 * phase_width, -20.0 * ctx.get_scale_factor()),
|
||||||
1.0,
|
1.0,
|
||||||
Angle::ZERO,
|
Angle::ZERO,
|
||||||
RewriteColor::NoOp,
|
RewriteColor::NoOp,
|
||||||
|
Loading…
Reference in New Issue
Block a user