Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/foxtools/MFXDynamicLabel.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file MFXDynamicLabel.h
15
/// @author Mirko Barthauer
16
/// @date 31.03.2023
17
///
18
// Text label with dynamic multi-line text (inserts line breaks on the fly)
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <string>
24
25
#include "fxheader.h"
26
27
28
/// @brief A list item which allows for custom coloring
29
class MFXDynamicLabel : public FXLabel {
30
/// @brief FOX declaration
31
FXDECLARE(MFXDynamicLabel)
32
33
public:
34
/// @brief enum for events
35
enum {
36
MID_LABEL_WIDTHCHANGE,
37
};
38
39
/// @brief Construct label with given text and icon
40
MFXDynamicLabel(FXComposite* p, const FXString& text, FXIcon* ic = 0, FXuint opts = LABEL_NORMAL, FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0, FXint pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD, std::string indent = "- ");
41
42
virtual ~MFXDynamicLabel() {};
43
44
/// @brief overload text label updates to store the original string as backup for when width changes again
45
void setText(const FXString& text);
46
47
/// @brief overload to be informed when the label text has to be reformatted due to width changes
48
long onUpdate(FXObject* sender, FXSelector, void*);
49
50
/// @brief overload position to be informed when the parent has done the layout
51
void position(FXint x, FXint y, FXint w, FXint h);
52
53
FXint getDefaultHeight();
54
55
protected:
56
/// @brief fox needs this
57
MFXDynamicLabel();
58
59
private:
60
/// @brief compute indentation
61
void computeIndentation();
62
63
/// @brief reformat line breaks
64
void reformatLineBreaks(const int curWidth);
65
66
/// @brief original string
67
std::string myOriginalString;
68
69
/// @brief indent string
70
std::string myIndentString;
71
72
/// @brief indent
73
int myIndent;
74
75
/// @brief previous width
76
int myPreviousWidth;
77
78
/// @brief Invalidated copy constructor.
79
MFXDynamicLabel(const MFXDynamicLabel&) = delete;
80
81
/// @brief Invalidated assignment operator.
82
MFXDynamicLabel& operator=(const MFXDynamicLabel&) = delete;
83
};
84
85