mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Workaround for wxCocoa bug causing wxSpinCtrl values to be reset when losing focus after changing them from the text field. #2612
This commit is contained in:
		
							parent
							
								
									f010354201
								
							
						
					
					
						commit
						8cbb12aeb6
					
				
					 1 changed files with 16 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -7,7 +7,6 @@ has 'parent'                => (is => 'ro', required => 1);
 | 
			
		|||
has 'option'                => (is => 'ro', required => 1);     # Slic3r::GUI::OptionsGroup::Option
 | 
			
		||||
has 'on_change'             => (is => 'rw', default => sub { sub {} });
 | 
			
		||||
has 'on_kill_focus'         => (is => 'rw', default => sub { sub {} });
 | 
			
		||||
has 'wxSsizer'              => (is => 'rw');                    # alternatively, wxSizer object
 | 
			
		||||
has 'disable_change_event'  => (is => 'rw', default => sub { 0 });
 | 
			
		||||
 | 
			
		||||
# This method should not fire the on_change event
 | 
			
		||||
| 
						 | 
				
			
			@ -128,6 +127,8 @@ extends 'Slic3r::GUI::OptionsGroup::Field::wxWindow';
 | 
			
		|||
use Wx qw(:misc);
 | 
			
		||||
use Wx::Event qw(EVT_SPINCTRL EVT_TEXT EVT_KILL_FOCUS);
 | 
			
		||||
 | 
			
		||||
has 'tmp_value' => (is => 'rw');
 | 
			
		||||
 | 
			
		||||
sub BUILD {
 | 
			
		||||
    my ($self) = @_;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -139,13 +140,27 @@ sub BUILD {
 | 
			
		|||
        $self->_on_change($self->option->opt_id);
 | 
			
		||||
    });
 | 
			
		||||
    EVT_TEXT($self->parent, $field, sub {
 | 
			
		||||
        my ($s, $event) = @_;
 | 
			
		||||
        
 | 
			
		||||
        # On OSX/Cocoa, wxSpinCtrl::GetValue() doesn't return the new value
 | 
			
		||||
        # when it was changed from the text control, so the on_change callback
 | 
			
		||||
        # gets the old one, and on_kill_focus resets the control to the old value.
 | 
			
		||||
        # As a workaround, we get the new value from $event->GetString and store
 | 
			
		||||
        # here temporarily so that we can return it from $self->get_value
 | 
			
		||||
        $self->tmp_value($event->GetString);
 | 
			
		||||
        $self->_on_change($self->option->opt_id);
 | 
			
		||||
        $self->tmp_value(undef);
 | 
			
		||||
    });
 | 
			
		||||
    EVT_KILL_FOCUS($field, sub {
 | 
			
		||||
        $self->_on_kill_focus($self->option->opt_id, @_);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub get_value {
 | 
			
		||||
    my ($self) = @_;
 | 
			
		||||
    return $self->tmp_value // $self->wxWindow->GetValue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
package Slic3r::GUI::OptionsGroup::Field::TextCtrl;
 | 
			
		||||
use Moo;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue