chiark / gitweb /
table size html attrs: Split out into base
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Mar 2021 10:53:44 +0000 (11:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Apr 2021 10:31:37 +0000 (11:31 +0100)
We are going to want these for dynamic reset.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
base/misc.rs
base/prelude.rs
daemon/session.rs
src/prelude.rs
src/ui.rs
templates/macros.tera

index c7abfc6387f90706f43553df8369c5f3807c5d9b..963dc67602cf08e0ae22362a9f677e04e5a9190d 100644 (file)
@@ -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<f64>) -> 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<f64>) -> SvgAttrs {
+  vec![
+    ("width"  .to_owned(), table_size.x().to_string()  ),
+    ("height" .to_owned(), table_size.y().to_string()  ),
+  ]
+}
index 398da67373df01c44e362ab7c790a94a5d9758a6..30cfe48bb7777c2e95c35b2616ca6af78e903752 100644 (file)
@@ -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;
index 29e1d3152039825e3a0b16cc9f328d692f9fac66..68baa68dc76f0af040ed83d65680698210a61943 100644 (file)
@@ -13,7 +13,8 @@ struct SessionRenderContext {
   ctoken: RawToken,
   player: PlayerId,
   gen: Generation,
-  table_size: Pos,
+  space_attrs: SvgAttrs,
+  rect_attrs: SvgAttrs,
   uses: Vec<SessionPieceContext>,
   defs: Vec<(VisiblePieceId, Html)>,
   nick: String,
@@ -21,7 +22,6 @@ struct SessionRenderContext {
   log: Vec<SessionFormattedLogEntry>,
   sse_url_prefix: String,
   links: Html,
-  scale: f64,
   player_info_pane: Html,
   fake_rng: bool,
 }
@@ -203,16 +203,18 @@ fn session_inner(form: Json<SessionForm>,
       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,
index cc097b5d7f2c70a21b7d79651752101ba32e3a7e..0aed003eabbb4df508a50a0fa3b4c447d53fe848 100644 (file)
@@ -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};
index 9ae5e6a65be85e845307ed034d18e660a57641ae..1cd7e68cece54d6b7f27f38c12308ec7cd66b538 100644 (file)
--- 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)]
index f4196c3c7e92675d6dc09848f1548afcad0e322a..7d32fadaf3c9b60f713a107016d1b1126e5a520e 100644 (file)
@@ -72,12 +72,15 @@ Hi {{nick | escape}}
 {% macro space() %}
     <svg id="space"
         xmlns="http://www.w3.org/2000/svg"
-        viewBox="0 0 {{ table_size[0] }} {{ table_size[1] }}"
-        width="{{ table_size[0]*scale }}"
-        height="{{ table_size[1]*scale }}"
+{%- for attr in space_attrs %}
+         {{ attr.0 }}="{{ attr.1 }}"
+{%- endfor %}
         >
       <rect fill="{{ table_colour }}" x="0" y="0"
-           width="{{ table_size[0] }}" height="{{ table_size[1] }}"/>
+{%- for attr in rect_attrs %}
+         {{ attr.0 }}="{{ attr.1 }}"
+{%- endfor %}
+           />
       <g id="pieces_marker"></g>
 {%- for piece in uses %}
       <use id="use{{ piece.id }}" href="#piece{{ piece.id }}"