Advertisement
Guest User

Untitled

a guest
Nov 6th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 2.29 KB | None | 0 0
  1. public class StackClass : Gtk.Window {
  2.    public Gtk.LevelBar[] barMass;
  3.     public StackClass () {
  4.         var header = new Gtk.HeaderBar();
  5.         header.set_show_close_button(true);
  6.         barMass = new Gtk.LevelBar[10];
  7.         var box2 = new Gtk.Box(Gtk.Orientation.VERTICAL, 1);
  8.         var box1 = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 1);
  9.         var btn = new Gtk.Button.with_label("SAS"); box2.pack_start(btn,true,true,5);
  10. //Стак
  11.         var stack = new Gtk.Stack();
  12.         Gtk.StackSwitcher switcher = new Gtk.StackSwitcher ();
  13.         switcher.set_valign (Gtk.Align.CENTER);
  14.         header.pack_start (switcher);
  15.         stack.set_transition_duration (500);//скорость анимации
  16.         stack.set_transition_type (SLIDE_LEFT_RIGHT);
  17.         switcher.set_stack (stack);//устанавливаем переключателю стак
  18. //создаем 10 прогрессБаров и заполняем ими бокс с флагами expand
  19.         for (int i=0;i<10;i++){
  20.             barMass[i] = new Gtk.LevelBar.for_interval (0.0, 10.0);
  21.             box1.pack_start(barMass[i],true,true,2);
  22.             barMass[i].set_orientation(Gtk.Orientation.VERTICAL);
  23.             //barMass[i].set_mode (Gtk.LevelBarMode.DISCRETE);
  24.             barMass[i].set_inverted(true);
  25.             barMass[i].set_hexpand(true);
  26.         }
  27.         barMass[0].set_value(10.0);
  28.    
  29.         stack.add_titled(box1,"box1","box1");
  30.         stack.add_titled(box2,"box2","box2");
  31.  
  32.         this.set_titlebar(header);
  33.         this.destroy.connect(Gtk.main_quit);
  34.         this.border_width = 10;
  35.         this.set_size_request (600, 500);
  36.         this.add(stack);
  37.         btn.clicked.connect(()=> {addNbar(Random.double_range (1, 100));});
  38.  
  39.         this.key_press_event.connect ((key) => {
  40.             print(key.str + " ");
  41.             addNbar(double.parse(key.str));
  42.             return false;
  43.         });
  44.  
  45.     }
  46.  
  47.  
  48.     public void addNbar(double newV){
  49.         for(int i=0;i<10-1;i++){
  50.             barMass[i].set_value(barMass[i+1].get_value());
  51.         }
  52.         barMass[9].set_value(newV);  
  53.     }
  54.  
  55.    
  56.     public static int main(string[] args){
  57.         Gtk.init(ref args);
  58.         var s = new StackClass();
  59.         s.show_all();
  60.         Gtk.main();
  61.         return 0;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement