Skip to content

Commit

Permalink
Table layout fix [margin]
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuria-Shikibe committed Jun 20, 2024
1 parent cf2ff07 commit 7ef171e
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 55 deletions.
25 changes: 9 additions & 16 deletions src/arc-impl/ui/Cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,23 @@ bool UI::LayoutCell::applySizeToItem(){ // NOLINT(*-make-member-function-const)
// allocatedBound.setShorterHeight(item->getHeight());
}

if(scaleRelativeToParentX || isSlaveX()){
if(scaleRelativeToParentX || isSlaveX() || hasRatioFromHeight()){
exportSize.x = allocatedBound.getWidth() * getHoriScale();
}

if(scaleRelativeToParentY || isSlaveY()){
if(scaleRelativeToParentY || isSlaveY() || hasRatioFromWidth()){
exportSize.y = allocatedBound.getHeight() * getVertScale();
}

if(hasRatioFromWidth()){
exportSize.y = exportSize.x * getRatio_W2H();
}

if(hasRatioFromHeight()){
exportSize.x = exportSize.y * getRatio_H2W();
}

// exportSize.clampX(0, allocatedBound.getWidth());
// exportSize.clampY(0, allocatedBound.getHeight());

// item->maximumSize = allocatedBound.getSize();
item->setWidth_Quiet(Math::clampPositive(exportSize.x - getMarginHori()));
item->setHeight_Quiet(Math::clampPositive(exportSize.y - getMarginVert()));

// const Geom::Vec2 currentSize = item->bound.getSize();
// if(currentSize == Geom::maxVec2<float>){
// item->setMaximumSize(allocatedBound.getSize());

// }

item->changed(ChangeSignal::notifySubs, ChangeSignal::notifyParentOnly);
Expand All @@ -65,10 +57,6 @@ void UI::LayoutCell::applyAlignToItem(const Rect bound) const{
}

void UI::LayoutCell::applyPosToItem(Elem* parent) const{
item->layout();

applyAlignToItem(allocatedBound);

float xMove{};
float yMove{};

Expand All @@ -84,6 +72,11 @@ void UI::LayoutCell::applyPosToItem(Elem* parent) const{
xMove = margin.left + getCellWidth() * scale.getSrcX();
}

item->bound.move(xMove, yMove);

item->layout();

applyAlignToItem(allocatedBound);

item->bound.move(xMove, yMove);
//TODO align...
Expand Down
2 changes: 1 addition & 1 deletion src/arc-impl/ui/Elem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void UI::Elem::passSound(const SoundSource sound) const{
bool UI::Elem::layout_tryFillParent() noexcept{
if(parent) {
if(const Rect rect = parent->getFilledChildrenBound(this); rect != bound) {
setSrc(rect.getSrcX(), rect.getSrcY());
setSrc(rect.getSrc());
setSize(rect.getWidth(), rect.getHeight());
overrideChanged(false);
changed(ChangeSignal::notifySubs);
Expand Down
37 changes: 22 additions & 15 deletions src/arc-impl/ui/Table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ void UI::Table::layoutRelative(){
currentLineScaleRequester.x++;
} else if(cell.isSlaveX()){

} else {
} else if(!cell.hasRatioFromHeight()){
auto& [size, priority] = maxSizeArr[rows() + curPos.x];
size = Math::max(size, cell.getDefWidth());
size = Math::max(size, cell.getDefWidth() + cell.getMarginHori());
priority = Math::max(priority, hard);
}

if(cell.scaleRelativeToParentY){
currentLineScaleRequester.y = 1;
} else if(cell.isSlaveY()){

} else {
} else if(!cell.hasRatioFromWidth()){
auto& [size, priority] = maxSizeArr[curPos.y];
size = Math::max(size, cell.getDefHeight());
size = Math::max(size, cell.getDefHeight() + cell.getMarginVert());
priority = Math::max(priority, hard);
}


expandX |= cell.modifyParentX;
expandY |= cell.modifyParentY;

Expand Down Expand Up @@ -244,13 +245,10 @@ void UI::Table::layoutRelative(){
cell.allocatedBound.setSize(maxSizeArr[curPosX_indexed].first, maxSizeArr[curPos.y].first);

cell.allocatedBound.setSrc(
currentSrc.x, currentSrc.y - cell.allocatedBound.getHeight() //Top src to Bottom src transform
currentSrc.x + cell.pad.left, currentSrc.y - cell.allocatedBound.getHeight() - cell.pad.top//Top src to Bottom src transform
);

const Geom::Vec2 thisPad{cell.pad.left, -cell.pad.top};

cell.applySizeToItem();
cell.allocatedBound.move(thisPad);

curPos.x++;
currentSrc.x += maxSizeArr[curPosX_indexed].first + cell.getPadHori();
Expand All @@ -267,7 +265,7 @@ void UI::Table::layoutRelative(){
currentMaxSize.setZero();

currentSrc.x = 0;
currentSrc.y -= maxSizeArr[curPos.y].first + maxYPad;
currentSrc.y -= (maxSizeArr[curPos.y].first + maxYPad);
maxYPad = 0;

curPos.y++;
Expand Down Expand Up @@ -330,19 +328,17 @@ void UI::Table::layout(){
layoutIrrelative();
}

Group::layout();

// layoutChildren();

//
// layoutChanged = false;
//
// if(relativeLayoutFormat){
// layoutRelative();
// } else{
// layoutIrrelative();
// }
//
// layoutChildren();

Group::layout();

//
// Group::layout();
Expand All @@ -354,11 +350,22 @@ void UI::Table::drawContent() const{
// Rect rect{cell.allocatedBound};
// rect.move(absoluteSrc);
//
// Rect itemBound{cell.item->getBound().setSrc(cell.item->getAbsSrc())};
//
// using namespace Graphic;
// Draw::Overlay::color(Colors::YELLOW, 0.7f);
// Draw::Overlay::Line::setLineStroke(1.0f);
// Draw::Overlay::Line::rectOrtho(rect);
// Draw::Overlay::Line::line(absoluteSrc, absoluteSrc + border.bot_lft());
//
// Draw::Overlay::color(Colors::ORANGE, 0.67f);
// Draw::Overlay::Line::rectOrtho(itemBound);
//
// // Draw::Overlay::Line::line(absoluteSrc, cell.item->getAbsSrc());
//
// if(!rect.containsLoose(itemBound)){
// Draw::Overlay::color(Colors::RED_DUSK, 0.37f);
// Draw::Overlay::Fill::rectOrtho(Draw::Overlay::getContextTexture(), itemBound);
// }
// }

Group::drawContent();
Expand Down
6 changes: 6 additions & 0 deletions src/arc/math/geom/shape/Rect_Orthogonal.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ export namespace Geom{
other.srcY > srcY && other.srcY + other.height < srcY + height;
}

[[nodiscard]] constexpr bool containsLoose(const Rect_Orthogonal& other) const noexcept{
return
other.srcX >= srcX && other.getEndX() <= getEndX() &&
other.srcY >= srcY && other.getEndY() <= getEndY();
}

[[nodiscard]] constexpr bool contains(const Rect_Orthogonal& other) const noexcept{
return
other.srcX >= srcX && other.getEndX() < getEndX() &&
Expand Down
3 changes: 2 additions & 1 deletion src/arc/ui/Styles.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export namespace UI::Styles {
{
style_elem_s1_noEdge.operator*() = style_elem_s1.operator*();
style_elem_s1_noEdge->edge = {};
drawer_elem_s1_noEdge = std::make_unique<UI::StyleDrawer>(style_elem_s1_noEdge.get());;
// style_elem_s1_noEdge->margin.set(4.f);
drawer_elem_s1_noEdge = std::make_unique<UI::StyleDrawer>(style_elem_s1_noEdge.get());
}

UI::defDrawer = drawer_elem_s1.get();
Expand Down
88 changes: 66 additions & 22 deletions src/game/ui/comp/HitboxEditor.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ namespace Game::Scene{
std::shared_ptr<Font::GlyphLayout> glyphLayout = Font::obtainLayoutPtr();
std::string specifiedMovement{};

bool saved{};

std::optional<float> getSpecMovement() const noexcept{
float val;
auto [ptr, ec] = std::from_chars(specifiedMovement.data(),
Expand Down Expand Up @@ -350,6 +352,22 @@ namespace Game::Scene{
selected.clear();
}

void duplicateSelected(){
std::list<EditBox> toCopy{};

for(const auto entity : selected){
auto& n = toCopy.emplace_back(*entity);
n.selected = true;
entity -> selected = false;
}

selected.clear();

selected.insert_range(toCopy | std::views::transform([](auto& t){return std::addressof(t);}));

boxes.append_range(std::move(toCopy));
}

void mirrowSelected(){
std::vector<EditBox> copy{};
copy.reserve(boxes.size());
Expand All @@ -373,7 +391,7 @@ namespace Game::Scene{
sideMenu.setFillparent();
sideMenu.setCellAlignMode(Align::Layout::top_center);

sideMenu.add<UI::Table>([this](UI::Table& transTable){
sideMenu.add<Table>([this](Table& transTable){
transTable.setEmptyDrawer();
transTable.defaultCellLayout.setMargin(2.f).fillParent();

Expand Down Expand Up @@ -406,9 +424,9 @@ namespace Game::Scene{

b.setTooltipBuilder({
.followTarget = TooltipFollowTarget::cursor,
.builder = [name](UI::Table& hint){
hint.setDrawer(UI::Styles::drawer_elem_s1_noEdge.get());
hint.add<UI::Label>([name](UI::Label& l){
.builder = [name](Table& hint){
hint.setDrawer(Styles::drawer_elem_s1_noEdge.get());
hint.add<Label>([name](Label& l){
l.setText(l.getBundleEntry(name));
l.setTextScl(0.75f);
l.setWrap();
Expand All @@ -430,7 +448,7 @@ namespace Game::Scene{
sideMenu.endline().emplace(Create::LineCreater{}).setHeight(4.f).setPad(
{.bottom = 4.f, .top = 4.f}).fillParentX().endLine();

sideMenu.add<UI::Table>([this](UI::Table& transTable){
sideMenu.add<Table>([this](Table& transTable){
transTable.setEmptyDrawer();
transTable.defaultCellLayout.setMargin(2.f).fillParent();

Expand Down Expand Up @@ -465,9 +483,9 @@ namespace Game::Scene{

b.setTooltipBuilder({
.followTarget = TooltipFollowTarget::cursor,
.builder = [name](UI::Table& hint){
hint.setDrawer(UI::Styles::drawer_elem_s1_noEdge.get());
hint.add<UI::Label>([name](UI::Label& l){
.builder = [name](Table& hint){
hint.setDrawer(Styles::drawer_elem_s1_noEdge.get());
hint.add<Label>([name](Label& l){
l.setText(l.getBundleEntry(name));
l.setTextScl(0.75f);
l.setWrap();
Expand All @@ -490,12 +508,12 @@ namespace Game::Scene{
{.bottom = 4.f, .top = 4.f}).fillParentX().endLine();

sideMenu.transferElem(Create::imageButton(Styles::drawer_elem_s1_noEdge.get(),
UI::Icons::inbox_upload_r,
Icons::inbox_upload_r,
[this]{
getRoot()->showDialog(true, Create::OutputFileDialog{
[this](OutputFileSelector& f){
f.targetSuffix = Game::HitBox::HitboxFileSuffix;
f.suffixFilter.insert(Game::HitBox::HitboxFileSuffix);
f.targetSuffix = HitBox::HitboxFileSuffix;
f.suffixFilter.insert(HitBox::HitboxFileSuffix);
f.singleSelect = true;
f.confirmCallback = [this](std::unordered_set<OS::File>&& files){
saveFile = *files.begin();
Expand All @@ -507,11 +525,25 @@ namespace Game::Scene{
).fillParentX().setMargin(2.f).setYRatio(.5f).endLine();

sideMenu.transferElem(Create::imageButton(Styles::drawer_elem_s1_noEdge.get(),
UI::Icons::inbox_download_r,
Icons::down,
[this]{
saveData();
}, [this](Button& b){
b.disableChecker = [this](auto&){
return !saveFile.exist();
};
}).first
).fillParentX().setMargin(2.f).setYRatio(.5f).endLine();

sideMenu.endline().emplace(Create::LineCreater{.defColor = UI::Pal::LIGHT_GRAY}).setHeight(2.f).setPad(
{.bottom = 2.f, .top = 2.f}).fillParentX().endLine();

sideMenu.transferElem(Create::imageButton(Styles::drawer_elem_s1_noEdge.get(),
Icons::code_download,
[this]{
getRoot()->showDialog(true, Create::BasicFileDialog{
[this](FileSelector& f){
f.suffixFilter.insert(Game::HitBox::HitboxFileSuffix);
f.suffixFilter.insert(HitBox::HitboxFileSuffix);
f.singleSelect = true;
f.confirmCallback = [this](std::unordered_set<OS::File>&& files){
saveFile = *files.begin();
Expand All @@ -526,16 +558,16 @@ namespace Game::Scene{
{.bottom = 4.f, .top = 4.f}).fillParentX().endLine();

sideMenu.transferElem(Create::imageButton(Styles::drawer_elem_s1_noEdge.get(),
UI::Icons::blender_icon_image_data,
Icons::blender_icon_image_data,
[this]{
getRoot()->showDialog(true, Create::BasicFileDialog{
root->showDialog(true, Create::BasicFileDialog{
[this](FileSelector& f){
f.suffixFilter.insert(".png");
f.singleSelect = true;
f.confirmCallback = [this](std::unordered_set<OS::File>&& files){
if(files.empty()) return;

refImageTexture = GL::Texture2D{*files.begin()};
this->refImageTexture = GL::Texture2D{*files.begin()};

Geom::RectBox& box{refImageBound.box.cap.box};
box.setSize(refImageTexture.getWidth(), refImageTexture.getHeight());
Expand All @@ -553,11 +585,11 @@ namespace Game::Scene{
.fillParentY()
.as<Table>();

screen = &add<UI::Viewport>([](UI::Viewport& section){
screen = &add<Viewport>([](Viewport& section){
// section.setEmptyDrawer();
}).fillParent().as<UI::Viewport>();
}).fillParent().as<Viewport>();

screen->getInputListener().on<UI::MouseActionPress>([this](const UI::MouseActionPress& e){
screen->getInputListener().on<MouseActionPress>([this](const MouseActionPress& e){
EditBox* hit{};

if(hasOp() && e.key == Ctrl::Mouse::LMB){
Expand All @@ -579,7 +611,12 @@ namespace Game::Scene{
quadTree.intersectPoint(screen->getCursorPosInScreen(), [&hit](EditBox& b){
if(!hit && !b.selected) hit = &b;
});
if(hit) addSelection(hit);
if(hit) switch(e.mode){
case Ctrl::Mode::Shift : addSelection(hit); break;
case Ctrl::Mode::None : clearSelected(); addSelection(hit); break;
default: break;
}

break;
}

Expand Down Expand Up @@ -940,6 +977,12 @@ namespace Game::Scene{
})
};

::Ctrl::Operation duplicate{
"duplicate", OS::KeyBind(Ctrl::Key::D, Ctrl::Act::Press, Ctrl::Mode::Shift, [this]{
duplicateSelected();
})
};

::Ctrl::Operation deleteSelection{
"deleteSelection", OS::KeyBind(Ctrl::Key::Delete, Ctrl::Act::Press, [this]{
deleteSelected();
Expand Down Expand Up @@ -1046,6 +1089,7 @@ namespace Game::Scene{
std::move(accurate_prs),
std::move(accurate_rls),
std::move(op_mirrow),
std::move(duplicate),
}
};

Expand Down Expand Up @@ -1095,7 +1139,7 @@ namespace Game::Scene{

// originTrans = {-100, 200, 40};

glyphLayout->setSCale(0.65f);
glyphLayout->setSCale(0.5f);

loadBinds();
}
Expand Down Expand Up @@ -1158,7 +1202,7 @@ namespace Game::Scene{
GL::TextureRegion wrap{&refImageTexture};
ext::GuardRef<const GL::TextureRegion*> _{Overlay::contextTexture, &wrap};

Overlay::color(UI::Pal::GRAY, .65f);
Overlay::color(UI::Pal::GRAY, .5f);
Overlay::mixColor(UI::Pal::GRAY, .1f);

Game::Draw::hitbox<Overlay>(refImageBound.box.snap.box);
Expand Down

0 comments on commit 7ef171e

Please sign in to comment.