Skip to content

Commit

Permalink
Upgrade FTXUI version + fix black line.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni committed Jun 2, 2024
1 parent 004d58c commit 7e17783
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required (VERSION 3.11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# --- Fetch FTXUI --------------------------------------------------------------
include(FetchContent)
Expand All @@ -7,7 +8,7 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)

FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG b56afce48ccd472cd2c3a53e619de0db1e7227a4
GIT_TAG 7b1f4d435bedecc49abc3f935bd97dc997a41977
)

FetchContent_Declare(fmt
Expand Down
44 changes: 15 additions & 29 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include <fmt/core.h>
#include <cstddef>
#include <iostream>
#include "ftxui/component/component.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"
#include "ftxui/screen/string.hpp"

using namespace ftxui;
Expand Down Expand Up @@ -39,12 +36,7 @@ Element HexaElement(int r, int g, int b) {
return text(HexColor(r, g, b));
}

void ToRGB(int h,
int s,
int v,
int& r,
int& g,
int& b) {
void ToRGB(int h, int s, int v, int& r, int& g, int& b) {
if (s == 0) {
r = v;
g = v;
Expand Down Expand Up @@ -118,7 +110,7 @@ class MainComponent : public ComponentBase {
int hue = h_;
Elements array;
int x_length = std::max(10, box_color_.x_max - box_color_.x_min) + 1;
int y_length = 15;
int y_length = 16;

int h, s, v;
ToHSV(r_, g_, b_, h, s, v);
Expand All @@ -127,21 +119,21 @@ class MainComponent : public ComponentBase {
std::max(0, std::min(2 * y_length - 1, (s * 2 * y_length) / 255));

for (int y = 0; y < y_length; ++y) {
int saturation_1 = 255 * (y + 0.0f) / float(y_length);
int saturation_2 = 255 * (y + 0.5f) / float(y_length);
Elements line;
for (int x = 0; x < x_length; ++x) {
int saturation_1 = 255 * (y + 0.0f) / float(y_length);
int saturation_2 = 255 * (y + 0.5f) / float(y_length);
int value = 255 * x / float(x_length);
if (x == target_x) {
if (2 * y == target_y) {
if (2 * y == target_y - 1) {
line.push_back(text(L"") //
| color(Color::HSV(hue, saturation_1, value)) //
| bgcolor(Color::Black)); //
continue;
}
if (2 * y == target_y + 1) {
line.push_back(text(L"") //
| color(Color::Black)//
if (2 * y == target_y) {
line.push_back(text(L"") //
| color(Color::Black) //
| bgcolor(Color::HSV(hue, saturation_2, value)));
continue;
}
Expand All @@ -152,11 +144,6 @@ class MainComponent : public ComponentBase {
}
array.push_back(hbox(std::move(line)));
}
for (int saturation = 0; saturation < 255; saturation += 20) {
Elements line;
// for (int hue = 0; hue < 255; hue += 2) {
array.push_back(hbox(std::move(line)));
}

return vbox({
window(
Expand Down Expand Up @@ -190,7 +177,6 @@ class MainComponent : public ComponentBase {
};

bool OnEvent(Event event) final {

int r = r_;
int g = g_;
int b = b_;
Expand Down Expand Up @@ -257,13 +243,13 @@ class MainComponent : public ComponentBase {
Component color_green_ = Slider(L"Green: ", &g_, 0, 255, 1);
Component color_blue_ = Slider(L"Blue: ", &b_, 0, 255, 1);
Component container_ = Container::Vertical({
color_hue_,
color_saturation_,
color_value_,
color_red_,
color_green_,
color_blue_,
});
color_hue_,
color_saturation_,
color_value_,
color_red_,
color_green_,
color_blue_,
});

Box box_color_;
CapturedMouse captured_mouse_;
Expand Down

0 comments on commit 7e17783

Please sign in to comment.