【问题标题】:set_halign(gtk::Align::End) on buttons in GTK Rust not right aligningGTK Rust 中按钮上的 set_halign(gtk::Align::End) 不正确对齐
【发布时间】:2023-02-01 06:01:36
【问题描述】:

因此,我从阅读文档中了解到,set_halign(gtk::Align::End) 会将按钮向右对齐,但这并没有发生,它与带有 set_halign(gtk::Align::Start) 的按钮保持向左对齐。

pub fn create_widget(&self) -> impl IsA<Widget> {
  let frame1 = frame::create_frame(self, "frame1");

  let box1 = boxx::create_box(self, "box1");
  box1.set_orientation(Orientation::Vertical);
  frame1.add(&box1);

  let superman_box = boxx::create_box(self, "superman box");
  superman_box.set_orientation(Orientation:Horizontal);
  box1.add(&superman_box);

  let superman_button = button::create_text_button(self, "superman", "Superman");
  superman_button.connect_clicked(move |_| {});
  superman_button.set_halign(gtk::Align::Start);
  superman_box.add(&superman_button);

  let sessions_button = button::create_text_button(self, "sessions_button", "Sessions");
  sessions_button.connect_clicked(move |_| {});
  sessions_button.set_halign(gtk::Align::End);
  superman_box.add(&sessions_button);

  let logout_button = button::create_text_button(self, "logout_button", "Logout");
  logout_button.connect_clicked(move |_| {});
  logout_button.set_halign(gtk::Align::End);
  superman_box.add(&logout_button);
}

【问题讨论】:

    标签: html css rust gtk3


    【解决方案1】:

    所以我决定重构整个东西,将超人按钮放在自己的框中,将会话和注销按钮放在自己的框中,如下所示:

    let left_box = boxx::create_box(self, "left_box");
    left_box.set_orientation(Orientation::Horizontal);
    left_box.set_halign(gtk::Align::Start);
    header_navbar.add(&left_box);
    
    let left_box_label = label::create_text_label(self, "left_box_label", "Supervisor");
    left_box.add(&left_box_label);
    
    let right_box = boxx::create_box(self, "right_box");
    right_box.set_orientation(Orientation::Horizontal);
    right_box.set_halign(gtk::Align::End);
    header_navbar.add(&right_box);
    
    let sessions_button = button::create_text_button(self, "sessions_button", "Sessions");
    sessions_button.connect_clicked(move |_| {eprintln!("Sessions button clicked!")});
    sessions_button.set_halign(gtk::Align::End);
    right_box.add(&sessions_button);
    
    let logout_button = button::create_text_button(self, "logout_button", "Logout");
    logout_button.connect_clicked(move |_| {eprintln!("Logout button clicked!")});
    logout_button.set_halign(gtk::Align::End);
    right_box.add(&logout_button);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      相关资源
      最近更新 更多