Skip to content

Commit

Permalink
Control panel basics
Browse files Browse the repository at this point in the history
  • Loading branch information
lemniscate8 committed Aug 9, 2021
1 parent 6ebd496 commit 9f5a3fd
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 10 deletions.
63 changes: 63 additions & 0 deletions include/emp/prefab/ControlPanel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef EMP_CONTROL_PANEL_HPP
#define EMP_CONTROL_PANEL_HPP

#include "emp/base/optional.hpp"
#include "emp/prefab/ButtonGroup.hpp"
#include "emp/prefab/ToggleButtonGroup.hpp"
#include "emp/prefab/FontAwesomeIcon.hpp"
#include "emp/tools/string_utils.hpp"
#include "emp/web/Div.hpp"

namespace emp::prefab {

class EndGroup {};

class ControlPanel : public web::Div {

ToggleButtonGroup play_pause_toggle;
optional<web::Div> active_group;

protected:
ControlPanel(web::internal::DivInfo * in_info) : web::Div(in_info),
play_pause_toggle(ToggleButtonGroup{
FontAwesomeIcon{"fa-play"}, FontAwesomeIcon{"fa-pause"},
"success", "warning",
true, false, emp::to_string(GetID(), "_play_pause")
})
{
AddAttr(
"class", "btn-toolbar",
"class", "space_groups",
"role", "toolbar",
"aria-label", "Toolbar with simulation controls"
);
active_group = ButtonGroup{};
*active_group << play_pause_toggle;
static_cast<Div>(*this) << *active_group;
}

public:
ControlPanel(const std::string & in_id="")
: ControlPanel(new web::internal::DivInfo(in_id)) { ; }

template <typename IN_TYPE>
emp::prefab::ControlPanel & operator<<(IN_TYPE && in_val) {
if constexpr(std::is_same<IN_TYPE, emp::prefab::ButtonGroup>::value) {
std::cout << "BG in!" << std::endl;
active_group = in_val;
static_cast<Div>(*this) << *active_group;
} else if constexpr(std::is_same<IN_TYPE, emp::prefab::EndGroup>::value) {
active_group = {};
} else {
if(!active_group.has_value()) {
active_group = ButtonGroup{};
static_cast<Div>(*this) << *active_group;
}
*active_group << std::forward<IN_TYPE>(in_val);
}
return (*this);
}
};
}

#endif
8 changes: 7 additions & 1 deletion include/emp/prefab/DefaultPrefabStyles.less
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,15 @@
display: none;
}

// -------------- ToolBar --------------

.btn-toolbar.space_groups > :not(:last-child) {
margin-right: .5rem;
}

// -------------- ToggleButtonGroup --------------

// Overrides nested toggel button group styles when using "hide_active" to turn
// Overrides nested toggle button group styles when using "hide_active" to turn
// cassette style buttons into play/pause style and "grayout" to add additional
// visual cues

Expand Down
18 changes: 9 additions & 9 deletions include/emp/prefab/ToggleButtonGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define EMP_TOGGLE_BUTTON_GROUP_HPP

#include "emp/tools/string_utils.hpp"
#include "emp/prefab/FontAwesomeIcon.hpp"
#include "emp/web/Element.hpp"
#include "emp/web/Input.hpp"

Expand Down Expand Up @@ -53,7 +52,7 @@ namespace emp::prefab {
* @param activate_indicator a string, FontAwesomeIcon or other component
* indicating that the first button actives this toggle
* @param deactivate_indicator a string, FontAwesomeIcon or other component
* indicating that the second button deactives this toggle
* indicating that the second button deactivates this toggle
* @param activate_style a bootstrap style (primary, secondary, etc) for
* the first button
* @param deactivate_style a bootstrap style (primary, secondary, etc) for
Expand All @@ -65,8 +64,8 @@ namespace emp::prefab {
*/
template<typename L1_TYPE, typename L2_TYPE>
ToggleButtonGroup(
L1_TYPE & activate_indicator,
L2_TYPE & deactivate_indicator,
L1_TYPE && activate_indicator,
L2_TYPE && deactivate_indicator,
const std::string & activate_style,
const std::string & deactivate_style,
const bool & cassette_style,
Expand Down Expand Up @@ -99,7 +98,7 @@ namespace emp::prefab {
false, false
);
activate_label << activate_radio;
activate_label << activate_indicator;
activate_label << std::forward<L1_TYPE>(activate_indicator);

deactivate_label.AddAttr(
"class", "active",
Expand All @@ -112,21 +111,22 @@ namespace emp::prefab {
false, true
);
deactivate_label << deactivate_radio;
deactivate_label << deactivate_indicator;
deactivate_label << std::forward<L2_TYPE>(deactivate_indicator);
}

public:
template<typename L1_TYPE, typename L2_TYPE>
ToggleButtonGroup(
L1_TYPE & activate_indicator,
L2_TYPE & deactivate_indicator,
L1_TYPE && activate_indicator,
L2_TYPE && deactivate_indicator,
const std::string & activate_style="success",
const std::string & deactivate_style="warning",
const bool & cassette_style=true,
const bool & grayout=false,
const std::string & in_id=""
) : ToggleButtonGroup(
activate_indicator, deactivate_indicator,
std::forward<L1_TYPE>(activate_indicator),
std::forward<L2_TYPE>(deactivate_indicator),
activate_style, deactivate_style,
cassette_style, grayout,
new internal::ToggleButtonGroupInfo(in_id)
Expand Down
2 changes: 2 additions & 0 deletions include/emp/web/Div.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

namespace emp::prefab {
class ButtonGroup;
class ControlPanel;
}

namespace emp {
Expand All @@ -57,6 +58,7 @@ namespace web {
class DivInfo : public internal::WidgetInfo {
friend Element; friend Div; friend TableInfo;
friend prefab::ButtonGroup;
friend prefab::ControlPanel;
protected:
double scroll_top; ///< Where should div scroll to? (0.0 to 1.0)
emp::vector<Widget> m_children; ///< Widgets contained in this one.
Expand Down

0 comments on commit 9f5a3fd

Please sign in to comment.