Comments (2)
put into GuiLite source would look a bit different, but this is a starting point if it helps. inserting \n was a nonstarter
void draw_string_in_wrapped_rect(c_surface* surface, int z_order, std::string instr, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)
{
int w = 0, h = 0;
c_word::get_str_size( instr.c_str(), font, w, h );
const int width = rect.width();
const int height = rect.height();
if( w <= width )
{
c_word::draw_string_in_rect( surface, z_order, instr.c_str(), rect, font, font_color, bg_color, align_type );
return;
}
int x = 0, y = 0, rowy = 0;
int est_chars_per_line = ( (float)width / w * instr.size() );
int nrows = std::max( 1, std::min( 1 + ( w - 1 ) / width, ( height + h ) / h ) );
for( int row = 0, pos = 0; row < nrows; row++, pos += est_chars_per_line, rowy += h )
{
std::string linestr = instr.substr( pos, est_chars_per_line );
const char *line = linestr.c_str();
c_word::fontOperator->get_string_pos( (const void *)line, (const LATTICE_FONT_INFO *)font, rect, align_type, x, y );
c_word::draw_string(
surface, z_order, (const void *)line, rect.m_left + x, rect.m_top + rowy + y, font, font_color, bg_color );
}
}
from guilite.
also worth looking at existing code
while (*s)
{
s += get_utf8_code(s, utf8_code);
offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color);
}
if char == \n you could increase a y offset and reset x
from guilite.
Related Issues (20)
- GuiLite examples capturing users name and sending to external site HOT 6
- Documentation? HOT 14
- . HOT 8
- 需要一个异形窗体的例子. HOT 2
- Why not pure C HOT 1
- can you support the customized key board HOT 2
- can i use it in mingw HOT 1
- is GuiLite used GPU ? GuiLite可以使用GPU渲染吗? HOT 1
- 只支持16位色和32位色吗? HOT 1
- vcpkg port? - I've started HOT 1
- use custom title bar in window HOT 1
- Linux/arm64/v8
- Need source for the xWindow to build for Linux on other processors HOT 1
- dumb question here what does the others toolkit library have in addition to headers file
- 有没有最简单的案例,就是显示一个中文 HOT 1
- Typo in GuiLite.h KEYBORAD_CLICK
- Keyboard input?
- The UI is flashing while I resize the app
- DRM
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 guilite.