MCPcopy Create free account
hub / github.com/SpartanJ/eepp / getMaxColumnContentWidth

Method getMaxColumnContentWidth

src/eepp/ui/uitableview.cpp:133–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133Float UITableView::getMaxColumnContentWidth( const size_t& colIndex, bool bestGuess ) {
134 Float lWidth = 0;
135 ConditionalLock l( getModel() != nullptr, getModel() ? &getModel()->resourceMutex() : nullptr );
136 if ( nullptr == getModel() || !getModel()->hasChildren() )
137 return lWidth;
138 ScopedOp op( [this] { mUISceneNode->setIsLoading( true ); },
139 [this] { mUISceneNode->setIsLoading( false ); } );
140 Float yOffset = getHeaderHeight();
141 auto worstCaseFunc = [&]( const ModelIndex& index ) {
142 UIWidget* widget = updateCell( { (Int64)0, (Int64)0 }, index, 0, yOffset );
143 if ( widget->isType( UI_TYPE_PUSHBUTTON ) ) {
144 Float w = widget->asType<UIPushButton>()->getContentSize().getWidth();
145 if ( w > lWidth )
146 lWidth = w;
147 }
148 };
149 // TODO: Improve best guess
150 if ( bestGuess && getItemCount() > 10 ) {
151 Variant dataTest( getModel()->data( getModel()->index( 0, colIndex ) ) );
152 if ( dataTest.isString() ) {
153 std::map<size_t, ModelIndex> lengths;
154 for ( size_t i = 0; i < getItemCount(); i++ ) {
155 ModelIndex index( getModel()->index( i, colIndex ) );
156 Variant data( getModel()->data( index ) );
157 if ( !data.isValid() )
158 continue;
159 size_t length = data.size();
160 if ( lengths.empty() || length > lengths.rbegin()->first )
161 lengths[length] = index;
162 }
163 size_t i = 0;
164 auto it = lengths.rbegin();
165 for ( ; it != lengths.rend() && i < 10; it++, i++ )
166 worstCaseFunc( it->second );
167 } else {
168 for ( size_t i = 0; i < getItemCount(); i++ )
169 worstCaseFunc( getModel()->index( i, colIndex ) );
170 }
171 } else {
172 for ( size_t i = 0; i < getItemCount(); i++ )
173 worstCaseFunc( getModel()->index( i, colIndex ) );
174 }
175 return lWidth;
176}
177
178void UITableView::createOrUpdateColumns( bool resetColumnData ) {
179 if ( !getModel() ) {

Callers

nothing calls this directly

Calls 14

getModelFunction · 0.85
setIsLoadingMethod · 0.80
isStringMethod · 0.80
rbeginMethod · 0.80
rendMethod · 0.80
hasChildrenMethod · 0.45
isTypeMethod · 0.45
getWidthMethod · 0.45
getContentSizeMethod · 0.45
dataMethod · 0.45
indexMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected