%% This is file `beamerouterthemeBFH-headbar.sty' version 0.1 (2026-09-10),
%% an add-on for
%% BFH-CI -- Corporate Design for Bern University of Applied Sciences
%% ----------------------------------------------------------------------------
%%
%%  Derived from `beamerouterthemeBFH.sty' and `beamerouterthemeBFH-sidebar.sty'
%%      Copyright (C) 2021--2026 by
%%      Marei Peischl <marei@peitex.de>
%%      Andreas Habegger <andreas.habegger@bfh.ch>
%%
%%  The head bar layout follows the idea of the `miniframes' outer theme
%%  (as used by the beamer theme `Singapore')
%%      Copyright 2007 by Till Tantau
%%      Copyright 2015 by Vedran Mileti\'c, Joseph Wright
%%
%% ============================================================================
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%%
%% ============================================================================
%%
%% This is an unofficial variant of the BFH-CI beamer outer theme. It replaces
%% the vertical navigation of `beamerouterthemeBFH-sidebar' by a horizontal
%% navigation bar in the head line, similar to the beamer theme `Singapore'.
%% Everything else (colors, fonts, footline, frame titles, title pages) is
%% inherited unchanged from the BFH-CI themes.
%%
%% Usage:
%%   \documentclass{bfhbeamer}
%%   \useoutertheme{BFH-headbar}
%%
%% Options (given as \useoutertheme[<options>]{BFH-headbar}):
%%   subsection = true|false   show the current subsection below the
%%                                 navigation (default: true)
%%   version    = true|false   show \version{...} at the right of the
%%                                 subsection line (default: true)
%%   subline    = true|false   show the second head line at all
%%                             (default: true)
%%   logo       = true|false   show the BFH logo at the right end of the
%%                             navigation bar; requires the bfhlogo package
%%                             (default: false)
%%   rule       = <dimen>      thickness of the orange rule below the head bar
%%                             (default: 1.5pt); use rule=0pt to remove it
%%   compress   = true|false   put all mini frames of a section into a single
%%                             row (default: false)
%%
%% Notes:
%%   * Like every navigation bar this theme only makes sense in a document
%%     that uses \section. Without sections the bar stays empty; use the
%%     plain `BFH' outer theme in that case.
%%   * Do not combine it with `BFH-sidebar' -- both are outer themes and would
%%     fight over the same templates.
%%   * Run LaTeX twice so that the navigation knows about all sections.
%%
\ProvidesPackage{beamerouterthemeBFH-headbar}[2026-09-10 v0.1 BFH-CI beamer outer theme headbar variant, CI of Bern University of Applied Sciences]


\mode<presentation>

%% ============================================================================
%% Inherit the BFH outer theme (footline, frame title, ...)
%% ============================================================================
\useoutertheme{BFH}

\ExplSyntaxOn


%% ============================================================================
%% Navigation entries
%% ============================================================================
%
% Redefined so that only the current section is emphasized. The beamer default
% for the shaded variant is \color{fg!50!bg}, which would render the inactive
% sections as a washed out orange instead of BFH-Gray.

\defbeamertemplate*{section~in~head/foot~shaded}{BFH-headbar}{%
	{\usebeamercolor[fg]{section~in~head/foot~shaded}\usebeamerfont{section~in~head/foot~shaded}\insertsectionhead}%
}

\defbeamertemplate*{navigation~in~head/foot}{BFH-headbar}{%
	% \insertnavigation insets its content by .3cm on both sides; compensate
	% for that so the bar lines up with the BFH text margins.
	\makebox[\linewidth][c]{
		\ifbeamertemplateempty{icon~in~head/foot/sidebar}{
				\insertnavigation{\dim_eval:n {\linewidth + .6cm}}%
		}{
			\insertnavigation{\dim_eval:n {\linewidth - \box_wd:N \g__ptxcd_frame_logo_box}}%
			\raisebox{\dim_eval:n {-.5\height+.5\ht\stutbox}}
			{\usebeamertemplate*{icon in head/foot/sidebar}}
		}%
	}
}

