mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-13 16:21:06 +03:00
- Introduced a new mixin `CustomScaleControlsMixin` to encapsulate custom scale control logic, allowing for code reuse in both mobile and desktop widgets. - Refactored `_CustomScaleMenuControlsState` and `_MobileCustomScaleControlsState` to utilize the new mixin, simplifying the scaling logic and reducing code duplication. - Updated slider handling and state management to leverage the mixin's methods for improved maintainability. Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
73 lines
2.3 KiB
Dart
73 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hbb/models/model.dart';
|
|
import 'package:flutter_hbb/common.dart';
|
|
import 'package:flutter_hbb/common/widgets/custom_scale_mixin.dart';
|
|
|
|
class MobileCustomScaleControls extends StatefulWidget {
|
|
final FFI ffi;
|
|
final ValueChanged<int>? onChanged;
|
|
const MobileCustomScaleControls({Key? key, required this.ffi, this.onChanged}) : super(key: key);
|
|
|
|
@override
|
|
State<MobileCustomScaleControls> createState() => _MobileCustomScaleControlsState();
|
|
}
|
|
|
|
class _MobileCustomScaleControlsState extends State<MobileCustomScaleControls>
|
|
with CustomScaleControlsMixin {
|
|
@override
|
|
FFI get ffi => widget.ffi;
|
|
|
|
@override
|
|
ValueChanged<int>? get onScaleChanged => widget.onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Smaller button size for mobile
|
|
const smallBtnConstraints = BoxConstraints(minWidth: 32, minHeight: 32);
|
|
|
|
final sliderControl = Slider(
|
|
value: scalePos,
|
|
min: 0.0,
|
|
max: 1.0,
|
|
divisions: (CustomScaleControlsMixin.maxPercent - CustomScaleControlsMixin.minPercent).round(),
|
|
label: '$scaleValue%',
|
|
onChanged: onSliderChanged,
|
|
);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
'${translate("Scale custom")}: $scaleValue%',
|
|
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
IconButton(
|
|
iconSize: 20,
|
|
padding: const EdgeInsets.all(4),
|
|
constraints: smallBtnConstraints,
|
|
icon: const Icon(Icons.remove),
|
|
tooltip: translate('Decrease'),
|
|
onPressed: () => nudgeScale(-1),
|
|
),
|
|
Expanded(child: sliderControl),
|
|
IconButton(
|
|
iconSize: 20,
|
|
padding: const EdgeInsets.all(4),
|
|
constraints: smallBtnConstraints,
|
|
icon: const Icon(Icons.add),
|
|
tooltip: translate('Increase'),
|
|
onPressed: () => nudgeScale(1),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|