auto

强大的display:grid

旧时模样 提交于 2019-11-29 16:04:27
自从用习惯flex布局我基本已经不怎么使用float了。 现在又出现了grid布局,就像flex的升级版,布局上十分强大。 主要属性: grid-template-columns://竖向排列 grid-template-rows://横向排列 首先比较一下flex和grid实现自适应九宫格,高度800px,宽度适应: flex 超过一层后样式就复杂了,特别是边框的处理有点复杂。(方法很多,不一一去展示了)。 <html> <head> <style type="text/css"> .box { padding: 10px; padding-bottom: 0; padding-right: 0; display: flex; flex-direction: column; height: 800px; width: calc(100vw - 20px); background-color: #000; } .content { display: flex; margin-bottom: 10px; flex: 1 } .b { flex: 1; margin-right: 10px; background-color: yellow; } </style> </head> <body> <div class="box"> <div class="content"> <div

CSS margin 属性

北战南征 提交于 2019-11-29 15:28:51
设置外边距的最简单的方法就是使用 margin 属性。 margin 属性接受任何长度单位,可以是像素、英寸、毫米或 em。 margin 可以设置为 auto。更常见的做法是为外边距设置长度值。下面的声明在 h1 元素的各个边上设置了 1/4 英寸宽的空白: h1 {margin : 0.25in;} 下面的例子为 h1 元素的四个边分别定义了不同的外边距,所使用的长度单位是像素 (px): h1 {margin : 10px 0px 15px 5px;} 与内边距的设置相同,这些值的顺序是从上外边距 (top) 开始围着元素顺时针旋转的: margin: top right bottom left 另外,还可以为 margin 设置一个百分比数值: p {margin : 10%;} 百分数是相对于父元素的 width 计算的。上面这个例子为 p 元素设置的外边距是其父元素的 width 的 10%。 margin 的默认值是 0,所以如果没有为 margin 声明一个值,就不会出现外边距。但是,在实际中,浏览器对许多元素已经提供了预定的样式,外边距也不例外。例如,在支持 CSS 的浏览器中,外边距会在每个段落元素的上面和下面生成“空行”。因此,如果没有为 p 元素声明外边距,浏览器可能会自己应用一个外边距。当然,只要你特别作了声明,就会覆盖默认样式。 值复制 还记得吗

[Cocos2d塔防游戏开发]Cocos2dx-3.X完成塔防游戏《王国保卫战》--游戏开始界面

纵饮孤独 提交于 2019-11-29 10:54:16
修改AppDelegate中内容,将setDesignResolutionSize中改为 <span style="font-size:14px;">(960, 640, ResolutionPolicy::FIXED_HEIGHT)</span> 保持传入的设计分辨率高度不变,根据屏幕分辨率修正设计分辨率的宽度 通过: auto scene = WelcomeScene::createScene(); director->runWithScene(scene); 来启动新的场景,进入开始游戏界面 首先是Kingdom Rush的LOGO以及该LOGO的动画 加载资源文件xx.plist SpriteFrameCache::getInstance()->addSpriteFramesWithFile("mainmenu_spritesheet_32_1-hd.plist"); 添加背景图片 //从SpriteFrameCache中加载图片 auto sprite_background = Sprite::createWithSpriteFrameName("mainmenu_bg.png"); //设置位置 sprite_background->setPosition(Point(visibleSize.width/2,visibleSize.height/2)); //添加背景

Observing weird behavior with 'auto' and std::minmax

喜欢而已 提交于 2019-11-29 09:48:46
I am using GCC 4.7.2 and Boost 1.58.0 on SUSE Enterprise Linux 11. I have the following code snippet which basically goes through a list of polygons to compute their length/width. I'm seeing strange output when using the 'auto' keyword with the std::minmax function. To compare, I also declare a second variable where the types are explicitly declared (i.e., dim vs dim1). namespace gtl = boost::polygon; typedef gtl::polygon_90_data<int> LayoutPolygon; typedef gtl::rectangle_data<int> LayoutRectangle; static LayoutFeatureVec calc_stats(LayoutPolygonSet const& lp) { LayoutFeatureVec v;

