I am using the Alloy framework to build a mobile application in Appcelerator Studio. To build the user interface i am using the *.tss files (sort of css) and using constants like Titanium.UI.SIZE or Titanium.UI.FILL for the width and height properties of the UI components.
I was wondering if there is a sort of css CALC method available in the Alloy framework, such that is possible to do size calculations like this:
width: calc(Titanium.UI.FILL - 20px)
height: calc(80% - 30px)
Thanks in advance!
If you are setting the width or height inside the .tss file, you have to set the value to an property of the Alloy global object (Alloy.CFG.yourVar or Alloy.Globals.yourVar).
alloy.js
Alloy.CFG.width = Ti.Platform.displayCaps.platformWidth - 20;
view.tss
"#myView":{
width:Alloy.CFG.width
}
If you set the value in your controller, you don't need to use like a global object property.
index.js
$.myView.width = Ti.Platform.displayCaps.platformWidth - 20;
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Platform.DisplayCaps-property-platformHeight
TSS (Titanium Style Sheet) is not CSS. It purely declarative json file - but you can use some Titanium code inside it like Ti.UI.FILL or Ti.UI.SIZE or for translation you could use the L() function.
As a solution for having calculated values, I see 3 possible ways:
Pre-calculating what you need as part of an app bootstrap inside alloy.js, and storing it in alloy as part of a "namespace" - do note that it will reside on the "global scope" - but I don't think that's what's going to bring your app down. So you would have something like this:
Alloy.js:
Alloy.UI.MyScreen.MyComponent.height = DO YOU CALCULATION HERE;
ControllerStyle.tss:
"#myComponent" : {
height: Alloy.UI.MyScreen.MyComponent.height
}
Make sure you build your namespace right and use closures to not pollute the global scope.
For more information on alloy.js see here: http://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Controllers-section-34636384_AlloyControllers-InitializerFile(alloy.js)
A second solution would be to use Dynamic Styles. See here: http://docs.appcelerator.com/platform/latest/#!/guide/Dynamic_Styles
Third solution would be to apply the properties you need in your controller code - this one is my least favorite because it forces you to "cross the bridge" between js and native when your controller loads and slows you down.
One thing you can do is pre-calculate it, another is set the calculated width not in tss but in the controller file.
What I tend to do, when I need to calculate something like this is pre-calculate this and use it throughout the app if there is more than 1 purpose of using it. Do this for example in alloy.js
Alloy.Globals.marginContentWidth = 300;
Or you can use any contant from the Ti Platform to calculate something. Now in tss you can use this
"#myUI": {
width: Alloy.Globals.marginContentWidth
}
This will work for you.
Another thing is not thinking about mobile UI like you do with a website. On mobile you need to think more flexible. One of the reasons you probably want width - 20px is because you want margin of 10px on both sides.
First off... don't use px. In mobile development you need points, or dp, but this is default so you can just use 20. To handle it more flexible, do this:
width: Ti.UI.FILL,
right: 10,
left: 10
This should fix your problem nicely
First of all .tss is not a sort of .css :), rather it is sort of json file.
Now what you want to do, you will need to learn Alloy & Titanium a bit deeper as you can do every sort of calculations in Titanium but there are other ways and perhaps since you are comparing it to .css, you are not getting it right.
So, I suggest you to first learn what Alloy & Titanium is and how they work and how they support each other.
You can always head on to the Titanium Docs which are absolutely clear to get you started on a right path. First give them a try, take time to learn things and we are always here to support you. :)
Good luck!
Related
I would like to order "circle" features in a layer in Mapbox studio. The entire Style, including this layer and other layers, is added to a map using GL.JS, and symbology for the layers are set in studio.
I see the documentation for circle-sort-key for gl-js style specification, but don't see where to set it along side the other properties (raduis, color, opacity, etc) for the layer style in studio.
Yes, it appears you can't set it within Studio.
However, you can set it using JS if you want:
map.setLayoutProperty('mylayer', 'circle-sort-key', ...)
Since the documentation doesn't give a detailed example, I'm adding my final solution here.
Following #steve-bennett's suggestion, to sort the smallest circles on top:
map.setLayoutProperty('layername','circle-sort-key',["*", -1, ["get", "propertyname"]])
How can I disallow rotation of a node in SceneKit?
For ex., I want a model (cone) to be dynamic, jumping and flying, but always vertically oriented?
I tried fix it like in apple's vehicle demo, it is bad solution. Also I tried below code, but model just slowly and glitchy falls down
- (void)renderer:(id<SCNSceneRenderer>)aRenderer didSimulatePhysicsAtTime:(NSTimeInterval)time{
_node.rotation = SCNVector4Make(0, 0, 0, 0);
//[_node.physicsBody resetTransform]; // - tried this too
}
...and finally I did not find any "allowRotation=NO" in scenekit manuals.
Instead of a Boolean allowsRotation flag like in SpriteKit, SceneKit lets you choose which directions a body is allowed to rotate in and by how much. See the angularVelocityFactor property.
This is probably a better idea than toggling the mass between different values — that approach looks like it could be unintended behavior, so you might not want to rely on it.
If you want to mix physics simulation and manual transforms, make sure to use a "kinematicBody" and not a "dynamicBody".
Ahaha, I found some bug solving this problem (but this is a bug, so it is weird)
create node
set mass=1
add node to scene
set mass=0 - this makes it static and unmovable, but...
set mass=1 - this makes it dynamic, jumping and falling but with fixed rotation!
iOS 8.0.2 iPad mini
Simple solution:
node.physicsBody?.allowsRotation = false
I am writing an application in Qt, which uses QToolBar elements. In Linux and Windows, all looks OK. But in OS X, QToolBar have terrible gradient as its background. Please, suggest me, how I can remove it?
UPD.: I'm using Qt 5.2.
Have you tried QStyleSheets?
http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qstatusbar
http://qt-project.org/doc/qt-5/stylesheet-reference.html#background-prop
QStatusBar * bar;
bar = new QStatusBar;
bar->setStyleSheet("background: transparent;");
// bar->setStyleSheet("background: none;");
// bar->setStyleSheet("background: white;");
bar->showMessage("StatusBar");
Or if you are using it in the context of a QMainWindow, it probably would look like:
this->statusBar()->setStyleSheet( //...
Hope that helps.
The way above with QStyleSheet is correct. Another approach is to apply for example QWindowsStyle object with setStyle to QToolBar. QWindowsStyle is something that will have simple and standard look on every platform. I use it when I would like to have look&feel exactly same on all platforms despite different looks&feels on win/mac/unx.
It seems toolbar ignores styleSheets on Mac at all (at least in Qt 5.2.1). I was able to remove the gradient using the styles, for example using the Windows style. Toolbar buttons are not affected with it.
toolBar->setStyle(QStyleFactory::create("windows"));
This is a known bug also in 2020 with Qt5.12 (and probably Qt5.15). What works is setting a border (which might be zero to your stylesheet):
QToolBar {
background-color: palette(base);
border-width: 0px;
}
background-color alone does not seem to ensure that it's repainted.
I started using asp.net MVC 4 and I don't quite understand how could I accomplish simple tasks like making a simple navigation menu for my website, I would like it to be just like the one here on stackoverflow where the images change on mouse over and also link to their corresponding pages.
what used to be a few minutes of work with HTML (in Dreamweaver for example) now takes much much more time and thought (at least for me).
Investigating about the 3 elements I've mentioned got me here:
How to show an image- even that is not easy, I have looked everywhere for something that looks like an ideal solution but couldn't find any! even here on stackoverflow, some solutions are involving writing long lines of code in the name of "Helpers", and I could dig into it but there are so many different solutions, and I wouldn't know which one is right.. why can't there be just one standardized solution?
How to link an image- also an issue, that i understand that I need to set the controller in the parameters list but again I ran into and issue that I might have found the solution for I just need to test it, I have read that I could have different methods inside of one controller and in this way I will not have to have one controller for each link. I will try that, better solutions are welcomed.
How to swap an image on mouse over- also looks crazy for me, I have found one solution where there are long lines of code for this here: http://www.codeproject.com/Tips/329596/MVC-3-Helper-for-Hover-Images
I am kind of disappointed that just for putting up the logo image and linking it I spend days! I do have background in .net c# HTML+CSS etc'.. so I am asking myself (and you guys) why does it have to be so unclear and not friendly?
Come on.. what am I missing? is there any library of helpers everybody is using or something like that?
I am still in the process of learning MVC 4 and I know I'll get it but I would've expected accomplishing these kind of simple tasks a lot faster.
also, in Microsoft examples, I have never found an example where they put a logo or a menu image, it is always plain text! so annoying and frustrating...
I will very much appreciate any help..
Thanks a lot!
Roy.
Start with http://www.asp.net/mvc/mvc3 and understand what are the paradigms of it and what is the differance between webform and mvc systesm.
Basically you need to understand how the masterpages are evolved in mvc or what is the replacement of master pages in mvc.
This is clue to what you want to achieve.
Now if you want to put the Image button in which if you hover and color will change then you need to do following steps.
Create a button first e.g
Html.ActionLink("YourButtonName", "Index", null, new
{#class="hoverButton" })
Now you need to create two classes in your css file with name hoverButton which contains property to show image and hoverButton:hover show image when you hover over the link. Like following.
hoverButton {
margin-bottom: 10px;
width: 160px;
height:160px;
display:block;
background:transparent url('Button.png') center top no-repeat;
}
.hoverButton:hover {
background-image: url('hoverButton.png');
}
This way when you hover over to button it will display different image in mvc view menu item.
Hope you understand the concept and it helps.
okay so i have basic skills in html, css, javascript.
im still in the learning phases but just need a little help on where to go in regards to creating a web app.
i can figure out all the code, so thats fine, i just need some pointers as to what to use where.
So basically ill have a webpage with a few simple buttons, when clicked they'll send a message to the server and the server will hold a count for each button clicked using a php script.
1) - would it be best to hold that information in a JSON file?
then from there, there'll be another webpage which will have div tags stretching 100% across the page, with an element inside it which will move across the page according to the count held on the server.
2) - what should i use to animate it moving?. would i use javascript? or css3 or something?
the front end will need to continuously update on the count held by the server.
3) - would AJAX methods be best using javascript?
any advice would be great thanks.
And one last thing.
With Javascript animating, if i wanted to animate a div moving horizontal, is the best way to do it by animating the margin size? or am i stuck in the dark days..
1: i would store it in a database, if you store it in a file make sure that you are handling writes in a safe way(multiple writes to the same file)
2:you could use javascript to animate the css properties of a html element(preferable the width)
3: Ajax would work but then you need to continuously poll the server for changes alternativly use longpoling http://en.wikipedia.org/wiki/Push_technology#Long_polling
an alternative if you only support modern browsers and your hosting company allows it is to use websockets
If you're trying to save information server side (which you seem to be), I would recommend using a database (such as MySQL).
If your animation is dependent on the value from the server, I would use javascript to animate it. Note that you will have to poll the server in order to actually get this information (lets say, every second). When you get the information, simply update the div you want to animate with the new information. I don't quite understand what you want your display to look like, so I can't really give you anything more specific here.
Yes. I would recommend using jQuery to handle your AJAX calls as it makes it much easier and deals with cross-browser weird-ities.
To your update:
One option could definately be to adjust the (left) margin size, but you could also use the relative position. It will basically push the element however many pixels in whatever position from where it would typically be displayed. So if your box is by default right along the left border, you could relatively position it 100px to the right. You can read more about position here.