cgv
Loading...
Searching...
No Matches
text_editor.h
1#pragma once
2
3#include <cgv/base/named.h>
4#include <cgv/data/ref_ptr.h>
5#include <cgv/media/font/font.h>
6
7#include "lib_begin.h"
8
9namespace cgv {
10 namespace gui {
11
14{
16 virtual void on_close_editor();
18 virtual void after_read();
20 virtual void after_save();
22 virtual void on_text_insertion(int text_pos, int nr_inserted);
24 virtual void on_text_deletion(int text_pos, int nr_deleted, const char* deleted_text);
26 virtual void on_update_callback();
27};
28
39
41class CGV_API text_editor : public base::named
42{
43protected:
46public:
48 text_editor(const std::string& name, text_editor_callback_handler* _handler = 0);
50 void set_callback_handler(text_editor_callback_handler* _handler);
52 const text_editor_callback_handler* get_callback_handler() const;
54 virtual ~text_editor();
56 virtual void set_base_path(const std::string& path) = 0;
58 virtual void set_filter(const std::string& filter) = 0;
60 virtual bool read(const std::string& file_name) = 0;
62 virtual bool is_modified() const = 0;
64 virtual bool save() = 0;
66 virtual void show() = 0;
68 virtual void hide() = 0;
70 virtual bool is_visible() const = 0;
72 virtual const char* get_text() const = 0;
74 virtual void set_text(const std::string& new_text) = 0;
76 virtual const char* get_style() const = 0;
78 virtual void set_style(int text_pos, int length, const char* style) = 0;
80 virtual unsigned int get_length() const = 0;
82 virtual void set_text_styles(const text_style* table, int nr_styles) = 0;
83};
84
87
88#if _MSC_VER >= 1400
89CGV_TEMPLATE template class CGV_API data::ref_ptr<text_editor_ptr>;
90#endif
91
93extern CGV_API text_editor_ptr create_text_editor(unsigned int w, unsigned int h, const std::string& title, int x=-1, int y=-1);
94
95 }
96}
97
98#include <cgv/config/lib_end.h>
base class for all gui types
Definition named.h:20
abstract base class for text editors
Definition text_editor.h:42
virtual const char * get_style() const =0
return pointer to style buffer
virtual void set_text(const std::string &new_text)=0
replace the complete text
virtual void set_base_path(const std::string &path)=0
set a different base path used for the file open and save dialog
virtual unsigned int get_length() const =0
return length of text and style buffer
virtual const char * get_text() const =0
return pointer to text buffer
virtual bool save()=0
save the current file
virtual void hide()=0
hide editor
virtual bool is_visible() const =0
return whether editor is visible
virtual void set_filter(const std::string &filter)=0
set a file filter for the file open and save dialog, default is "*"
virtual bool is_modified() const =0
check if the current file is modified
text_editor_callback_handler * handler
store a callback handler
Definition text_editor.h:45
virtual void set_text_styles(const text_style *table, int nr_styles)=0
set text styles from a table, where the first style is labeled with the character A,...
virtual void set_style(int text_pos, int length, const char *style)=0
set the style of a given text portion
virtual bool read(const std::string &file_name)=0
read a new text file
virtual void show()=0
show editor
data::ref_ptr< text_editor > text_editor_ptr
ref counted pointer to abst control
Definition text_editor.h:86
text_editor_ptr create_text_editor(unsigned int w, unsigned int h, const std::string &title, int x, int y)
construct a new text editor in a separate window of given size, title and position
the cgv namespace
Definition print.h:11
implement this interface to interact with the text editor
Definition text_editor.h:14
description of a text style
Definition text_editor.h:31
float font_size
font size in pixels
Definition text_editor.h:37
int color
rgb color packed into one integer, i.e. 0xff00ff corresponds to magenta
Definition text_editor.h:33
cgv::media::font::font_face_ptr font_face
font face string with font name first, followed by +bold and or +italic
Definition text_editor.h:35