Skip to content

Commit 46a4fb7

Browse files
authored
Merge pull request #5 from rerdavies/dev
Dev - merge 0.0.3-beta3
2 parents f1e5557 + b822520 commit 46a4fb7

9 files changed

+63
-28
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cmake_minimum_required(VERSION 3.16.0)
22
project(nwindows
3-
VERSION 0.0.2
3+
VERSION 0.0.3
44
DESCRIPTION "Modern Text User Interface Library for C++."
55
HOMEPAGE_URL "https://rerdavies.github.io/nwindows/"
66
LANGUAGES CXX
77
)
8-
set(NWINDOWS_RELEASE_QUALIFIER "-beta2")
8+
set(NWINDOWS_RELEASE_QUALIFIER "-beta3")
99

1010

1111

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Documentation](https://img.shields.io/badge/documentation-Examples-blue)](https://github.com/rerdavies/nwindows/tree/main/examples)
66
<!--[![Documentation](https://img.shields.io/badge/documentation-Release%20Notes-blue)](https://reravies.github.io/nwindows/) -->
77

8-
*0.0.2-beta2*
8+
*0.0.3-beta3*
99

1010
The *NWindows* library is a C++ text user interface (TUI) library for building console applications on Linux.
1111
The library uses elements to compose user interfaces using an innovative and concise manipulator system. The library provides a rich set of elements with which to build user interfaces.

ReleaseNotes.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release Notes
22

3+
### NWindows 0.0.3-beta3
4+
5+
- Cache can_display_character() results for faster rendering.
6+
7+
38
### NWindows 0.0.2-beta2
49

510
- Polyfill checkbox/radio-button/dropdown characters on EGA/VGA (Linux) terminals.

docs/src/NWindowsVersionInfo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
* SOFTWARE.
2222
*/
2323

24-
export const NWindowsVersion = "0.0.2-beta2";
24+
export const NWindowsVersion = "0.0.3-beta3";

docs/src/assets/ReleaseNotes.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release Notes
22

3+
### NWindows 0.0.3-beta3
4+
5+
- Cache can_display_character() results for faster rendering.
6+
7+
38
### NWindows 0.0.2-beta2
49

510
- Polyfill checkbox/radio-button/dropdown characters on EGA/VGA (Linux) terminals.

src/ConsoleFontTest.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,24 @@ void dump_unicode_ioctl()
109109
Finally closeConsoleFd([console_fd]() { close(console_fd); });
110110

111111

112-
std::vector<uint8_t> fontdata;
113-
fontdata.resize(512 * 32);
112+
std::vector<uint8_t> font_data;
113+
font_data.resize(512 * 32);
114114

115-
struct consolefontdesc fontdesc;
116-
fontdesc.charcount = 512;
117-
fontdesc.chardata = (char*)fontdata.data();
118-
fontdesc.charheight = 32;
115+
struct consolefontdesc font_desc;
116+
font_desc.charcount = 512;
117+
font_desc.chardata = (char*)font_data.data();
118+
font_desc.charheight = 32;
119119

120120
errno = 0;
121-
int rc = ioctl(console_fd, GIO_FONTX, &fontdesc);
121+
int rc = ioctl(console_fd, GIO_FONTX, &font_desc);
122122

123123
if (rc != 0)
124124
{
125125
std::string msg = strerror(errno);
126126
std::cout << "FontX not supported. " << msg << std::endl;
127127
}
128128
else {
129-
std::cout << "Fontx supported: " << fontdesc.charcount << " characters, height: " << fontdesc.charheight << std::endl;
129+
std::cout << "Fontx supported: " << font_desc.charcount << " characters, height: " << font_desc.charheight << std::endl;
130130
}
131131

132132

src/NWindows.cpp

+33-14
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ void NWindow::add_child_window(NWindow::ptr child)
11761176
{
11771177
this->child_windows_.push_back(child);
11781178
child->parent_window_ = this;
1179+
child->top_level_window_ = this->top_level_window_;
11791180
child->is_unicode_locale_ = this->is_unicode_locale_;
11801181
child->color_palette(this->color_palette_);
11811182

@@ -1192,6 +1193,7 @@ bool NWindow::remove_child_window(NWindow* child)
11921193
if (i->get() == child)
11931194
{
11941195
child->parent_window_ = nullptr;
1196+
child->top_level_window_ = nullptr;
11951197
child_windows_.erase(i);
11961198
return true;
11971199
}
@@ -1201,21 +1203,11 @@ bool NWindow::remove_child_window(NWindow* child)
12011203

12021204
NWindow* NWindow::top_level_window()
12031205
{
1204-
NWindow* window = this;
1205-
while (window->parent_window_ != nullptr)
1206-
{
1207-
window = window->parent_window_;
1208-
}
1209-
return window;
1206+
return this->top_level_window_;
12101207
}
12111208
const NWindow* NWindow::top_level_window() const
12121209
{
1213-
const NWindow* window = this;
1214-
while (window->parent_window_ != nullptr)
1215-
{
1216-
window = window->parent_window_;
1217-
}
1218-
return window;
1210+
return this->top_level_window_;
12191211
}
12201212

12211213

@@ -1286,6 +1278,8 @@ void NWindow::init_root_window()
12861278
{
12871279
throw std::runtime_error("A root window already exists. Create a child window instead, by supplying a parent window argument to NWindow::create.");
12881280
}
1281+
this->top_level_window_ = this;
1282+
12891283
std::string old_locale = ::setlocale(LC_ALL, "");
12901284
std::string locale = ::setlocale(LC_ALL, nullptr);
12911285

@@ -4573,7 +4567,7 @@ static bool use_raspberry_pi_fallback() {
45734567
{
45744568
g_checked_raspberry_pi = true;
45754569

4576-
// Are we running in raspi lxterminal?
4570+
// Are we running in Raspberry Pi lxterminal?
45774571
// GIO_LAUNCHED_DESKTOP_FILE=/usr/share/raspi-ui-overrides/applications/lxterminal.desktop
45784572
const char* term = std::getenv("GIO_LAUNCHED_DESKTOP_FILE");
45794573
g_use_raspberry_pi_fallback = false;
@@ -6313,8 +6307,33 @@ void NWindow::handle_is_active_changed(bool activated)
63136307
}
63146308

63156309

6316-
63176310
bool NWindow::can_display_character(char32_t c) const
6311+
{
6312+
if (this->top_level_window() != this)
6313+
{
6314+
return this->top_level_window()->can_display_character(c);
6315+
}
6316+
// Simple cache implementation, assuming that the underlying call
6317+
// requires a round-trip wire transit,
6318+
6319+
auto ff = can_display_character_cache_.find(c);
6320+
if (ff != can_display_character_cache_.end())
6321+
{
6322+
return ff->second;
6323+
}
6324+
bool result = can_display_character_(c);
6325+
6326+
// moral constness.
6327+
const_cast<NWindow*>(this)->can_display_character_cache_[c] = result;
6328+
6329+
return result;
6330+
}
6331+
// std::unordered_map<char32_t,bool> NWindow::can_display_character_cache_;
6332+
6333+
6334+
6335+
6336+
bool NWindow::can_display_character_(char32_t c) const
63186337
{
63196338
// Figure out whether wcwidth() works on Windows for emoji (and other extended unicode characters)
63206339
// or figure out an alternative.

src/include/NWindows/NWindows.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "NEvent.hpp"
4040
#include "NClipboard.hpp"
4141
#include "NUtf8.hpp"
42+
#include <unordered_map>
4243

4344
#include "NWindowsVersionInfo.hpp"
4445

@@ -1426,6 +1427,7 @@ namespace nwindows
14261427
static void set_locale(const std::string& locale);
14271428
bool can_display_character(char32_t c) const;
14281429

1430+
14291431
std::shared_ptr<ConsoleFont> console_font() const { return this->top_level_window()->console_font_; }
14301432

14311433

@@ -1615,6 +1617,9 @@ namespace nwindows
16151617
virtual void render() override;
16161618

16171619
private:
1620+
bool can_display_character_(char32_t c) const;
1621+
std::unordered_map<char32_t,bool> can_display_character_cache_;
1622+
16181623

16191624
bool is_unicode_locale() const { return is_unicode_locale_; }
16201625

@@ -1745,6 +1750,7 @@ namespace nwindows
17451750
std::vector<PANEL*> panel_stack_; // root level window only.
17461751

17471752
NWindow* parent_window_ = nullptr;
1753+
NWindow* top_level_window_ = nullptr;
17481754
std::vector<NWindow::ptr> child_windows_; // for ownership.
17491755

17501756
std::string title_;

src/include/NWindows/NWindowsVersionInfo.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
// Uses Semantic Versioning
2929
#define NWINDOWS_MAJOR_VERSION 0
3030
#define NWINDOWS_MINOR_VERSION 0
31-
#define NWINDOWS_BUILD_NUMBER 2 // increments with each release
32-
#define NWINDOWS_RELEASE_QUALIFIER "-beta2"
31+
#define NWINDOWS_BUILD_NUMBER 3 // increments with each release
32+
#define NWINDOWS_RELEASE_QUALIFIER "-beta3"
3333

3434

3535

0 commit comments

Comments
 (0)