c++ - 使用 fltk 时文本未出现在编译窗口中
问题描述
我正在阅读“C++ 编程原理和实践”一书。我正在学习如何使用 fltk(第 12 章),并且我已经成功地安装了库并编译了程序。我可以绘制基本形状并为其着色,更改用于绘制它们的线条纹理,但是,问题是我无法让文本出现在最终编译的窗口上。负责将文本输出到屏幕的“文本”函数不执行任何操作。屏幕没有文字。几何图形出现在窗口中,问题是文本独有的。当我尝试向我的图表添加标签时也是如此。“标签”文本没有出现。其他一切都很完美,我尝试编译基本的 fltk hello,world 程序。当我编译它们时,文本出现在屏幕上。
这是代码
#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;
int main(){
Point tl {100,100};
Simple_window win {tl,600,400,"Canvas"};
Axis xa {Axis::x, Point{20,300},280,10,"x axis"};
win.attach(xa);
win.set_label("Canvas#2");
Axis ya{Axis::y, Point{20,300},280,10,"y axis"};
ya.set_color(Color::cyan);
ya.label.set_color(Color::dark_red);
win.attach(ya);
win.set_label("Canvas #3");
Function sine{sin,0,100,Point{20,150},1000,50,50};
win.attach(sine);
win.set_label("Canvas#4");
sine.set_color(Color::blue);
Polygon poly;
poly.add(Point{300,200});
poly.add(Point{350,100});
poly.add(Point{400,200});
poly.set_color(Color::red);
poly.set_style(Line_style::dash);
win.attach(poly);
Rectangle r{Point{200,200},100,50};
win.attach(r);
win.set_label("Canvas 6");
Closed_polyline poly_rect;
poly_rect.add(Point{100,50});
poly_rect.add(Point{200,50});
poly_rect.add(Point{200,100});
poly_rect.add(Point{100,100});
win.attach(poly_rect);
poly_rect.add(Point{50,75});
r.set_fill_color(Color::yellow);
poly.set_style(Line_style(Line_style::dash,4));
poly_rect.set_style(Line_style(Line_style::dash,2));
poly_rect.set_fill_color(Color::green);
win.set_label("Canvas 7");
Text t{Point{150,150},"testing..."};
win.attach(t);
win.set_label("Canvas 8");
win.wait_for_button();
}
Simple_window 和 Graph 文件是本书附带的文件。这些文件利用 fl_draw 在屏幕上“绘制”文本,我假设这个函数不起作用。我正在使用 ubuntu 并使用 g++ 编译器。
这是我目前的输出
解决方案
啊,问题解决了。事实证明,文本的默认字体大小太小而肉眼无法看到。我不得不通过使用函数“set_font_size”来增加文本的字体大小,然后文本再次变得可见。
推荐阅读
- firebase - iOS 在 Firebase 中有可信提供者的概念吗?
- php - fetchAll() 正在打印数据两次
- css - 如何使用列表样式类型的十进制但没有点
- google-maps - kmz更改后刷新谷歌地图
- node.js - Openshift - 来自构建 pod 的错误流日志
- php - 会话管理器不在本地主机上工作
- java - Appium - 移动自动化测试 - Android - 选项卡栏的选定选项卡的选定属性始终为 false
- javascript - Bootstrap 水平导航加手风琴
- firebase - 用于 signInWithPhoneNumber 的 Firebase AUTH API 导致 400 错误请求
- google-search-console - 网站链接未在 Google 上编入索引