From: Ian Jackson Date: Wed, 31 Mar 2021 10:53:44 +0000 (+0100) Subject: table size html attrs: Split out into base X-Git-Tag: otter-0.5.0~355 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e0fe77feefc4548e6d2bbdf4e58f4acbe861ec25;p=otter.git table size html attrs: Split out into base We are going to want these for dynamic reset. Signed-off-by: Ian Jackson --- diff --git a/base/misc.rs b/base/misc.rs index c7abfc63..963dc676 100644 --- a/base/misc.rs +++ b/base/misc.rs @@ -7,6 +7,8 @@ use crate::prelude::*; +pub const SVG_SCALE: f64 = 6.; + pub fn timestring_abbreviate<'x>(base: &str, this: &'x str) -> (&'x str, bool) { @@ -44,3 +46,21 @@ macro_rules! display_as_debug { } } pub use crate::display_as_debug; + +pub type SvgAttrs = Vec<(String,String)>; + +pub fn space_table_attrs(table_size: PosC) -> SvgAttrs { + let PosC { coords: [x, y] } = table_size.into(); + vec![ + ("viewBox".to_owned(), format!("0 0 {x} {y}", x=x, y=y) ), + ("width" .to_owned(), (SVG_SCALE * x).to_string() ), + ("height" .to_owned(), (SVG_SCALE * y).to_string() ), + ] +} + +pub fn space_rect_attrs(table_size: PosC) -> SvgAttrs { + vec![ + ("width" .to_owned(), table_size.x().to_string() ), + ("height" .to_owned(), table_size.y().to_string() ), + ] +} diff --git a/base/prelude.rs b/base/prelude.rs index 398da673..30cfe48b 100644 --- a/base/prelude.rs +++ b/base/prelude.rs @@ -22,6 +22,6 @@ pub use serde_with::SerializeDisplay; pub use thiserror::Error; pub use void::Void; -pub use crate::geometry::CoordinateOverflow; +pub use crate::geometry::{CoordinateOverflow, PosC}; pub use crate::misc::default; pub use crate::misc::display_as_debug; diff --git a/daemon/session.rs b/daemon/session.rs index 29e1d315..68baa68d 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -13,7 +13,8 @@ struct SessionRenderContext { ctoken: RawToken, player: PlayerId, gen: Generation, - table_size: Pos, + space_attrs: SvgAttrs, + rect_attrs: SvgAttrs, uses: Vec, defs: Vec<(VisiblePieceId, Html)>, nick: String, @@ -21,7 +22,6 @@ struct SessionRenderContext { log: Vec, sse_url_prefix: String, links: Html, - scale: f64, player_info_pane: Html, fake_rng: bool, } @@ -203,16 +203,18 @@ fn session_inner(form: Json, None => "".into(), }; + let table_size = ig.gs.table_size.promote(); + let src = SessionRenderContext { table_colour: ig.gs.table_colour.clone(), ctoken, gen: ig.gs.gen, log, - table_size: ig.gs.table_size, player, defs: alldefs, uses, - scale: SVG_SCALE, + space_attrs: space_table_attrs(table_size), + rect_attrs: space_table_attrs(table_size), nick, sse_url_prefix, player_info_pane, diff --git a/src/prelude.rs b/src/prelude.rs index cc097b5d..0aed003e 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -108,8 +108,7 @@ pub use otter_base::geometry::{self,Coord,Pos,PosC,Rect,RectC}; pub use otter_base::geometry::{CoordinateOverflow,Region}; pub use otter_base::zcoord::{self, ZCoord}; pub use otter_base::misc as base_misc; -pub use base_misc::default; -pub use base_misc::display_as_debug; +pub use base_misc::*; pub use crate::dbgc; pub use crate::{deref_to_field, deref_to_field_mut}; diff --git a/src/ui.rs b/src/ui.rs index 9ae5e6a6..1cd7e68c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -4,8 +4,6 @@ use crate::prelude::*; -pub const SVG_SCALE: f64 = 6.; - pub const HELD_SURROUND_COLOUR: &str = "black"; #[derive(Clone,Copy,Debug,Eq,PartialEq,Serialize,Deserialize,EnumString)] diff --git a/templates/macros.tera b/templates/macros.tera index f4196c3c..7d32fada 100644 --- a/templates/macros.tera +++ b/templates/macros.tera @@ -72,12 +72,15 @@ Hi {{nick | escape}} {% macro space() %} +{%- for attr in rect_attrs %} + {{ attr.0 }}="{{ attr.1 }}" +{%- endfor %} + /> {%- for piece in uses %}