LaTeX-Base/HSRTReport/Modules/InfoBlocks.tex

259 lines
6.4 KiB
TeX

% !TEX root = ../../Main.tex
% ==== Colors ====
\definecolor{britishracinggreen}{rgb}{0.0, 0.26, 0.15}
\definecolor{eggplant}{rgb}{0.38, 0.25, 0.32}
\definecolor{hanblue}{rgb}{0.27, 0.42, 0.81}
\definecolor{navyblue}{rgb}{0.0, 0.0, 0.5}
\definecolor{pansypurple}{rgb}{0.47, 0.09, 0.29}
\definecolor{shockingpink}{rgb}{0.99, 0.06, 0.75}
% ==== Base Case ====
% Define a counter to track nesting level
\newcounter{coloredBoxLevel}
% Parameters:
\makeatletter
\define@key{coloredBox}{icon}{\def\coloredBoxIcon{#1}}
\define@key{coloredBox}{icon.prefix}{\def\coloredBoxIconPrefix{#1}}
\define@key{coloredBox}{icon.fontsize}{\def\coloredBoxIconSize{#1}}
\define@key{coloredBox}{icon.offset.x}{\def\coloredBoxIconOffsetX{#1}}
\define@key{coloredBox}{icon.offset.y}{\def\coloredBoxIconOffsetY{#1}}
\define@key{coloredBox}{icon.color}{\def\coloredBoxColor{#1}}
\define@key{coloredBox}{background.color}{\def\coloredBoxBackground{#1}}
\makeatother
% Define the environment
\NewEnviron{ColoredBox}[1][
icon={\faInfoCircle},
icon.color={blue},
icon.prefix={},
icon.fontsize={28pt},
icon.offset.x={0pt},
icon.offset.y={0pt},
background.color={blue}
]{
% Start of the environment
%% Setting the keys
\setkeys{coloredBox}{#1}
%% Set background opacity
% Increment the nesting level counter
\stepcounter{coloredBoxLevel}
% Set opacity based on the nesting level using a formula
\FPeval{\backgroundOpacityFloat}{0.05 + 0.075 * \arabic{coloredBoxLevel}}
% Convert the opacity to a percentage integer
\FPeval{\backgroundOpacity}{round(\backgroundOpacityFloat * 100, 0)}
% Always have the icon opacity 15% higher than the background
\FPeval{\iconOpacity}{\backgroundOpacity + 20}
%% === Content ===
\ifnum\value{coloredBoxLevel}=1
% Commands to only execute at the page level
\filbreak
\fi
\vspace*{0.5\baselineskip}
\noindent
\begin{minipage}{\linewidth}
\begin{mdframed}[
backgroundcolor={\coloredBoxBackground!\backgroundOpacity},
hidealllines=true,
skipabove=0.7\baselineskip,
skipbelow=0.7\baselineskip,
splitbottomskip=2pt,
splittopskip=4pt,
roundcorner=5pt
]
% [REFACTOR] using picture environment instead of tikz due to pgf errors
\begin{picture}(\textwidth, 0)(0, 0)
\put(\coloredBoxIconOffsetX-\coloredBoxIconSize,\coloredBoxIconOffsetY-0.7cm){
\fontsize{\coloredBoxIconSize}{\coloredBoxIconSize}
\selectfont
\color{\coloredBoxColor!\iconOpacity} \coloredBoxIcon
}
\end{picture}
\hspace*{0.25cm}
\begin{minipage}{\linewidth-0.5cm}
\vspace*{0.5\baselineskip}
\BODY
\vspace*{0.5\baselineskip}
\end{minipage}
\end{mdframed}
\end{minipage}
%% === /Content ===
% Reduce the nesting level counter
\addtocounter{coloredBoxLevel}{-1}
}
% ==== /Base Case ====
% ==== Info Box ====
% Derived from `ColoredBox`
\NewEnviron{InfoBox}[1][
icon={\faInfoCircle},
icon.color={blue},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={0pt},
icon.offset.y={0pt},
background.color={blue}
]{
\let\iBODY\BODY
\begin{ColoredBox}[#1]
\iBODY
\end{ColoredBox}
}
% ==== /Info Box ====
% ==== Warning Box ====
% Derived from `ColoredBox`
\NewEnviron{WarningBox}[1][
icon={\faExclamationTriangle},
icon.color={red},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={0pt},
icon.offset.y={0pt},
background.color={red}
]{
\let\wBODY\BODY
\begin{ColoredBox}[#1]
\wBODY
\end{ColoredBox}
}
% ==== /Warning Box ====
% ==== Success Box ====
% Derived from `ColoredBox`
\NewEnviron{SuccessBox}[1][
icon={\faCheckCircle},
icon.color={green},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={0pt},
icon.offset.y={2pt},
background.color={green}
]{
\let\sBODY\BODY
\begin{ColoredBox}[#1]
\sBODY
\end{ColoredBox}
}
% ==== /Success Box ====
% ==== Important Box ====
% Derived from `ColoredBox`
\NewEnviron{ImportantBox}[1][
icon={\faExclamationCircle},
icon.color={orange},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={0pt},
icon.offset.y={0pt},
background.color={orange}
]{
\let\impBODY\BODY
\begin{ColoredBox}[#1]
\impBODY
\end{ColoredBox}
}
% ==== Simpler Custom Boxes ====
% Environment `CustomBox`
% Usage:
% \begin{CustomBox}{<icon>}{<color>}
% ...
% \end{CustomBox}
% Parameters:
\NewEnviron{CustomBox}[2]{
\let\cBODY\BODY
\begin{ColoredBox}[
icon={#1},
icon.color={#2},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={0pt},
icon.offset.y={0pt},
background.color={#2}
]
\cBODY
\end{ColoredBox}
}
% ==== /Simpler Custom Boxes ====
% ==== Voting results Environment ====
% Using vote-yea Icon from fontawesome
\NewEnviron{VotingResultsBox}[1]{
\let\VotingResultsBODY\BODY
\begin{ColoredBox}[
icon={\faVoteYea},
icon.color={#1},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={-0.2cm},
icon.offset.y={0pt},
background.color={#1}
]
\VotingResultsBODY
\end{ColoredBox}
}
% ==== /Voting results Environment ====
% ==== Voting Results ====
% Derived from `VotingResultsBox`
\NewEnviron{VotingResults}[3]{
\let\voteBODY\BODY
% Choose the color based on the vote results
\ifnum#1>#2
\def\voteColor{britishracinggreen}
\else
\ifnum#1<#2
\def\voteColor{red}
\else
\def\voteColor{eggplant}
\fi
\fi
\begin{VotingResultsBox}{\voteColor}
\voteBODY
\begin{multicols}{3}
\begin{CustomBox}{\faThumbsUp}{britishracinggreen}
\textbf{Ja:} #1
\end{CustomBox}
\columnbreak
\begin{CustomBox}{\faThumbsDown}{red}
\textbf{Nein:} #2
\end{CustomBox}
\columnbreak
\begin{CustomBox}{\faQuestion}{eggplant}
\textbf{Enthaltung:} #3
\end{CustomBox}
\end{multicols}
\end{VotingResultsBox}
}
% ==== /Voting Results ====
% ==== Discussion Box ====
% Derived from `ColoredBox`
\NewEnviron{DiscussionBox}[1][
icon={\faComments},
icon.color={hanblue},
icon.prefix={},
icon.fontsize={24pt},
icon.offset.x={0pt},
icon.offset.y={0pt},
background.color={hanblue}
]{
\let\dBODY\BODY
\begin{ColoredBox}[#1]
\dBODY
\end{ColoredBox}
}
% ==== /Discussion Box ====