gammasoft71 / xtd

Free open-source modern C++17 / C++20 framework to create console, GUI (forms like WinForms) and unit test applications and libraries on Microsoft Windows, Apple macOS and Linux.
https://gammasoft71.github.io/xtd
MIT License
737 stars 58 forks source link

[BUG] 'xtd::forms::button' anchor style, anchor_styles::top, is ignored when contained in a xtd::forms::group_box. #198

Closed wsberry closed 1 year ago

wsberry commented 1 year ago

Describe the bug

'xtd::forms::button' anchor style, anchor_styles::top, is ignored when contained in a xtd::forms::group_box and the group box is resized vertically. Horizontal anchoring works as expected.

To Reproduce you may use the provided sample code:

namespace group_box_test
{
    inline void message(const std::string_view caption, const std::string_view msg)
    {
        using namespace xtd;
        using namespace xtd::forms;
        message_dialog dialog;
        dialog.buttons(message_dialog_buttons::ok);
        dialog.icon(xtd::forms::message_dialog_icon::information);
        dialog.message(msg.data());
        dialog.text(caption.data());
        dialog.show_dialog();
    }

  class form1 : public xtd::forms::form {
  public:
      form1() {
          using namespace xtd;
          using namespace xtd::forms;

          text("Group Box Example");
          location({200, 200});
          client_size({640, 480});

          const anchor_styles left_panel_anchor = 
                            anchor_styles::top | anchor_styles::left | anchor_styles::bottom;

          const anchor_styles right_panel_anchor =
                    anchor_styles::top | anchor_styles::left | anchor_styles::bottom | anchor_styles::right;

          group_box1_.parent(*this);
          group_box1_.location({10, 10});
          group_box1_.size({305, 460});
          group_box1_.anchor(left_panel_anchor);
          group_box1_.text("Service Options");

          group_box2_.parent(*this);
          group_box2_.text(" ");
          group_box2_.location({325, 10});
          group_box2_.size({305, 460});
          group_box2_.anchor(right_panel_anchor);

          button_hello_.parent(group_box2_);
          button_hello_.location({10, 10});
          button_hello_.anchor(anchor_styles::top | anchor_styles::left);
          button_hello_.text("&Hello World...");
          button_hello_.width(128);
          button_hello_.click += [] {
              message("Message", "Hello World");
          };
      }

      static void main()
      {
          using namespace xtd::forms;
          application::enable_visual_styles();
          application::run(form1());
      }

  private:
      xtd::forms::group_box group_box1_;
      xtd::forms::group_box group_box2_;
      xtd::forms::button button_hello_;
  };
}

Steps to reproduce the behavior:

  1. Build and run the provided code.
  2. Increase the size of the application dialog vertically.

Expected behaviour

If the attribute 'anchor_styles::top' is set on a 'xtd::forms::button' instance then it should remain at the top of the group_box when the group_box is resized vertically.

A clear and concise description of what you expected to happen.

Desktop

Model Name: MacBook Air Model Identifier: MacBookAir10,1 Chip: Apple M1 Total Number of Cores: 8 (4 performance and 4 efficiency) Memory: 16 GB System Firmware Version: 7459.141.1 OS Loader Version: 7459.141.1

Workaround

None Found

gammasoft71 commented 1 year ago

There is indeed a problem with the group_box control. I'll look when I get back to fix it. This issue is only present on macOS.

Workaround : you can use a panel while waiting for the issue to be fixed.