summaryrefslogtreecommitdiff
path: root/wx+
diff options
context:
space:
mode:
Diffstat (limited to 'wx+')
-rw-r--r--wx+/choice_enum.h16
-rw-r--r--wx+/graph.cpp11
-rw-r--r--wx+/graph.h6
-rw-r--r--wx+/grid.cpp6
-rw-r--r--wx+/grid.h16
5 files changed, 26 insertions, 29 deletions
diff --git a/wx+/choice_enum.h b/wx+/choice_enum.h
index a590861a..a25bf104 100644
--- a/wx+/choice_enum.h
+++ b/wx+/choice_enum.h
@@ -48,7 +48,7 @@ struct EnumDescrList
using DescrList = std::vector<std::pair<Enum, std::pair<wxString, wxString>>>;
DescrList descrList;
- std::unordered_map<const wxChoice*, std::vector<wxString>> itemsSetLast;
+ std::unordered_map<const wxChoice*, std::vector<wxString>> labelsSetLast;
};
template <class Enum> void setEnumVal(const EnumDescrList<Enum>& mapping, wxChoice& ctrl, Enum value);
template <class Enum> Enum getEnumVal(const EnumDescrList<Enum>& mapping, const wxChoice& ctrl);
@@ -71,16 +71,16 @@ template <class Enum> void updateTooltipEnumVal(const EnumDescrList<Enum>& mappi
template <class Enum>
void setEnumVal(EnumDescrList<Enum>& mapping, wxChoice& ctrl, Enum value)
{
- auto& itemsSetLast = mapping.itemsSetLast[&ctrl];
+ auto& labelsSetLast = mapping.labelsSetLast[&ctrl];
- std::vector<wxString> items;
- for (auto it = mapping.descrList.begin(); it != mapping.descrList.end(); ++it)
- items.push_back(it->second.first);
+ std::vector<wxString> labels;
+ for (const auto& [val, texts] : mapping.descrList)
+ labels.push_back(texts.first);
- if (items != itemsSetLast)
+ if (labels != labelsSetLast)
{
- ctrl.Set(items); //expensive as fuck! => only call when absolutely needed!
- itemsSetLast = std::move(items);
+ ctrl.Set(labels); //expensive as fuck! => only call when absolutely needed!
+ labelsSetLast = std::move(labels);
}
//-----------------------------------------------------------------
diff --git a/wx+/graph.cpp b/wx+/graph.cpp
index be75ac4d..8dec2074 100644
--- a/wx+/graph.cpp
+++ b/wx+/graph.cpp
@@ -511,7 +511,7 @@ void Graph2D::onMouseCaptureLost(wxMouseCaptureLostEvent& event)
}
-void Graph2D::addCurve(const std::shared_ptr<CurveData>& data, const CurveAttributes& ca)
+void Graph2D::addCurve(const SharedRef<CurveData>& data, const CurveAttributes& ca)
{
CurveAttributes newAttr = ca;
if (newAttr.autoColor)
@@ -587,10 +587,9 @@ void Graph2D::render(wxDC& dc) const
//detect x value range
double minX = attr_.minX ? *attr_.minX : std::numeric_limits<double>::infinity(); //automatic: ensure values are initialized by first curve
double maxX = attr_.maxX ? *attr_.maxX : -std::numeric_limits<double>::infinity(); //
- for (auto it = curves_.begin(); it != curves_.end(); ++it)
- if (const CurveData* curve = it->first.get())
+ for (const auto& [curve, attrib] : curves_)
{
- const std::pair<double, double> rangeX = curve->getRangeX();
+ const std::pair<double, double> rangeX = curve.ref().getRangeX();
assert(rangeX.first <= rangeX.second + 1.0e-9);
//GCC fucks up badly when comparing two *binary identical* doubles and finds "begin > end" with diff of 1e-18
@@ -620,12 +619,12 @@ void Graph2D::render(wxDC& dc) const
std::vector<std::vector<char>> oobMarker (curves_.size()); //effectively a std::vector<bool> marking points that start an out-of-bounds line
for (size_t index = 0; index < curves_.size(); ++index)
- if (const CurveData* curve = curves_[index].first.get())
{
+ const CurveData& curve = curves_ [index].first.ref();
std::vector<CurvePoint>& points = curvePoints[index];
auto& marker = oobMarker [index];
- points = curve->getPoints(minX, maxX, graphArea.GetSize());
+ points = curve.getPoints(minX, maxX, graphArea.GetSize());
marker.resize(points.size()); //default value: false
if (!points.empty())
{
diff --git a/wx+/graph.h b/wx+/graph.h
index 288ef9e7..55734a06 100644
--- a/wx+/graph.h
+++ b/wx+/graph.h
@@ -25,7 +25,7 @@ namespace zen
setLabelX(Graph2D::LABEL_X_BOTTOM, 20, std::make_shared<LabelFormatterTimeElapsed>()).
setLabelY(Graph2D::LABEL_Y_RIGHT, 60, std::make_shared<LabelFormatterBytes>()));
//set graph data
- std::shared_ptr<CurveData> curveDataBytes_ = ...
+ SharedRef<CurveData> curveDataBytes_ = ...
m_panelGraph->setCurve(curveDataBytes_, Graph2D::CurveAttributes().setLineWidth(2).setColor(wxColor(0, 192, 0))); */
struct CurvePoint
@@ -215,7 +215,7 @@ public:
int lineWidth = fastFromDIP(2);
};
- void addCurve(const std::shared_ptr<CurveData>& data, const CurveAttributes& ca = CurveAttributes());
+ void addCurve(const SharedRef<CurveData>& data, const CurveAttributes& ca = CurveAttributes());
void clearCurves() { curves_.clear(); }
static wxColor getBorderColor() { return {130, 135, 144}; } //medium grey, the same Win7 uses for other frame borders => not accessible! but no big deal...
@@ -326,7 +326,7 @@ private:
std::optional<wxBitmap> doubleBuffer_;
- using CurveList = std::vector<std::pair<std::shared_ptr<CurveData>, CurveAttributes>>;
+ using CurveList = std::vector<std::pair<SharedRef<CurveData>, CurveAttributes>>;
CurveList curves_;
//perf!!! generating the font is *very* expensive! => buffer for Graph2D::render()!
diff --git a/wx+/grid.cpp b/wx+/grid.cpp
index ab9babbb..fb9aacbc 100644
--- a/wx+/grid.cpp
+++ b/wx+/grid.cpp
@@ -1641,6 +1641,12 @@ void Grid::updateWindowSizes(bool updateScrollbar)
wxSize Grid::GetSizeAvailableForScrollTarget(const wxSize& size)
{
+ //1. "size == GetSize() == (0, 0)" happens temporarily during initialization
+ //2. often it's even (0, 20)
+ //3. fuck knows why, but we *temporarily* get "size == GetSize() == (1, 1)" when wxAUI panel containing Grid is dropped
+ if (size.x <= 1 || size.y <= 1)
+ return {}; //probably best considering calling code in generic/scrlwing.cpp: wxScrollHelper::AdjustScrollbars()
+
//1. calculate row label width independent from scrollbars
const int mainWinHeightGross = std::max(0, size.GetHeight() - getColumnLabelHeight()); //independent from client sizes and scrollbars!
const ptrdiff_t logicalHeight = rowLabelWin_->getLogicalHeight(); //
diff --git a/wx+/grid.h b/wx+/grid.h
index 4de76b66..8ab03932 100644
--- a/wx+/grid.h
+++ b/wx+/grid.h
@@ -12,6 +12,7 @@
#include <optional>
#include <set>
#include <vector>
+#include <zen/stl_tools.h>
//#include <zen/basic_math.h>
#include <wx/scrolwin.h>
@@ -366,18 +367,9 @@ private:
template <class ColAttrReal>
std::vector<ColAttrReal> makeConsistent(const std::vector<ColAttrReal>& attribs, const std::vector<ColAttrReal>& defaults)
{
- using ColTypeReal = decltype(ColAttrReal().type);
- std::vector<ColAttrReal> output;
-
- std::set<ColTypeReal> usedTypes; //remove duplicates
- auto appendUnique = [&](const std::vector<ColAttrReal>& attr)
- {
- std::copy_if(attr.begin(), attr.end(), std::back_inserter(output),
- [&](const ColAttrReal& a) { return usedTypes.insert(a.type).second; });
- };
- appendUnique(attribs);
- appendUnique(defaults); //make sure each type is existing!
-
+ std::vector<ColAttrReal> output = attribs;
+ append(output, defaults); //make sure each type is existing!
+ removeDuplicatesStable(output, [](const ColAttrReal& lhs, const ColAttrReal& rhs) { return lhs.type < rhs.type; });
return output;
}
bgstack15