WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
ShuffleboardComponent.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <string_view>
8
11#include <wpi/StringMap.h>
12
14
15namespace frc {
16
17class ShuffleboardContainer;
18
19/**
20 * A generic component in Shuffleboard.
21 *
22 * @tparam Derived the self type
23 */
24template <typename Derived>
26 public:
27 /**
28 * Constructs a ShuffleboardComponent.
29 *
30 * @param parent The parent container.
31 * @param title The component title.
32 * @param type The component type.
33 */
34 ShuffleboardComponent(ShuffleboardContainer& parent, std::string_view title,
35 std::string_view type = "")
36 : ShuffleboardValue(title),
37 ShuffleboardComponentBase(parent, title, type) {}
38
39 /**
40 * Sets custom properties for this component. Property names are
41 * case-sensitive and whitespace-insensitive (capitalization and spaces do not
42 * matter).
43 *
44 * @param properties the properties for this component
45 * @return this component
46 */
47 Derived& WithProperties(const wpi::StringMap<nt::Value>& properties) {
48 m_properties = properties;
49 m_metadataDirty = true;
50 return *static_cast<Derived*>(this);
51 }
52
53 /**
54 * Sets the position of this component in the tab. This has no effect if this
55 * component is inside a layout.
56 *
57 * If the position of a single component is set, it is recommended to set the
58 * positions of <i>all</i> components inside a tab to prevent Shuffleboard
59 * from automatically placing another component there before the one with the
60 * specific position is sent.
61 *
62 * @param columnIndex the column in the tab to place this component
63 * @param rowIndex the row in the tab to place this component
64 * @return this component
65 */
66 Derived& WithPosition(int columnIndex, int rowIndex) {
67 m_column = columnIndex;
68 m_row = rowIndex;
69 m_metadataDirty = true;
70 return *static_cast<Derived*>(this);
71 }
72
73 /**
74 * Sets the size of this component in the tab. This has no effect if this
75 * component is inside a layout.
76 *
77 * @param width how many columns wide the component should be
78 * @param height how many rows high the component should be
79 * @return this component
80 */
81 Derived& WithSize(int width, int height) {
82 m_width = width;
83 m_height = height;
84 m_metadataDirty = true;
85 return *static_cast<Derived*>(this);
86 }
87};
88
89} // namespace frc
A shim class to allow storing ShuffleboardComponents in arrays.
Definition ShuffleboardComponentBase.h:24
int m_width
Definition ShuffleboardComponentBase.h:42
wpi::StringMap< nt::Value > m_properties
Definition ShuffleboardComponentBase.h:38
bool m_metadataDirty
Definition ShuffleboardComponentBase.h:39
int m_height
Definition ShuffleboardComponentBase.h:43
int m_row
Definition ShuffleboardComponentBase.h:41
int m_column
Definition ShuffleboardComponentBase.h:40
A generic component in Shuffleboard.
Definition ShuffleboardComponent.h:25
Derived & WithSize(int width, int height)
Sets the size of this component in the tab.
Definition ShuffleboardComponent.h:81
Derived & WithProperties(const wpi::StringMap< nt::Value > &properties)
Sets custom properties for this component.
Definition ShuffleboardComponent.h:47
ShuffleboardComponent(ShuffleboardContainer &parent, std::string_view title, std::string_view type="")
Constructs a ShuffleboardComponent.
Definition ShuffleboardComponent.h:34
Derived & WithPosition(int columnIndex, int rowIndex)
Sets the position of this component in the tab.
Definition ShuffleboardComponent.h:66
Common interface for objects that can contain shuffleboard components.
Definition ShuffleboardContainer.h:42
Definition ShuffleboardValue.h:15
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.h:26
Definition CAN.h:11