%% ============================================================================
%% Head line
%% ============================================================================

\defbeamertemplate*{headline}{BFH-headbar}{%
\usebeamertemplate***{progressbar~headline}\par\nointerlineskip
\begin{beamercolorbox}[
	leftskip=\beamer@leftmargin,rightskip=\beamer@rightmargin,
	vmode]{headline}
	\setlength{\linewidth}{\dimexpr\paperwidth-\beamer@leftmargin-\beamer@rightmargin}
	\setlength{\hsize}{\dimexpr\paperwidth-\beamer@leftmargin-\beamer@rightmargin}
	\vskip\baselineskip
    \vskip-.7\baselineskip
	  \usebeamertemplate{navigation~in~head/foot}%
		% the mini frames stick out below the declared box dimensions
	\par
	\vskip2ex
  \usebeamertemplate{subheadline}
	\end{beamercolorbox}%
	\par\nointerlineskip
	\usebeamertemplate{headbar~rule}
	\par
	\nointerlineskip
}

\defbeamertemplate*{headbar~rule}{BFH}{
	\begin{beamercolorbox}[wd=\paperwidth,ht=\l__ptxcd_headbar_rule_dim,dp=0pt]{headbar~rule}
	\end{beamercolorbox}%
}

\defbeamertemplate*{headbar~rule}{BFH-progressbar}{
	\begingroup
	\keys_set:nn {ptxcd/beamer/outer/progressbar} {height=\l__ptxcd_headbar_rule_dim}
	\usebeamertemplate{progressbar}
	\endgroup
}

\bool_new:N \g__ptxcd_headbar_version_or_subsection_bool

\defbeamertemplate{subheadline}{BFH-headbar}{
	\bool_if:NT \g__ptxcd_headbar_version_or_subsection_bool {
		\rule[-1ex]{0pt}{2.25ex}\strut
		\makebox[\linewidth]{
		\usebeamercolor{subsection~in~head/foot}\color{fg}%
		\bool_if:NT \g__ptxcd_headbar_subsection_bool {
			\usebeamerfont{subsection~in~head/foot}%
			\usebeamertemplate*{subsection~in~head/foot}%
		}
		\hfill	
		\usebeamertemplate*{version~in~head/foot/sidebar}
		}
  }
	\par
}[action]{
	\bool_gset_false:N	\g__ptxcd_headbar_version_or_subsection_bool
	\ifbeamertemplateempty{version~in~head/foot/sidebar} {}{\bool_gset_true:N \g__ptxcd_headbar_version_or_subsection_bool}
	\ifbeamertemplateempty{subsection~in~head/foot} {}{\bool_gset_true:N \g__ptxcd_headbar_version_or_subsection_bool}
}

%% ============================================================================
%% Options
%% to avoid creating booleans to switch templates the templates have to be defined before the options
%% ============================================================================


\keys_define:nn {ptxcd/beamer/outer} {
	subsection .bool_gset:N = \g__ptxcd_headbar_subsection_bool,
	subsection .initial:n    = true,
	subsection .default:n    = true,
%
	subline .choice:,
  subline / true .code:n = \setbeamertemplate{subheadline}[BFH-headbar],
  subline /false .code:n = \setbeamertemplate{subheadline}{},
	subline .default:n = true,
	subline .initial:n = true,
%
	headbar-rule .dim_set:N = \l__ptxcd_headbar_rule_dim,
	headbar-rule .initial:n  = 1.5pt,
	headbar/rule .meta:n = {headbar-rule=#1},
}

\ProcessKeyOptions[ptxcd/beamer/outer]

\ifbeamertemplateempty{subheadline}{}{
	\setbeamertemplate{subheadline}[BFH-headbar]
}


\mode<all>

\endinput
