Comments (15)
You can also set an override flag on your widget, and check that before applying the constraint variable values. If the flag is set, ignore the constraint values and use the override values. There's lot's of ways you could solve this without hacking into the kiwi source.
from kiwi.
context
is there for you store anything you want to be associated with a variable. It can be any Python object, so storing a function there would be fine.
from kiwi.
What I want is a way to update effected widgets attributes when variable's value changed. I can think of two ways:
1, Associate the widget attribute with variable with context
attribute, and iterate solver->m_impl->m_vars
and apply variable value to widget attribute, after calling updateVariables
.
2, Hack Variable::setValue
method to set the value to widget attribute immediately.
Either way, I need to hack kiwi's source code somehow.
from kiwi.
What widgets are you talking about, and what attribute do you want to set?
If you are using Kiwi directly on your own, you know when you call updateVariables
, so you can just iterate your variables then. If you are talking about Enaml's widgets, you may be better off hooking into its layout system rather than hacking Kiwi's source.
Basically, I need to know more about what you are trying to do before I can give you better advice.
from kiwi.
I'm using kiwi on my own, and I want to only update the variables that are constrained rather than all the variables defined by widget.
For example, each widget defines left, top, width, height
, but for some widgets I only add a constraint for width
and height
, and want to set the left
and top
manually.
So I can only iterate the variables in solver->m_impl->m_rows
rather than all the variables defined by the widgets.
from kiwi.
PS, I find that there is a problem with solver->m_impl->m_vars
, is that it's never get removed except when reset the solver. So If I keep adding and removing constraints, the m_vars keep growing.
from kiwi.
m_impl
is private
and not part of the public API.
from kiwi.
If you want to set left
and top
of your widgets manually, you are free to do so. I'm not really seeing how this is an issue with Kiwi.
from kiwi.
The problem is I have no way to know which variable is constrained and which not (except through private m_impl->m_rows
I guess).
If I choose the enaml way to do this, then the left
and top
would be reseted to zero every time re-layout:
""" Update the geometry of the underlying toolkit widget.
This should not be called directly by user code.
"""
d = self.constrainable()
x = d.left.value()
y = d.top.value()
w = d.width.value()
h = d.height.value()
self.set_geometry(x, y, w, h)
from kiwi.
I've changed Variable
's initial value to NAN
, and set the value to NAN
if not found in m_rows
, so I can detect the un-constrained variables.
Here's the diff in case you are interested.
diff --git a/libs/kiwi/kiwi/solverimpl.h b/libs/kiwi/kiwi/solverimpl.h
index 33b0711..fd517cc 100644
--- a/libs/kiwi/kiwi/solverimpl.h
+++ b/libs/kiwi/kiwi/solverimpl.h
@@ -10,6 +10,7 @@
#include <limits>
#include <memory>
#include <vector>
+#include <cmath>
#include "constraint.h"
#include "errors.h"
#include "expression.h"
@@ -305,7 +306,7 @@ public:
Variable& var( const_cast<Variable&>( var_it->first ) );
row_iter_t row_it = m_rows.find( var_it->second );
if( row_it == row_end )
- var.setValue( 0.0 );
+ var.setValue( NAN );
else
var.setValue( row_it->second->constant() );
}
diff --git a/libs/kiwi/kiwi/variable.h b/libs/kiwi/kiwi/variable.h
index 525f434..e4de813 100644
--- a/libs/kiwi/kiwi/variable.h
+++ b/libs/kiwi/kiwi/variable.h
@@ -8,6 +8,7 @@
#pragma once
#include <memory>
#include <string>
+#include <cmath>
#include "shareddata.h"
@@ -91,13 +92,13 @@ private:
SharedData(),
m_name( name ),
m_context( context ),
- m_value( 0.0 ) {}
+ m_value(NAN) {}
VariableData( const char* name, Context* context ) :
SharedData(),
m_name( name ),
m_context( context ),
- m_value( 0.0 ) {}
+ m_value(NAN) {}
~VariableData() {}
from kiwi.
You said you are using kiwi on your own. So you should know if the variables are constrained or not because you added them to the solver.
from kiwi.
You can also just added a constraint for the left
and top
values to constrain them to what you want e.g.: left == 42, top == 78
from kiwi.
Updating a constraint is more expensive, since it could be an animation or scrollview updating it every frame.
Traversing the constraint structure to find out what variables it uses is doable i think.
from kiwi.
Setting a flag is another useful feature I think, but I still think checking the NAN is a good default behaviour, thanks for your suggestions ;D
from kiwi.
Checking for NAN values doesn't cover a situation where constraints have been added and then removed later. The variables may still be underconstrained..
from kiwi.
Related Issues (20)
- 1.3.2 final tag is not on GitHub HOT 3
- The performance compare when create many constraint use different language realize kiwi, why my c++ code is slow? HOT 4
- Missing wheel dependency? Installation fails. HOT 3
- Build fails with gcc on macOS HOT 2
- Is there a way to test if a constraint was broken? HOT 9
- 1.4.0 fails to build from source HOT 22
- Documentation: How to build on Windows HOT 5
- AssocVector implicit copy constructor warning
- Not compatible with setuptools >=61 HOT 1
- License info on PyPI contains complete license text HOT 5
- 1.4.2: pep517 warnings HOT 18
- pip install fails on Python 3.11b3 HOT 17
- Failed building wheel for kiwisolver :( HOT 4
- Cann't install on python 3.11b3 HOT 2
- 1.4.3 has no attribute __version__ HOT 2
- ERROR: Failed building wheel for kiwisolver: C2440: 'static_cast': cannot convert from 'expr_type' to 'type' HOT 2
- Provide cp311 releases HOT 1
- Objective cell memory leak? HOT 26
- Continuous fuzzing by way of Google's OSS-Fuzz HOT 1
- Tests fail on pypy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kiwi.