Text source satisfying

Improved layout options, better UI, tested features.
This commit is contained in:
Bruno Herbelin
2023-11-13 12:41:37 +01:00
parent d39064b209
commit 58371c36d3
12 changed files with 368 additions and 70 deletions

View File

@@ -1858,9 +1858,9 @@ void ImGuiVisitor::visit(TextSource &s)
// Prepare display text
static int numlines = 0;
const ImGuiContext &g = *GImGui;
ImVec2 fieldsize(w, MAX(3, numlines) * g.FontSize + g.Style.ItemSpacing.y + g.Style.FramePadding.y);
ImVec2 fieldsize(w, MAX(4, numlines) * g.FontSize + g.Style.ItemSpacing.y + g.Style.FramePadding.y);
// Editor
// Text contents
std::string _contents = tc->text();
// if the content is a subtitle file
if (tc->isSubtitle()) {
@@ -1876,12 +1876,12 @@ void ImGuiVisitor::visit(TextSource &s)
if (ImGuiToolkit::IconButton(3, 5, "Open"))
SystemToolkit::open(_contents.c_str());
}
// general case of free text
// general case of free text : text editor
else {
if (ImGuiToolkit::InputTextMultiline("Text", &_contents, fieldsize, &numlines)) {
info.reset();
tc->setText(_contents);
Action::manager().store(s.name() + ": Change text");
Action::manager().store(s.name() + " Change text");
}
botom = ImGui::GetCursorPos();
@@ -1890,37 +1890,173 @@ void ImGuiVisitor::visit(TextSource &s)
if (ImGuiToolkit::IconButton(ICON_FA_COPY, "Copy"))
ImGui::SetClipboardText(_contents.c_str());
ImGui::SetCursorPos(
ImVec2(top.x + 0.9 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight()));
ImVec2(top.x + 0.95 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight()));
if (ImGuiToolkit::IconButton(ICON_FA_PASTE, "Paste")) {
_contents = std::string(ImGui::GetClipboardText());
info.reset();
tc->setText(_contents);
Action::manager().store(s.name() + ": Change text");
Action::manager().store(s.name() + " Change text");
}
ImGui::SetCursorPos(ImVec2(top.x, botom.y - 2.f * ImGui::GetFrameHeight()));
if (ImGuiToolkit::IconButton(ICON_FA_CODE, "Pango syntax"))
SystemToolkit::open("https://docs.gtk.org/Pango/pango_markup.html");
}
// Properties
// Text Properties
ImGui::SetCursorPos(botom);
ImVec4 color = ImGuiToolkit::ColorConvertARGBToFloat4(tc->color());
if (ImGui::ColorEdit4("Text Color", (float *) &color, ImGuiColorEditFlags_AlphaPreview |
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel) ) {
tc->setColor( ImGuiToolkit::ColorConvertFloat4ToARGB(color) );
}
if (ImGui::IsItemDeactivatedAfterEdit())
Action::manager().store( s.name() + " Change font color" );
std::string font = tc->fontDescriptor();
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGuiToolkit::InputText("Font", &font);
ImGuiToolkit::InputText("##Font", &font, ImGuiInputTextFlags_EnterReturnsTrue);
if (ImGui::IsItemDeactivatedAfterEdit()) {
tc->setFontDescriptor(font);
Action::manager().store( s.name() + " Change font");
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
if (ImGuiToolkit::TextButton("Font")) {
tc->setFontDescriptor("arial 24");
tc->setColor(0xffffffff);
Action::manager().store(s.name() + " Reset font");
}
botom = ImGui::GetCursorPos();
ImGui::SameLine(0, IMGUI_SAME_LINE);
if (ImGuiToolkit::IconButton(1, 13, "Pango font description"))
SystemToolkit::open("https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html");
ImGui::SetCursorPos(botom);
int align = tc->halignment();
color = ImGuiToolkit::ColorConvertARGBToFloat4(tc->outlineColor());
if (ImGui::ColorEdit4("Text Outline Color", (float *) &color, ImGuiColorEditFlags_AlphaPreview |
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel) ) {
tc->setOutlineColor( ImGuiToolkit::ColorConvertFloat4ToARGB(color) );
}
if (ImGui::IsItemDeactivatedAfterEdit())
Action::manager().store( s.name() + " Change outline color" );
ImGui::SameLine(0, IMGUI_SAME_LINE);
int outline = tc->outline();
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
if (ImGui::Combo("Horizontal", &align, "Left\0Center\0Right\0Absolute\0")) {
tc->setHalignment(align);
Action::manager().store( s.name() + " Horizontal align");
if (ImGui::Combo("##Outline", &outline, "None\0Border\0Border & shadow\0")) {
tc->setOutline(outline);
Action::manager().store(s.name() + " Change outline");
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
if (ImGuiToolkit::TextButton("Outline")) {
tc->setOutline(2);
tc->setOutlineColor(0xFF000000);
Action::manager().store(s.name() + " Reset outline");
}
align = tc->valignment();
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
if (ImGui::Combo("Vertical", &align, "Baseline\0Bottom\0top\0Absolute\0Center\0")) {
tc->setValignment(align);
Action::manager().store( s.name() + " Vertical align");
// HORIZONTAL alignment
bool on = true;
uint var = tc->horizontalAlignment();
on = var == 0;
float _x = ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN;
_x -= 4.f * (g.FontSize + g.Style.FramePadding.x + IMGUI_SAME_LINE);
if (var != 1) {
// not centered
ImGui::SetNextItemWidth(_x);
if (var > 2) {
// Absolute position
float align_x = tc->horizontalPadding();
if (ImGui::SliderFloat("##Posx", &align_x, 0.f, 1.f, "%.2f")) {
tc->setHorizontalPadding(align_x);
}
if (ImGui::IsItemHovered())
ImGuiToolkit::ToolTip( "Coordinates" );
} else {
// padding top or bottom
int pad_x = (int) tc->horizontalPadding();
if (ImGui::SliderInt("##Padx", &pad_x, 0, 1000)) {
tc->setHorizontalPadding((float) pad_x);
}
if (ImGui::IsItemHovered())
ImGuiToolkit::ToolTip( "Padding" );
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
} else {
_x += IMGUI_SAME_LINE + g.Style.FramePadding.x;
ImGui::SetCursorPosX(_x);
}
if (ImGuiToolkit::ButtonIconToggle(17, 16, &on, "Left"))
tc->setHorizontalAlignment(0);
ImGui::SameLine(0, IMGUI_SAME_LINE);
on = var == 1;
if (ImGuiToolkit::ButtonIconToggle(18, 16, &on, "Center"))
tc->setHorizontalAlignment(1);
ImGui::SameLine(0, IMGUI_SAME_LINE);
on = var == 2;
if (ImGuiToolkit::ButtonIconToggle(19, 16, &on, "Right"))
tc->setHorizontalAlignment(2);
ImGui::SameLine(0, IMGUI_SAME_LINE);
on = var == 3;
if (ImGuiToolkit::ButtonIconToggle(6, 10, &on, "Absolute"))
tc->setHorizontalAlignment(3);
if (var != tc->horizontalAlignment())
Action::manager().store(s.name() + " Change h-align");
ImGui::SameLine(0, IMGUI_SAME_LINE);
if (ImGuiToolkit::TextButton("Horizontal")) {
tc->setHorizontalAlignment(1);
Action::manager().store(s.name() + " Reset h-align");
}
// VERTICAL alignment
var = tc->verticalAlignment();
on = var == 0;
_x = ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN;
_x -= 4.f * (g.FontSize + g.Style.FramePadding.x + IMGUI_SAME_LINE);
if (var != 2) {
// not centered
ImGui::SetNextItemWidth(_x);
if (var > 2) {
// Absolute position
float align_y = tc->verticalPadding();
if (ImGui::SliderFloat("##Posy", &align_y, 0.f, 1.f, "%.2f")) {
tc->setVerticalPadding(align_y);
}
if (ImGui::IsItemHovered())
ImGuiToolkit::ToolTip( "Coordinates" );
} else {
// padding top or bottom
int pad_y = (int) tc->verticalPadding();
if (ImGui::SliderInt("##Pady", &pad_y, 0, 1000)) {
tc->setVerticalPadding((float) pad_y);
}
if (ImGui::IsItemHovered())
ImGuiToolkit::ToolTip( "Padding" );
}
ImGui::SameLine(0, IMGUI_SAME_LINE);
} else {
// no value slider for centered
_x += IMGUI_SAME_LINE + g.Style.FramePadding.x;
ImGui::SetCursorPosX(_x);
}
if (ImGuiToolkit::ButtonIconToggle(1, 17, &on, "Bottom"))
tc->setVerticalAlignment(0);
ImGui::SameLine(0, IMGUI_SAME_LINE);
on = var == 2;
if (ImGuiToolkit::ButtonIconToggle(3, 17, &on, "Center"))
tc->setVerticalAlignment(2);
ImGui::SameLine(0, IMGUI_SAME_LINE);
on = var == 1;
if (ImGuiToolkit::ButtonIconToggle(2, 17, &on, "Top"))
tc->setVerticalAlignment(1);
ImGui::SameLine(0, IMGUI_SAME_LINE);
on = var == 3;
if (ImGuiToolkit::ButtonIconToggle(3, 10, &on, "Absolute"))
tc->setVerticalAlignment(3);
if (var != tc->verticalAlignment())
Action::manager().store(s.name() + " Change v-align");
ImGui::SameLine(0, IMGUI_SAME_LINE);
if (ImGuiToolkit::TextButton("Vertical")) {
tc->setVerticalAlignment(2);
Action::manager().store(s.name() + " Reset v-align");
}
botom = ImGui::GetCursorPos();