How to make wrapped, scrollable text in cocos2d-x? - cocos2d-x

I've got a ui::Text in a ui::Layout and depending on the content, it overflows. I've looked into Label::setOverflow and Label::setWrap off the ui::Text's virtualRenderer Label, but I don't see a way to make it scrollable and wrap.
How can I make a scrollable ui::Text while making sure it's wrapping text properly?

The trick is, instead of using ui::Scrollview, to use a ui::ListView with only one item inside, the ui::Text. This lets you scroll around and dynamically resize the container, for when you change the text content of the ui::Text.
The key is a) setting the width of the ui::Text to the same size as its parent ui::ListView and the height to 0 and b) calling my_listview->requestDoLayout() on the listview anytime the text content changes, so that the scrollable area reflects that.
Here's an example of how you'd implement the large body of text scrolling into a smaller ui::Panel:
ui::ListView* listview = ListView::create();
my_scene->addChild(listview);
listview->setContentSize({300, 500}); //give it whatever size
ui::Text* text = ui::Text::create("[multiline content]", "fontName.ttf", 16);
text->setTextAreaSize({300, 0}); //use that same size, but use 0 height. This auto sets overflow and wrap in the backend
listview->addChild(text);
listview->requestDoLayout(); //this triggers resizing the listview to accommodate the
//string content. Needs to happen each time you
//text->setString(new_content) too.

Related

Set Initial Height for Resizable Text Area with Large Initial Value

I have a text area element that I want to cap at an initial height of 168px that is expandable vertically but has an initial value that's large and is auto-expanding the box past that 168px initial height on page load. I want to be able to allow the user to be able to expand that box if they want to later on but initially on page load it should be set to 168px with the overflow from that initial value hidden. Have tried various combinations of min-height, resize: vertical, and overflow without success. The box is still autoexpanding as the initial value gets loaded into it on page load. Is this possible with CSS?
I guess, this code will work. Please share your code as a snippet, it would be easy to debug.
textarea{
resize:vertical;
min-height:168px;
}
<textarea></textarea>

Decrease label text size based on container width

I have a sidebar with a display name and the problem is if the user name is too long it will go beyond the container. I tried to use Jquery FitText but it doesn't seem to do what i want unless i'm doing something wrong. Function to resize is always called even if i change browser window size and the container where the name is didn't change anything. Is there a way to make the text fit the container without going beyond it?
This is actually possible with pure CSS.
Here is a great article: https://css-tricks.com/viewport-sized-typography/.
UPDATE
The issue with using pure CSS is that the text will always fit the viewport. The following custom solution only changes the text size if it overflows the containing box: jsfiddle.net/0swbytek

What is the best way to get with of an element with horizontal scrollbars using angularjs?

I have a div with fixed width. So if content goes over the available width, a horizontal scrollbar appears. Now I want to add a button which should increase the width of the div such that it does not require any horizontal scrollbar. Meaning, it should set whatever is the required width to accommodate the entire content in it.
I tried getting the width using innerWidth which returns incorrect width. Quick google search mentioned about scrollWidth, offsetWidth but there are no such methods in angular.js

Responsive HTML Elements with Specified Dimension Content

I try to create responsive HTML elements whenever the browser width is wide enough, it fills with 3 horizontal box elements whose content can be text or an image. When text content doesn't fill the whole box, it leaves some empty space so that it doesn't wrapped around the box.
However the text content can fill the box. Whether the box is filled or not, it should have same dimension unless the browser dimension changes.
When browser dimension is widening, the 3 elements should stay with the original dimension. But when it is narrowing, the 3 horizontal elements can reduce to 2 horizontal elements, leaving the other element to new space. And it can be 1 horizontal element if the browser space is narrow enough.
There can be many 3 horizontal elements, like this:
X X X
X X X
X X X
They're stacked like a table.
When the content is an image, its size must comply to the box dimension not the other way around, so it shrinks when the original image is bigger than the box or stretch when the image is smaller.
so far this is what I have
my JSFiddle link
The code above have a responsive horizontal box. Also the picture doesn't comply to the box but vice versa.
Please advice.
Responsive design won't be obtained by using Width and height elements.
Try setting these to Min-height / Max-height etc..
Also if you really want to keep it responsive then you should just install the bootstrap framework and use
col-md-4 to achieve this much easier without having to worry about css styling etc..

How to get the HTML text to just stay in one place

I am making a site in HTML, and I am putting a heading on top of an object. When I shrink the window enough, the object and the text interfere
Is there any way I can have the text just stay in one spot without it wrapping to the browser window if there is no space left in the browser?
I have tried using fixed as a position property in CSS, but the same thing happened.
If you set an explicit width on the containing object (perhaps a <div> tag) it will not resize with the window. When the window becomes too small, it will not wrap around like you mentioned but force a scroll bar to appear.
I'm not sure what you mean by ending lines. If you're talking about wrapping, have you considered a fixed size DIV with overflow:hidden as a CSS rule?