Is it well-formed, if I redefine a variable as auto, and the deduced type is the same? [duplicate]

徘徊边缘 提交于 2019-11-29 09:29:15
This question already has an answer here: Does a declaration using “auto” match an extern declaration that uses a concrete type specifier? 3 answers Look at this snippet: int a; extern int b; auto b = a; Is it well-formed? Clang successfully compiles it, but GCC and MSVC don't. (This issue has come up when I answered How to declare and define a static member with deduced type? ) Tl;DR; clang is correct, the logic is that this is allowed by [dcl.spec.auto] and to restrict this for deduced return types [dcl.spec.auto]p11 was added otherwise there is no restriction and therefore this is not

unexpected copies with foreach over a map

五迷三道 提交于 2019-11-29 09:14:22
I am trying to loop over the entries of a map, and I get unexpected copies. Here is the program: #include <iostream> #include <map> #include <string> struct X { X() { std::cout << "default constructor\n"; } X(const X&) { std::cout << "copy constructor\n"; } }; int main() { std::map<int, X> numbers = {{1, X()}, {2, X()}, {3, X()}}; std::cout << "STARTING LOOP\n"; for (const std::pair<int, X>& p : numbers) { } std::cout << "ENDING LOOP\n"; } And here is the output: default constructor copy constructor default constructor copy constructor default constructor copy constructor copy constructor copy

'auto' not allowed in function prototype with Clang

五迷三道 提交于 2019-11-29 09:14:06
Using Clang 3.5, 3.6, or 3.7, with the flag std=c++1y the following code does not compile : #include <iostream> auto foo(auto bar) { return bar; } int main() { std::cout << foo(5.0f) << std::endl; } The error given is : error: 'auto' not allowed in function prototype I do not have errors using g++ 4.9. Is this error produced because Clang has not yet implemented this functionnality yet or is it because I am not allowed to do that and GCC somehow permits it ? As we see from the ISO C++ discussion mailing: decltype(auto) parameters vs. perfect forwarding auto parameters of non-lambdas is part of

auto from const std::vector<>&; object or reference?

烂漫一生 提交于 2019-11-29 09:07:54
suppose we have an object with the following interface: struct Node_t { ... const std::vector< something >& getChilds() const; } node; Now, i access the property with an auto variable like this: auto childs = node->getChilds(); what is the type of childs ? a std::vector< something > or a reference to one? The type of childs will be std::vector<something> . auto is powered by the same rules as template type deduction . The type picked here is the same that would get picked for template <typename T> f(T t); in a call like f(node->getChilds()) . Similarly, auto& would get you the same type that

How do I declare a function whose return type is deduced?

一笑奈何 提交于 2019-11-29 06:02:20
Consider this C++1y code ( LIVE EXAMPLE ): #include <iostream> auto foo(); int main() { std::cout << foo(); // ERROR! } auto foo() { return 1234; } The compiler (GCC 4.8.1) generously shoots out this error: main.cpp: In function ‘int main()’: main.cpp:8:18: error: use of ‘auto foo()’ before deduction of ‘auto’ std::cout << foo(); ^ How do I forward-declare foo() here? Or maybe more appropriately, is it possible to forward-declare foo() ? I've also tried compiling code where I tried to declare foo() in the .h file, defined foo() just like the one above in a .cpp file, included the .h in my main

Forcing auto to be a reference type in a range for loop

微笑、不失礼 提交于 2019-11-29 05:30:14
Suppose I have foo which is a populated std::vector<double> . I need to operate on the elements of this vector. I'm motivated to write for (auto it : foo){ /*ToDo - Operate on 'it'*/ } But it appears that this will not write back to foo since it is a value type: a deep copy of the vector element has been taken. Can I give some guidance to auto to make it a reference type? Then I could operate directly on it . I suspect I'm missing some trivial syntax. A minimal auto reference The loop can be declared as follows: for (auto& it : foo) { // ^ the additional & is needed /*ToDo - Operate on 'it'*/